From 8eb7b170bc654bfccea16b9d619fe643eda6a3ba Mon Sep 17 00:00:00 2001 From: Daniel Tenner Date: Sun, 19 Apr 2009 20:38:28 +0100 Subject: [PATCH] Added support for repeat transactions --- lib/active_merchant/billing/gateways/xpay.rb | 9 +++++++ test/remote/gateways/remote_xpay_test.rb | 26 +++++++++++++++++--- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/lib/active_merchant/billing/gateways/xpay.rb b/lib/active_merchant/billing/gateways/xpay.rb index f95d0e65c1a..d38f223ff5d 100644 --- a/lib/active_merchant/billing/gateways/xpay.rb +++ b/lib/active_merchant/billing/gateways/xpay.rb @@ -94,6 +94,15 @@ def credit(money, identification, options = {}) commit(TRANSACTIONS[:credit], nil, post) end + + def repeat(money, identification, options={}) + post = {} + add_parent_transaction_data(post, identification) + add_invoice(post, options) + add_amount(post, money, options, 1) + + commit(TRANSACTIONS[:purchase], money, post) + end private diff --git a/test/remote/gateways/remote_xpay_test.rb b/test/remote/gateways/remote_xpay_test.rb index 3c1ef54ad28..0fc8311279c 100644 --- a/test/remote/gateways/remote_xpay_test.rb +++ b/test/remote/gateways/remote_xpay_test.rb @@ -41,6 +41,8 @@ def setup :description => 'Store Purchase', :currency => 'GBP' } + + @responses = {} end def test_successful_purchase @@ -85,7 +87,6 @@ def test_unsuccessful_capture end def test_authorize_and_void - @responses = {} @credit_cards.each do |type, credit_card| assert response = @gateway.authorize(@amount, credit_card, @options) assert_success response @@ -105,7 +106,6 @@ def test_authorize_and_void end def test_authorize_and_capture_and_refund - @responses = {} @credit_cards.each do |type, credit_card| assert response = @gateway.authorize(@amount, credit_card, @options) assert_success response @@ -132,5 +132,23 @@ def test_authorize_and_capture_and_refund assert_equal "The transaction was processed successfully.", response.message end end - -end + + def test_purchase_and_repeat + @credit_cards.each do |type, credit_card| + assert response = @gateway.purchase(@amount, credit_card, @options) + assert_success response + assert_equal "The transaction was processed successfully.", response.message + @responses[type] = response + end + @credit_cards.each do |type, credit_card| + identification = { + :transaction_reference => @responses[type].transaction_reference, + :transaction_verifier => @responses[type].transaction_verifier + } + assert response = @gateway.repeat(@amount, identification, @options) + assert_success response + assert_equal "The transaction was processed successfully.", response.message + end + end + +end \ No newline at end of file