From 8aa99c3aef400414ad4cb53d27fdb10d299c8cce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Coutable?= Date: Mon, 10 Jun 2013 12:01:08 +0200 Subject: [PATCH] Ogone: Add a :store_amount option Some banks will not authorize if the amount is too small. This adds a gateway option that overrides the default amount (0.01) for the authorization part of the #store method. Closes #724. --- CHANGELOG | 1 + lib/active_merchant/billing/gateways/ogone.rb | 28 +++++++---- test/remote/gateways/remote_ogone_test.rb | 13 ++--- test/unit/gateways/ogone_test.rb | 47 ++++++++++++++++--- 4 files changed, 68 insertions(+), 21 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index e75a875541e..0fb027a7fb0 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -5,6 +5,7 @@ * SecureNet: Fix order of xml params [duff] * Paymill: Add support for void [duff] * Add MoneyMovers gateway [jeffutter] +* Ogone: Add a :store_amount option [rymai] == Version 1.38.1 (September 16, 2013) diff --git a/lib/active_merchant/billing/gateways/ogone.rb b/lib/active_merchant/billing/gateways/ogone.rb index 973faa5c4ec..0f0fbb016d2 100644 --- a/lib/active_merchant/billing/gateways/ogone.rb +++ b/lib/active_merchant/billing/gateways/ogone.rb @@ -32,13 +32,13 @@ module Billing #:nodoc: # == Usage # # gateway = ActiveMerchant::Billing::OgoneGateway.new( - # :login => "my_ogone_psp_id", - # :user => "my_ogone_user_id", - # :password => "my_ogone_pswd", - # :signature => "my_ogone_sha_signature", # Only if you configured your Ogone environment so. - # :signature_encryptor => "sha512", # Can be "none" (default), "sha1", "sha256" or "sha512". + # :login => "my_ogone_psp_id", + # :user => "my_ogone_user_id", + # :password => "my_ogone_pswd", + # :signature => "my_ogone_sha_signature", # Only if you configured your Ogone environment so. + # :signature_encryptor => "sha512" # Can be "none" (default), "sha1", "sha256" or "sha512". # # Must be the same as the one configured in your Ogone account. - # ) + # ) # # # set up credit card object as in main ActiveMerchant example # creditcard = ActiveMerchant::Billing::CreditCard.new( @@ -75,7 +75,19 @@ module Billing #:nodoc: # # # When using store, you can also let Ogone generate the alias for you # response = gateway.store(creditcard) - # puts response.billing_id # Retrieve the generated alias + # puts response.billing_id # Retrieve the generated alias + # + # # By default, Ogone tries to authorize 0.01 EUR but you can change this + # # amount using the :store_amount option when creating the gateway object: + # gateway = ActiveMerchant::Billing::OgoneGateway.new( + # :login => "my_ogone_psp_id", + # :user => "my_ogone_user_id", + # :password => "my_ogone_pswd", + # :signature => "my_ogone_sha_signature", + # :signature_encryptor => "sha512", + # :store_amount => 100 # The store method will try to authorize 1 EUR instead of 0.01 EUR + # ) + # response = gateway.store(creditcard) # authorize 1 EUR and void the authorization right away # # == 3-D Secure feature # @@ -195,7 +207,7 @@ def refund(money, reference, options = {}) # Store a credit card by creating an Ogone Alias def store(payment_source, options = {}) options.merge!(:alias_operation => 'BYPSP') unless(options.has_key?(:billing_id) || options.has_key?(:store)) - response = authorize(1, payment_source, options) + response = authorize(@options[:store_amount] || 1, payment_source, options) void(response.authorization) if response.success? response end diff --git a/test/remote/gateways/remote_ogone_test.rb b/test/remote/gateways/remote_ogone_test.rb index 8003596642c..9c613f573b3 100644 --- a/test/remote/gateways/remote_ogone_test.rb +++ b/test/remote/gateways/remote_ogone_test.rb @@ -163,17 +163,18 @@ def test_successful_store assert_success purchase end - def test_successful_store_generated_alias - assert response = @gateway.store(@credit_card) + def test_successful_store_with_store_amount_at_the_gateway_level + gateway = OgoneGateway.new(fixtures(:ogone).merge(:store_amount => 100)) + assert response = gateway.store(@credit_card, :billing_id => 'test_alias') assert_success response - assert purchase = @gateway.purchase(@amount, response.billing_id) + assert purchase = gateway.purchase(@amount, 'test_alias') assert_success purchase end - def test_successful_store - assert response = @gateway.store(@credit_card, :billing_id => 'test_alias') + def test_successful_store_generated_alias + assert response = @gateway.store(@credit_card) assert_success response - assert purchase = @gateway.purchase(@amount, 'test_alias') + assert purchase = @gateway.purchase(@amount, response.billing_id) assert_success purchase end diff --git a/test/unit/gateways/ogone_test.rb b/test/unit/gateways/ogone_test.rb index 09c597a105d..c07b3b85f5c 100644 --- a/test/unit/gateways/ogone_test.rb +++ b/test/unit/gateways/ogone_test.rb @@ -171,14 +171,22 @@ def test_successful_refund end def test_successful_store - @gateway.expects(:add_pair).at_least(1) - @gateway.expects(:add_pair).with(anything, 'ECI', '7') - @gateway.expects(:ssl_post).times(2).returns(successful_purchase_response) + @gateway.expects(:authorize).with(1, @credit_card, :billing_id => @billing_id).returns(OgoneResponse.new(true, '', @gateway.send(:parse, successful_purchase_response), :authorization => '3014726;RES')) + @gateway.expects(:void).with('3014726;RES') assert response = @gateway.store(@credit_card, :billing_id => @billing_id) assert_success response assert_equal '3014726;RES', response.authorization - assert_equal '2', response.billing_id - assert response.test? + assert_equal @billing_id, response.billing_id + end + + def test_store_amount_at_gateway_level + gateway = OgoneGateway.new(@credentials.merge(:store_amount => 100)) + gateway.expects(:authorize).with(100, @credit_card, :billing_id => @billing_id).returns(OgoneResponse.new(true, '', gateway.send(:parse, successful_purchase_response_100), :authorization => '3014726;RES')) + gateway.expects(:void).with('3014726;RES') + assert response = gateway.store(@credit_card, :billing_id => @billing_id) + assert_success response + assert_equal '3014726;RES', response.authorization + assert_equal @billing_id, response.billing_id end def test_deprecated_store_option @@ -258,7 +266,7 @@ def test_cvv_result def test_billing_id @gateway.expects(:ssl_post).returns(successful_purchase_response) response = @gateway.purchase(@amount, @credit_card) - assert_equal '2', response.billing_id + assert_equal @billing_id, response.billing_id end def test_order_id @@ -456,7 +464,32 @@ def successful_purchase_response currency="EUR" PM="CreditCard" BRAND="VISA" - ALIAS="2"> + ALIAS="#{@billing_id}"> + + END + end + + def successful_purchase_response_100 + <<-END + END end