Permalink
Browse files

Add support for custom currency at Gateway level. Helped by @rymai

  • Loading branch information...
1 parent 73f36b2 commit 5c62959013c5c37a94ad8230c418bbfd10e5969d @ZenCocoon ZenCocoon committed with jduff Oct 27, 2011
@@ -210,7 +210,7 @@ def add_authorization(post, authorization)
end
def add_money(post, money, options)
- add_pair post, 'currency', options[:currency] || currency(money)
+ add_pair post, 'currency', options[:currency] || @options[:currency] || currency(money)
add_pair post, 'amount', amount(money)
end
@@ -11,7 +11,8 @@ def setup
@options = {
:order_id => generate_unique_id[0...30],
:billing_address => address,
- :description => 'Store Purchase'
+ :description => 'Store Purchase',
+ :currency => fixtures(:ogone)[:currency] || 'EUR'
}
end
@@ -20,6 +21,7 @@ def test_successful_purchase
assert_success response
assert_equal OgoneGateway::SUCCESS_MESSAGE, response.message
assert_equal '7', response.params['ECI']
+ assert_equal @options[:currency], response.params["currency"]
end
def test_successful_purchase_with_utf8_encoding_1
@@ -82,6 +84,26 @@ def test_successful_purchase_with_custom_eci
assert_equal '4', response.params['ECI']
end
+ # NOTE: You have to allow USD as a supported currency in the "Account"->"Currencies"
+ # section of your account admin on https://secure.ogone.com/ncol/test/frame_ogone.asp before running this test
+ def test_successful_purchase_with_custom_currency_at_the_gateway_level
+ gateway = OgoneGateway.new(fixtures(:ogone).merge(:currency => 'USD'))
+ assert response = gateway.purchase(@amount, @credit_card)
+ assert_success response
+ assert_equal OgoneGateway::SUCCESS_MESSAGE, response.message
+ assert_equal "USD", response.params["currency"]
+ end
+
+ # NOTE: You have to allow USD as a supported currency in the "Account"->"Currencies"
+ # section of your account admin on https://secure.ogone.com/ncol/test/frame_ogone.asp before running this test
+ def test_successful_purchase_with_custom_currency
+ gateway = OgoneGateway.new(fixtures(:ogone).merge(:currency => 'EUR'))
+ assert response = gateway.purchase(@amount, @credit_card, @options.merge(:currency => 'USD'))
+ assert_success response
+ assert_equal OgoneGateway::SUCCESS_MESSAGE, response.message
+ assert_equal "USD", response.params["currency"]
+ end
+
def test_unsuccessful_purchase
assert response = @gateway.purchase(@amount, @declined_card, @options)
assert_failure response
@@ -150,6 +150,28 @@ def test_supported_card_types
def test_default_currency
assert_equal 'EUR', OgoneGateway.default_currency
+
+ gateway = OgoneGateway.new(@credentials)
+ gateway.expects(:add_pair).at_least(1)
+ gateway.expects(:add_pair).with(anything, 'currency', 'EUR')
+ gateway.expects(:ssl_post).returns(successful_purchase_response)
+ gateway.purchase(@amount, @credit_card, @options)
+ end
+
+ def test_custom_currency_at_gateway_level
+ gateway = OgoneGateway.new(@credentials.merge(:currency => 'USD'))
+ gateway.expects(:add_pair).at_least(1)
+ gateway.expects(:add_pair).with(anything, 'currency', 'USD')
+ gateway.expects(:ssl_post).returns(successful_purchase_response)
+ gateway.purchase(@amount, @credit_card, @options)
+ end
+
+ def test_local_custom_currency_overwrite_gateway_level
+ gateway = OgoneGateway.new(@credentials.merge(:currency => 'USD'))
+ gateway.expects(:add_pair).at_least(1)
+ gateway.expects(:add_pair).with(anything, 'currency', 'EUR')
+ gateway.expects(:ssl_post).returns(successful_purchase_response)
+ gateway.purchase(@amount, @credit_card, @options.merge(:currency => 'EUR'))
end
def test_avs_result

0 comments on commit 5c62959

Please sign in to comment.