Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into support_tokenized…
Browse files Browse the repository at this point in the history
…_cards_checkoutcom
  • Loading branch information
obahareth committed May 12, 2019
2 parents 9f6e4d4 + e5084d2 commit d847bfe
Show file tree
Hide file tree
Showing 8 changed files with 157 additions and 15 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
* 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
* Adyen: Support preAuths and Synchronous Adjusts [curiousepic] #3212

== Version 1.93.0 (April 18, 2019)
* Stripe: Do not consider a refund unsuccessful if only refunding the fee failed [jasonwebster] #3188
Expand Down
8 changes: 7 additions & 1 deletion lib/active_merchant/billing/gateways/adyen.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ def adjust(money, authorization, options={})
post = init_post(options)
add_invoice_for_modification(post, money, options)
add_reference(post, authorization, options)
add_extra_data(post, nil, options)
commit('adjustAuthorisation', post, options)
end

Expand Down Expand Up @@ -174,6 +175,9 @@ def add_extra_data(post, payment, options)
post[:additionalData][:overwriteBrand] = normalize(options[:overwrite_brand]) if options[:overwrite_brand]
post[:additionalData][:customRoutingFlag] = options[:custom_routing_flag] if options[:custom_routing_flag]
post[:additionalData]['paymentdatasource.type'] = NETWORK_TOKENIZATION_CARD_SOURCE[payment.source.to_s] if payment.is_a?(NetworkTokenizationCreditCard)
post[:additionalData][:authorisationType] = options[:authorisation_type] if options[:authorisation_type]
post[:additionalData][:adjustAuthorisationData] = options[:adjust_authorisation_data] if options[:adjust_authorisation_data]
post[:additionalData][:RequestedTestAcquirerResponseCode] = options[:requested_test_acquirer_response_code] if options[:requested_test_acquirer_response_code] && test?
post[:deviceFingerprint] = options[:device_fingerprint] if options[:device_fingerprint]
add_risk_data(post, options)
end
Expand Down Expand Up @@ -396,8 +400,10 @@ def success_from(action, response)
case action.to_s
when 'authorise', 'authorise3d'
['Authorised', 'Received', 'RedirectShopper'].include?(response['resultCode'])
when 'capture', 'refund', 'cancel', 'adjustAuthorisation'
when 'capture', 'refund', 'cancel'
response['response'] == "[#{action}-received]"
when 'adjustAuthorisation'
response['response'] == 'Authorised' || response['response'] == '[adjustAuthorisation-received]'
else
false
end
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
57 changes: 47 additions & 10 deletions test/remote/gateways/remote_adyen_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -365,36 +365,73 @@ def test_failed_void
assert_equal 'Original pspReference required for this operation', response.message
end

def test_successful_adjust
authorize = @gateway.authorize(@amount, @credit_card, @options)
def test_successful_asynchronous_adjust
authorize = @gateway.authorize(@amount, @credit_card, @options.merge(authorisation_type: 'PreAuth'))
assert_success authorize

assert adjust = @gateway.adjust(200, authorize.authorization)
assert adjust = @gateway.adjust(200, authorize.authorization, @options)
assert_success adjust
assert_equal '[adjustAuthorisation-received]', adjust.message
end

def test_successful_adjust_and_capture
authorize = @gateway.authorize(@amount, @credit_card, @options)
def test_successful_asynchronous_adjust_and_capture
authorize = @gateway.authorize(@amount, @credit_card, @options.merge(authorisation_type: 'PreAuth'))
assert_success authorize

assert adjust = @gateway.adjust(200, authorize.authorization)
assert adjust = @gateway.adjust(200, authorize.authorization, @options)
assert_success adjust
assert_equal '[adjustAuthorisation-received]', adjust.message

assert capture = @gateway.capture(200, authorize.authorization)
assert_success capture
end

def test_failed_adjust
auth = @gateway.authorize(@amount, @credit_card, @options)
assert_success auth
def test_failed_asynchronous_adjust
authorize = @gateway.authorize(@amount, @credit_card, @options.merge(authorisation_type: 'PreAuth'))
assert_success authorize

assert response = @gateway.adjust(200, '')
assert response = @gateway.adjust(200, '', @options)
assert_failure response
assert_equal 'Original pspReference required for this operation', response.message
end

# Requires Adyen to set your test account to Synchronous Adjust mode.
def test_successful_synchronous_adjust_using_adjust_data
authorize = @gateway.authorize(@amount, @credit_card, @options.merge(authorisation_type: 'PreAuth'))
assert_success authorize

options = @options.merge(adjust_authorisation_data: authorize.params['additionalData']['adjustAuthorisationData'])
assert adjust = @gateway.adjust(200, authorize.authorization, options)
assert_success adjust
assert_equal 'Authorised', adjust.message
end

# Requires Adyen to set your test account to Synchronous Adjust mode.
def test_successful_synchronous_adjust_and_capture
authorize = @gateway.authorize(@amount, @credit_card, @options.merge(authorisation_type: 'PreAuth'))
assert_success authorize

options = @options.merge(adjust_authorisation_data: authorize.params['additionalData']['adjustAuthorisationData'])
assert adjust = @gateway.adjust(200, authorize.authorization, options)
assert_success adjust
assert_equal 'Authorised', adjust.message

assert capture = @gateway.capture(200, authorize.authorization)
assert_success capture
end

# Requires Adyen to set your test account to Synchronous Adjust mode.
def test_failed_synchronous_adjust_using_adjust_data
authorize = @gateway.authorize(@amount, @credit_card, @options.merge(authorisation_type: 'PreAuth'))
assert_success authorize

options = @options.merge(adjust_authorisation_data: authorize.params['additionalData']['adjustAuthorisationData'],
requested_test_acquirer_response_code: '2')
assert adjust = @gateway.adjust(200, authorize.authorization, options)
assert_failure adjust
assert_equal 'Refused', adjust.message
end

def test_successful_store
assert response = @gateway.store(@credit_card, @options)

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[:multi_currency] = false
assert response = @multi_currency_gateway.purchase(@amount, @credit_card, @options.merge(currency: 'JPY', multi_currency: true))

assert_success response
assert response.test?
Expand Down
27 changes: 26 additions & 1 deletion test/unit/gateways/adyen_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,6 @@ def test_successful_adjust
response = @gateway.adjust(200, '8835544088660594')
assert_equal '8835544088660594#8835544088660594#', response.authorization
assert_equal '[adjustAuthorisation-received]', response.message
assert response.test?
end

def test_failed_adjust
Expand All @@ -325,6 +324,20 @@ def test_failed_adjust
assert_failure response
end

def test_successful_synchronous_adjust
@gateway.expects(:ssl_post).returns(successful_synchronous_adjust_response)
response = @gateway.adjust(200, '8835544088660594')
assert_equal '8835544088660594#8835574118820108#', response.authorization
assert_equal 'Authorised', response.message
end

def test_failed_synchronous_adjust
@gateway.expects(:ssl_post).returns(failed_synchronous_adjust_response)
response = @gateway.adjust(200, '8835544088660594')
assert_equal 'Refused', response.message
assert_failure response
end

def test_successful_store
response = stub_comms do
@gateway.store(@credit_card, @options)
Expand Down Expand Up @@ -708,6 +721,18 @@ def failed_adjust_response
RESPONSE
end

def successful_synchronous_adjust_response
<<-RESPONSE
{\"additionalData\":{\"authCode\":\"70125\",\"adjustAuthorisationData\":\"BQABAQA9NtGnJAkLXKqW1C+VUeCNMzDf4WwzLFBiuQ8iaA2Yvflz41t0cYxtA7XVzG2pzlJPMnkSK75k3eByNS0\\/m0\\/N2+NnnKv\\/9rYPn8Pjq1jc7CapczdqZNl8P9FwqtIa4Kdeq7ZBNeGalx9oH4reutlFggzWCr+4eYXMRqMgQNI2Bu5XvwkqBbXwbDL05CuNPjjEwO64YrCpVBLrxk4vlW4fvCLFR0u8O68C+Y4swmsPDvGUxWpRgwNVqXsTmvt9z8hlej21BErL8fPEy+fJP4Zab8oyfcLrv9FJkHZq03cyzJpOzqX458Ctn9sIwBawXzNEFN5bCt6eT1rgp0yuHeMGEGwrjNl8rijez7Rd\\/vy1WUYAAMfmZFuJMQ73l1+Hkr0VlHv6crlyP\\/FVTY\\/XIUiGMqa1yM08Zu\\/Gur5N7lU8qnMi2WO9QPyHmmdlfo7+AGsrKrzV4wY\\/wISg0pcv8PypBWVq\\/hYoCqlHsGUuIiyGLIW7A8LtG6\\/JqAA9t\\/0EdnQVz0k06IEEYnBzkQoY8Qv3cVszgPQukGstBraB47gQdVDp9vmuQjMstt8Te56SDRxtfcu0z4nQIURVSkJJNj8RYfwXH9OUbz3Vd2vwoR3lCJFTCKIeW8sidNVB3xAZnddBVQ3P\\/QxPnrrRdCcnoWSGoEOBBIxgF00XwNxJ4P7Xj1bB7oq3M7k99dgPnSdZIjyvG6BWKnCQcGyVRB0yOaYBaOCmN66EgWfXoJR5BA4Jo6gnWnESWV62iUC8OCzmis1VagfaBn0A9vWNcqKFkUr\\/68s3w8ixLJFy+WdpAS\\/flzC3bJbvy9YR9nESKAP40XiNGz9iBROCfPI2bSOvdFf831RdTxWaE+ewAC3w9GsgEKAXxzWsVeSODWRZQA0TEVOfX8SaNVa5w3EXLDsRVnmKgUH8yQnEJQBGhDJXg1sEbowE07CzzdAY5Mc=\",\"refusalReasonRaw\":\"AUTHORISED\"},\"pspReference\":\"8835574118820108\",\"response\":\"Authorised\"}
RESPONSE
end

def failed_synchronous_adjust_response
<<-RESPONSE
{\"additionalData\":{\"authCode\":\"90745\",\"refusalReasonRaw\":\"2\"},\"pspReference\":\"8835574120337117\",\"response\":\"Refused\"}
RESPONSE
end

def successful_verify_response
<<-RESPONSE
{
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

0 comments on commit d847bfe

Please sign in to comment.