Skip to content

Commit

Permalink
Ogone: Add a :store_amount option
Browse files Browse the repository at this point in the history
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 activemerchant#724.
  • Loading branch information
rymai authored and ntalbott committed Sep 26, 2013
1 parent 383f3c5 commit 8aa99c3
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 21 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
28 changes: 20 additions & 8 deletions lib/active_merchant/billing/gateways/ogone.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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
#
Expand Down Expand Up @@ -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
Expand Down
13 changes: 7 additions & 6 deletions test/remote/gateways/remote_ogone_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
47 changes: 40 additions & 7 deletions test/unit/gateways/ogone_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -456,7 +464,32 @@ def successful_purchase_response
currency="EUR"
PM="CreditCard"
BRAND="VISA"
ALIAS="2">
ALIAS="#{@billing_id}">
</ncresponse>
END
end

def successful_purchase_response_100
<<-END
<?xml version="1.0"?><ncresponse
orderID="1233680882919266242708828"
PAYID="3014726"
NCSTATUS="0"
NCERROR="0"
NCERRORPLUS="!"
ACCEPTANCE="test123"
STATUS="5"
IPCTY="99"
CCCTY="99"
ECI="7"
CVCCheck="NO"
AAVCheck="NO"
VC="NO"
amount="100"
currency="EUR"
PM="CreditCard"
BRAND="VISA"
ALIAS="#{@billing_id}">
</ncresponse>
END
end
Expand Down

0 comments on commit 8aa99c3

Please sign in to comment.