From dc92ea5eb876f44f4766d900b0989ede2486a953 Mon Sep 17 00:00:00 2001 From: Robby Russell Date: Mon, 1 Dec 2008 11:01:33 -0800 Subject: [PATCH] Adding the ability to run a card store when performing an authorize(). Returns an array with the response for authorize and store --- .../billing/gateways/merchant_e_solutions.rb | 12 +++++++++++- test/unit/gateways/merchant_e_solutions_test.rb | 11 +++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/lib/active_merchant/billing/gateways/merchant_e_solutions.rb b/lib/active_merchant/billing/gateways/merchant_e_solutions.rb index de0825ece64..46b74654a26 100644 --- a/lib/active_merchant/billing/gateways/merchant_e_solutions.rb +++ b/lib/active_merchant/billing/gateways/merchant_e_solutions.rb @@ -28,7 +28,17 @@ def authorize(money, creditcard_or_card_id, options = {}) add_invoice(post, options) add_payment_source(post, creditcard_or_card_id, options) add_address(post, options) - commit('P', money, post) + authorize_result = commit('P', money, post) + + unless options.has_key? :store + options[:store] = false + end + + if options[:store] + return [authorize_result, store(creditcard_or_card_id, options)] + else + return authorize_result + end end # returns a single ActiveMerchant::Billing::Response object unless options[:store] == true diff --git a/test/unit/gateways/merchant_e_solutions_test.rb b/test/unit/gateways/merchant_e_solutions_test.rb index 7b3eda3e1ca..42e59f2c7d8 100644 --- a/test/unit/gateways/merchant_e_solutions_test.rb +++ b/test/unit/gateways/merchant_e_solutions_test.rb @@ -48,6 +48,12 @@ def test_authorization assert_equal '42e52603e4c83a55890fbbcfb92b8de1', response.authorization assert response.test? end + + def test_authorization_with_store + @gateway.expects(:authorize).returns(successful_authorization_with_store_response) + assert response = @gateway.authorize(@amount, @credit_card, @options.merge({:store => true})) + assert_instance_of Array, response + end def test_capture @gateway.expects(:ssl_post).returns(successful_capture_response) @@ -152,6 +158,11 @@ def successful_purchase_store_response def successful_authorization_response 'transaction_id=42e52603e4c83a55890fbbcfb92b8de1&error_code=000&auth_response_text=Exact Match&auth_code=12345A' end + + def successful_authorization_with_store_response + [ 'transaction_id=42e52603e4c83a55890fbbcfb92b8de1&error_code=000&auth_response_text=Exact Match&auth_code=12345A', + 'transaction_id=ae641b57b19b3bb89faab44191479872&error_code=000&auth_response_text=Card Data Stored'] + end def successful_credit_response 'transaction_id=0a5ca4662ac034a59595acb61e8da025&error_code=000&auth_response_text=Credit Approved'