Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Elavon: Multi-currency support #3210

Merged
merged 1 commit into from
May 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* Adyen: Add normalized hash of 3DS 2.0 data fields from web browsers [davidsantoso] #3207
* Stripe: Do not attempt application fee refund if refund was not successful [jasonwebster] #3206
* Elavon: Send transaction_currency if currency is provided [gcatlin] #3201
* Elavon: Multi-currency support [jknipp] #3210

== Version 1.93.0 (April 18, 2019)
* Stripe: Do not consider a refund unsuccessful if only refunding the fee failed [jasonwebster] #3188
Expand Down
3 changes: 2 additions & 1 deletion lib/active_merchant/billing/gateways/elavon.rb
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,8 @@ def add_creditcard(form, creditcard)
end

def add_currency(form, money, options)
form[:transaction_currency] = options[:currency] if options[:currency]
currency = options[:currency] || currency(money)
form[:transaction_currency] = currency if currency && (@options[:multi_currency] || options[:multi_currency])
end

def add_token(form, token)
Expand Down
7 changes: 7 additions & 0 deletions test/fixtures.yml
Original file line number Diff line number Diff line change
Expand Up @@ -275,10 +275,17 @@ efsnet:
password: Y

# Provided for url update test

elavon:
login: "009005"
user: "devportal"
password: "BDDZY5KOUDCNPV4L3821K7PETO4Z7TPYOJB06TYBI1CW771IDHXBVBP51HZ6ZANJ"

elavon_multi_currency:
login: "009006"
user: "devportal"
password: "XWJS3QTFCH40HW0QGHJKXAYADCTDH0TXXAKXAEZCGCCJ29CFNPCZT4KA9D5KQMDA"
multi_currency: true

element:
account_id: "1013963"
Expand Down
24 changes: 22 additions & 2 deletions test/remote/gateways/remote_elavon_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
class RemoteElavonTest < Test::Unit::TestCase
def setup
@gateway = ElavonGateway.new(fixtures(:elavon))
@multi_currency_gateway = ElavonGateway.new(fixtures(:elavon_multi_currency))

@credit_card = credit_card('4124939999999990')
@bad_credit_card = credit_card('invalid')
Expand Down Expand Up @@ -205,8 +206,27 @@ def test_successful_purchase_with_custom_fields
assert response.authorization
end

def test_successful_purchase_with_currency
assert response = @gateway.purchase(@amount, @credit_card, @options.merge(currency: 'JPY'))
def test_failed_purchase_with_multi_currency_terminal_setting_disabled
assert response = @gateway.purchase(@amount, @credit_card, @options.merge(currency: 'USD', multi_currency: true))

assert_failure response
assert response.test?
assert_equal 'Transaction currency is not allowed for this terminal. Your terminal must be setup with Multi currency', response.message
assert response.authorization
end

def test_successful_purchase_with_multi_currency_gateway_setting
assert response = @multi_currency_gateway.purchase(@amount, @credit_card, @options.merge(currency: 'JPY'))

assert_success response
assert response.test?
assert_equal 'APPROVAL', response.message
assert response.authorization
end

def test_successful_purchase_with_multi_currency_transaction_setting
@multi_currency_gateway.options.merge!(multi_currency: false)
assert response = @multi_currency_gateway.purchase(@amount, @credit_card, @options.merge(currency: 'JPY', multi_currency: true))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to test the gateway-level and option-level flags separately?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that's a holdover from before I changed to use a gateway-level flag. I'll add a new test.


assert_success response
assert response.test?
Expand Down
44 changes: 44 additions & 0 deletions test/unit/gateways/elavon_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ def setup
:password => 'password'
)

@multi_currency_gateway = ElavonGateway.new(
:login => 'login',
:user => 'user',
:password => 'password',
:multi_currency => true
)

@credit_card = credit_card
@amount = 100

Expand Down Expand Up @@ -115,6 +122,26 @@ def test_successful_authorization_with_ip
assert_success response
end

def test_successful_purchase_with_multi_currency
response = stub_comms(@multi_currency_gateway) do
@multi_currency_gateway.purchase(@amount, @credit_card, @options.merge(currency: 'EUR'))
end.check_request do |endpoint, data, headers|
assert_match(/ssl_transaction_currency=EUR/, data)
end.respond_with(successful_purchase_with_multi_currency_response)

assert_success response
end

def test_successful_purchase_without_multi_currency
response = stub_comms do
@gateway.purchase(@amount, @credit_card, @options.merge(currency: 'EUR', multi_currency: false))
end.check_request do |endpoint, data, headers|
assert_no_match(/ssl_transaction_currency=EUR/, data)
end.respond_with(successful_purchase_response)

assert_success response
end

def test_failed_capture
@gateway.expects(:ssl_post).returns(failed_authorization_response)
authorization = '123456INVALID;00000000-0000-0000-0000-00000000000'
Expand Down Expand Up @@ -298,6 +325,23 @@ def successful_purchase_response
ssl_txn_time=08/07/2009 09:54:18 PM"
end

def successful_purchase_with_multi_currency_response
"ssl_card_number=42********4242
ssl_exp_date=0910
ssl_amount=1.00
ssl_invoice_number=
ssl_description=Test Transaction
ssl_result=0
ssl_result_message=APPROVED
ssl_txn_id=00000000-0000-0000-0000-00000000000
ssl_approval_code=123456
ssl_cvv2_response=P
ssl_avs_response=X
ssl_account_balance=0.00
ssl_transaction_currency=EUR
ssl_txn_time=08/07/2009 09:54:18 PM"
end

def successful_refund_response
"ssl_card_number=42*****2222
ssl_exp_date=
Expand Down