Skip to content

Commit

Permalink
ECS-3530 Adyen Format error fix
Browse files Browse the repository at this point in the history
[ECS-3530](https://spreedly.atlassian.net/browse/ECS-3530)

This PR fix format error using NT

Unit tests
----------------
Finished in 0.126432 seconds.

121 tests, 641 assertions, 0 failures,
0 errors, 0 pendings, 0 omissions, 0 notifications
100% passed

Remote tests
----------------
Finished in 609.957316 seconds.

143 tests, 464 assertions, 11 failures,
0 errors, 0 pendings, 0 omissions, 0 notifications
92.3077% passed

0.23 tests/s, 0.76 assertions/s

-> failures not related to change
  • Loading branch information
jherreraa authored and Alma Malambo committed Aug 14, 2024
1 parent 70e9830 commit 19370e2
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 14 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* Braintree: Updates to Paypal Integration [almalee24] #5190
* CommerceHub: Update test url [DustinHaefele] #5211
* Elavon: Update sending CVV for MIT transactions [almalee24] #5210
* Adyen: Fix NT integration [jherreraa] #5155

== Version 1.137.0 (August 2, 2024)
* Unlock dependency on `rexml` to allow fixing a CVE (#5181).
Expand Down
23 changes: 17 additions & 6 deletions lib/active_merchant/billing/gateways/adyen.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def authorize(money, payment, options = {})
add_3ds(post, options)
add_3ds_authenticated_data(post, options)
add_splits(post, options)
add_recurring_contract(post, options)
add_recurring_contract(post, options, payment)
add_network_transaction_reference(post, options)
add_application_info(post, options)
add_level_2_data(post, options)
Expand Down Expand Up @@ -625,20 +625,31 @@ def add_mpi_data_for_network_tokenization_card(post, payment, options)

post[:mpiData] = {}
post[:mpiData][:authenticationResponse] = 'Y'
post[:mpiData][:cavv] = payment.payment_cryptogram
if NETWORK_TOKENIZATION_CARD_SOURCE[payment.source.to_s].nil? && options[:switch_cryptogram_mapping_nt]
post[:mpiData][:tokenAuthenticationVerificationValue] = payment.payment_cryptogram
else
post[:mpiData][:cavv] = payment.payment_cryptogram
end
post[:mpiData][:directoryResponse] = 'Y'
post[:mpiData][:eci] = payment.eci || '07'
end

def add_recurring_contract(post, options = {})
return unless options[:recurring_contract_type]
def add_recurring_contract(post, options = {}, payment = nil)
return unless options[:recurring_contract_type] || (payment.try(:source) == :network_token && options[:switch_cryptogram_mapping_nt])

post[:recurring] = {}
post[:recurring][:contract] = options[:recurring_contract_type]
post[:recurring] ||= {}
post[:recurring][:contract] = options[:recurring_contract_type] if options[:recurring_contract_type]
post[:recurring][:recurringDetailName] = options[:recurring_detail_name] if options[:recurring_detail_name]
post[:recurring][:recurringExpiry] = options[:recurring_expiry] if options[:recurring_expiry]
post[:recurring][:recurringFrequency] = options[:recurring_frequency] if options[:recurring_frequency]
post[:recurring][:tokenService] = options[:token_service] if options[:token_service]
if payment.try(:source) == :network_token && options[:switch_cryptogram_mapping_nt]
post[:recurring][:contract] = 'EXTERNAL'
post[:recurring][:tokenService] = case payment.brand
when 'visa' then 'VISATOKENSERVICE'
else 'MCTOKENSERVICE'
end
end
end

def add_application_info(post, options)
Expand Down
22 changes: 15 additions & 7 deletions test/remote/gateways/remote_adyen_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ def test_successful_authorize_with_3ds2_browser_client_data
end

def test_successful_authorize_with_network_token
response = @gateway.authorize(@amount, @nt_credit_card, @options)
response = @gateway.authorize(@amount, @nt_credit_card, @options.merge(switch_cryptogram_mapping_nt: true))
assert_success response
assert_equal 'Authorised', response.message
end
Expand Down Expand Up @@ -562,7 +562,13 @@ def test_successful_purchase_with_shipping_default_country_code
end

def test_successful_purchase_with_apple_pay
response = @gateway.purchase(@amount, @apple_pay_card, @options)
response = @gateway.purchase(@amount, @apple_pay_card, @options.merge(switch_cryptogram_mapping_nt: true))
assert_success response
assert_equal '[capture-received]', response.message
end

def test_successful_purchase_with_apple_pay_with_ld_flag_false
response = @gateway.purchase(@amount, @apple_pay_card, @options.merge(switch_cryptogram_mapping_nt: false))
assert_success response
assert_equal '[capture-received]', response.message
end
Expand All @@ -580,7 +586,7 @@ def test_succesful_purchase_with_brand_override_with_execute_threed_false
end

def test_successful_purchase_with_google_pay
response = @gateway.purchase(@amount, @google_pay_card, @options)
response = @gateway.purchase(@amount, @google_pay_card, @options.merge(switch_cryptogram_mapping_nt: true))
assert_success response
assert_equal '[capture-received]', response.message
end
Expand Down Expand Up @@ -610,7 +616,7 @@ def test_successful_purchase_with_google_pay_without_billing_address_and_address
end

def test_successful_purchase_with_google_pay_and_truncate_order_id
response = @gateway.purchase(@amount, @google_pay_card, @options.merge(order_id: @long_order_id))
response = @gateway.purchase(@amount, @google_pay_card, @options.merge(order_id: @long_order_id, switch_cryptogram_mapping_nt: true))
assert_success response
assert_equal '[capture-received]', response.message
end
Expand All @@ -634,7 +640,7 @@ def test_successful_purchase_with_unionpay_card
end

def test_successful_purchase_with_network_token
response = @gateway.purchase(@amount, @nt_credit_card, @options)
response = @gateway.purchase(@amount, @nt_credit_card, @options.merge(switch_cryptogram_mapping_nt: true))
assert_success response
assert_equal '[capture-received]', response.message
end
Expand Down Expand Up @@ -1450,7 +1456,8 @@ def test_purchase_with_skip_mpi_data
first_options = options.merge(
order_id: generate_unique_id,
shopper_interaction: 'Ecommerce',
recurring_processing_model: 'Subscription'
recurring_processing_model: 'Subscription',
switch_cryptogram_mapping_nt: true
)
assert auth = @gateway.authorize(@amount, @apple_pay_card, first_options)
assert_success auth
Expand All @@ -1465,7 +1472,8 @@ def test_purchase_with_skip_mpi_data
skip_mpi_data: 'Y',
shopper_interaction: 'ContAuth',
recurring_processing_model: 'Subscription',
network_transaction_id: auth.network_transaction_id
network_transaction_id: auth.network_transaction_id,
switch_cryptogram_mapping_nt: true
)

assert purchase = @gateway.purchase(@amount, @apple_pay_card, used_options)
Expand Down
28 changes: 27 additions & 1 deletion test/unit/gateways/adyen_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1232,7 +1232,7 @@ def test_authorize_with_network_tokenization_credit_card_no_name

def test_authorize_with_network_tokenization_credit_card
response = stub_comms do
@gateway.authorize(@amount, @apple_pay_card, @options)
@gateway.authorize(@amount, @apple_pay_card, @options.merge(switch_cryptogram_mapping_nt: false))
end.check_request do |_endpoint, data, _headers|
parsed = JSON.parse(data)
assert_equal 'YwAAAAAABaYcCMX/OhNRQAAAAAA=', parsed['mpiData']['cavv']
Expand All @@ -1242,6 +1242,32 @@ def test_authorize_with_network_tokenization_credit_card
assert_success response
end

def test_authorize_with_network_tokenization_credit_card_using_ld_option
response = stub_comms do
@gateway.authorize(@amount, @apple_pay_card, @options.merge(switch_cryptogram_mapping_nt: true))
end.check_request do |_endpoint, data, _headers|
parsed = JSON.parse(data)
assert_equal 'YwAAAAAABaYcCMX/OhNRQAAAAAA=', parsed['mpiData']['cavv']
assert_equal '07', parsed['mpiData']['eci']
assert_equal 'applepay', parsed['additionalData']['paymentdatasource.type']
end.respond_with(successful_authorize_response)
assert_success response
end

def test_authorize_with_network_tokenization_credit_card_no_apple_no_google
response = stub_comms do
@gateway.authorize(@amount, @nt_credit_card, @options.merge(switch_cryptogram_mapping_nt: true))
end.check_request do |_endpoint, data, _headers|
parsed = JSON.parse(data)
assert_equal 'EHuWW9PiBkWvqE5juRwDzAUFBAk=', parsed['mpiData']['tokenAuthenticationVerificationValue']
assert_equal '07', parsed['mpiData']['eci']
assert_nil parsed['additionalData']['paymentdatasource.type']
assert_equal 'VISATOKENSERVICE', parsed['recurring']['tokenService']
assert_equal 'EXTERNAL', parsed['recurring']['contract']
end.respond_with(successful_authorize_response)
assert_success response
end

def test_authorize_and_capture_with_network_transaction_id
auth = stub_comms do
@gateway.authorize(@amount, @credit_card, @options)
Expand Down

0 comments on commit 19370e2

Please sign in to comment.