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 committed Jun 27, 2024
1 parent 3805b4b commit 30babca
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 7 deletions.
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 @@ -622,20 +622,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 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.is_a?(NetworkTokenizationCreditCard)

post[:recurring] = {}
post[:recurring][:contract] = options[:recurring_contract_type]
if payment.is_a?(NetworkTokenizationCreditCard) && options[:switch_cryptogram_mapping_nt]
post[:recurring][:contract] = 'EXTERNAL'
post[:recurring][:tokenService] = case payment.brand
when 'visa' then 'VISATOKENSERVICE'
else 'MCTOKENSERVICE'
end
end
post[:recurring][:contract] = options[:recurring_contract_type] ||= post[:recurring][:contract]
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]
post[:recurring][:tokenService] = options[:token_service] if options[:token_service] ||= post[:recurring][:tokenService]
end

def add_application_info(post, options)
Expand Down
17 changes: 16 additions & 1 deletion test/unit/gateways/adyen_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1222,7 +1222,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 @@ -1232,6 +1232,21 @@ 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']['tokenAuthenticationVerificationValue']
assert_nil parsed['mpiData']['cavv']
assert_equal '07', parsed['mpiData']['eci']
assert_equal 'applepay', 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 30babca

Please sign in to comment.