lib/active_merchant/billing/gateways/trust_commerce.rb in activemerchant-1.95.0 vs lib/active_merchant/billing/gateways/trust_commerce.rb in activemerchant-1.96.0
- old
+ new
@@ -102,10 +102,12 @@
}
TEST_LOGIN = 'TestMerchant'
TEST_PASSWORD = 'password'
+ VOIDABLE_ACTIONS = %w(preauth sale postauth credit)
+
self.money_format = :cents
self.supported_cardtypes = [:visa, :master, :discover, :american_express, :diners_club, :jcb]
self.supported_countries = ['US']
self.homepage_url = 'http://www.trustcommerce.com/'
self.display_name = 'TrustCommerce'
@@ -177,25 +179,27 @@
# capture() is the second half of the preauth(authorize)/postauth(capture) model. The TC API docs call this
# postauth, we preserve active_merchant's nomenclature of capture() for consistency with the rest of the library. To process
# a postauthorization with TC, you need an amount in cents or a money object, and a TC transid.
def capture(money, authorization, options = {})
+ transaction_id, _ = split_authorization(authorization)
parameters = {
:amount => amount(money),
- :transid => authorization,
+ :transid => transaction_id,
}
add_aggregator(parameters, options)
commit('postauth', parameters)
end
# refund() allows you to return money to a card that was previously billed. You need to supply the amount, in cents or a money object,
# that you want to refund, and a TC transid for the transaction that you are refunding.
def refund(money, identification, options = {})
+ transaction_id, _ = split_authorization(identification)
parameters = {
:amount => amount(money),
- :transid => identification
+ :transid => transaction_id
}
add_aggregator(parameters, options)
commit('credit', parameters)
end
@@ -212,22 +216,28 @@
# of "accepted" even if the transid you are trying to deauthorize has
# already been captured. Note: Your account needs to be configured by
# TrustCommerce to allow for reversal transactions before you can use this
# method.
#
+ # void() is also used to to cancel a capture (postauth), purchase (sale),
+ # or refund (credit) or a before it is sent for settlement.
+ #
# NOTE: AMEX preauth's cannot be reversed. If you want to clear it more
# quickly than the automatic expiration (7-10 days), you will have to
# capture it and then immediately issue a credit for the same amount
# which should clear the customers credit card with 48 hours according to
# TC.
def void(authorization, options = {})
+ transaction_id, original_action = split_authorization(authorization)
+ action = (VOIDABLE_ACTIONS - ['preauth']).include?(original_action) ? 'void' : 'reversal'
+
parameters = {
- :transid => authorization,
+ :transid => transaction_id,
}
add_aggregator(parameters, options)
- commit('reversal', parameters)
+ commit(action, parameters)
end
# recurring() a TrustCommerce account that is activated for Citadel, TrustCommerce's
# hosted customer billing info database.
#
@@ -414,11 +424,11 @@
# to be considered successful, transaction status must be either "approved" or "accepted"
success = SUCCESS_TYPES.include?(data['status'])
message = message_from(data)
Response.new(success, message, data,
:test => test?,
- :authorization => data['transid'],
+ :authorization => authorization_from(action, data),
:cvv_result => data['cvv'],
:avs_result => { :code => data['avs'] }
)
end
@@ -444,8 +454,17 @@
else
return 'The transaction was successful'
end
end
+ def authorization_from(action, data)
+ authorization = data['transid']
+ authorization = "#{authorization}|#{action}" if authorization && VOIDABLE_ACTIONS.include?(action)
+ authorization
+ end
+
+ def split_authorization(authorization)
+ authorization.split('|')
+ end
end
end
end