lib/active_merchant/billing/gateways/sage_pay.rb in activemerchant-1.68.0 vs lib/active_merchant/billing/gateways/sage_pay.rb in activemerchant-1.69.0

- old
+ new

@@ -86,11 +86,11 @@ add_payment_method(post, payment_method, options) add_address(post, options) add_customer_data(post, options) add_optional_data(post, options) - commit((options[:repeat] ? :repeat : :purchase), post) + commit((past_purchase_reference?(payment_method) ? :repeat : :purchase), post) end def authorize(money, payment_method, options = {}) requires!(options, :order_id) @@ -266,16 +266,18 @@ add_pair(post, :VendorTxCode, sanitize_order_id(options[:order_id]), :required => true) add_pair(post, :Description, truncate(options[:description] || options[:order_id], 100)) end def add_payment_method(post, payment_method, options) - if options[:repeat] - add_related_reference(post, payment_method) - elsif payment_method.respond_to?(:number) - add_credit_card(post, payment_method) + if payment_method.is_a?(String) + if past_purchase_reference?(payment_method) + add_related_reference(post, payment_method) + else + add_token_details(post, payment_method, options) + end else - add_token_details(post, payment_method, options) + add_credit_card(post, payment_method) end end def add_credit_card(post, credit_card) add_pair(post, :CardHolder, truncate(credit_card.name, 50), :required => true) @@ -357,13 +359,13 @@ case action when :store response['Token'] else [ params[:VendorTxCode], - response["VPSTxId"], + response["VPSTxId"] || params[:VPSTxId], response["TxAuthNo"], - response["SecurityKey"], + response["SecurityKey"] || params[:SecurityKey], action ].join(";") end end def abort_or_void_from(identification) @@ -420,9 +422,13 @@ def add_pair(post, key, value, options = {}) post[key] = value if !value.blank? || options[:required] end + def past_purchase_reference?(payment_method) + return false unless payment_method.is_a?(String) + payment_method.split(';').last == 'purchase' + end end end end