lib/active_merchant/billing/gateways/sage_pay.rb in activemerchant-1.64.0 vs lib/active_merchant/billing/gateways/sage_pay.rb in activemerchant-1.65.0

- old
+ new

@@ -18,11 +18,12 @@ :authorization => 'DEFERRED', :capture => 'RELEASE', :void => 'VOID', :abort => 'ABORT', :store => 'TOKEN', - :unstore => 'REMOVETOKEN' + :unstore => 'REMOVETOKEN', + :repeat => 'REPEAT' } CREDIT_CARDS = { :visa => "VISA", :master => "MC", @@ -85,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(:purchase, post) + commit((options[:repeat] ? :repeat : :purchase), post) end def authorize(money, payment_method, options = {}) requires!(options, :order_id) @@ -128,11 +129,11 @@ def refund(money, identification, options = {}) requires!(options, :order_id, :description) post = {} - add_credit_reference(post, identification) + add_related_reference(post, identification) add_amount(post, money, options) add_invoice(post, options) commit(:credit, post) end @@ -193,11 +194,11 @@ add_pair(post, :VPSTxId, transaction_id) add_pair(post, :TxAuthNo, authorization) add_pair(post, :SecurityKey, security_key) end - def add_credit_reference(post, identification) + def add_related_reference(post, identification) order_id, transaction_id, authorization, security_key = identification.split(';') add_pair(post, :RelatedVendorTxCode, order_id) add_pair(post, :RelatedVPSTxId, transaction_id) add_pair(post, :RelatedTxAuthNo, authorization) @@ -265,10 +266,12 @@ 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 payment_method.respond_to?(:number) + if options[:repeat] + add_related_reference(post, payment_method) + elsif payment_method.respond_to?(:number) add_credit_card(post, payment_method) else add_token_details(post, payment_method, options) end end