Skip to content
This repository has been archived by the owner on Aug 30, 2024. It is now read-only.

Commit

Permalink
SagePay: Support Repeat transactions
Browse files Browse the repository at this point in the history
Also deactivates the remote test for a Maestro card since it
is not supported for accounts set to use GBP currency, and
prevents an order_id conflict for another test.

Closes activemerchant#2395
  • Loading branch information
curiousepic authored and davidsantoso committed Apr 11, 2017
1 parent 58e0c33 commit 54557d8
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 19 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
* TransFirst Transaction Express: Support ACH [curiousepic] #2389
* Checkout V2: Fix sandbox URL [nicolas-maalouf-cko] #2391
* Checkout V2: Fix success_from not properly checking two possible success codes [davidsantoso]
* SagePay: Support Repeat transactions [curiousepic] #2395

== Version 1.64.0 (March 6, 2017)
* Authorize.net: Allow settings to be passed for CIM purchases [fwilkins] #2300
Expand Down
13 changes: 8 additions & 5 deletions lib/active_merchant/billing/gateways/sage_pay.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ class SagePayGateway < Gateway
:void => 'VOID',
:abort => 'ABORT',
:store => 'TOKEN',
:unstore => 'REMOVETOKEN'
:unstore => 'REMOVETOKEN',
:repeat => 'REPEAT'
}

CREDIT_CARDS = {
Expand Down Expand Up @@ -87,7 +88,7 @@ def purchase(money, payment_method, 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 = {})
Expand Down Expand Up @@ -130,7 +131,7 @@ def refund(money, identification, options = {})

post = {}

add_credit_reference(post, identification)
add_related_reference(post, identification)
add_amount(post, money, options)
add_invoice(post, options)

Expand Down Expand Up @@ -195,7 +196,7 @@ def add_reference(post, identification)
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)
Expand Down Expand Up @@ -267,7 +268,9 @@ def add_invoice(post, options)
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)
Expand Down
37 changes: 23 additions & 14 deletions test/remote/gateways/remote_sage_pay_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,13 @@ def test_successful_visa_purchase
assert !response.authorization.blank?
end

def test_successful_maestro_purchase
assert response = @gateway.purchase(@amount, @maestro, @options)
assert_success response
assert response.test?
assert !response.authorization.blank?
end
# Maestro is not available for GBP
# def test_successful_maestro_purchase
# assert response = @gateway.purchase(@amount, @maestro, @options)
# assert_success response
# assert response.test?
# assert !response.authorization.blank?
# end

def test_successful_amex_purchase
assert response = @gateway.purchase(@amount, @amex, @options)
Expand Down Expand Up @@ -313,6 +314,14 @@ def test_successful_purchase_with_website
assert_success response
end

def test_successful_repeat_purchase
response = @gateway.purchase(@amount, @visa, @options)
assert_success response

repeat = @gateway.purchase(@amount, response.authorization, @options.merge(repeat: true, order_id: generate_unique_id))
assert_success repeat
end

def test_invalid_login
message = SagePayGateway.simulate ? 'VSP Simulator cannot find your vendor name. Ensure you have have supplied a Vendor field with your VSP Vendor name assigned to it.' : '3034 : The Vendor or VendorName value is required.'

Expand All @@ -337,7 +346,7 @@ def test_successful_store_and_repurchase_with_resupplied_verification_value
assert_success response
assert !response.authorization.blank?
assert purchase = @gateway.purchase(@amount, response.authorization, @options.merge(customer: 1))
assert purchase = @gateway.purchase(@amount, response.authorization, @options.merge(verification_value: '123', order_id: 'foobar123'))
assert purchase = @gateway.purchase(@amount, response.authorization, @options.merge(verification_value: '123', order_id: generate_unique_id))
assert_success purchase
end

Expand Down Expand Up @@ -417,13 +426,13 @@ def basket_xml
# Example from http://www.sagepay.co.uk/support/customer-xml
def customer_xml
<<-XML
<customer>
<customerMiddleInitial>W</customerMiddleInitial>
<customerBirth>1983-01-01</customerBirth>
<customerWorkPhone>020 1234567</customerWorkPhone>
<customerMobilePhone>0799 1234567</customerMobilePhone>
<previousCust>0</previousCust>
<timeOnFile>10</timeOnFile>
<customer>
<customerMiddleInitial>W</customerMiddleInitial>
<customerBirth>1983-01-01</customerBirth>
<customerWorkPhone>020 1234567</customerWorkPhone>
<customerMobilePhone>0799 1234567</customerMobilePhone>
<previousCust>0</previousCust>
<timeOnFile>10</timeOnFile>
<customerId>CUST123</customerId>
</customer>
XML
Expand Down

0 comments on commit 54557d8

Please sign in to comment.