From 30babca22293bb45454106caf74d5a85ced8d4ad Mon Sep 17 00:00:00 2001 From: Johan Herrera Date: Tue, 25 Jun 2024 15:38:30 -0500 Subject: [PATCH] ECS-3530 Adyen Format error fix [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 --- lib/active_merchant/billing/gateways/adyen.rb | 23 ++++++++++++++----- test/unit/gateways/adyen_test.rb | 17 +++++++++++++- 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/lib/active_merchant/billing/gateways/adyen.rb b/lib/active_merchant/billing/gateways/adyen.rb index 648cb4299a8..2136572051d 100644 --- a/lib/active_merchant/billing/gateways/adyen.rb +++ b/lib/active_merchant/billing/gateways/adyen.rb @@ -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) @@ -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) diff --git a/test/unit/gateways/adyen_test.rb b/test/unit/gateways/adyen_test.rb index e673cc9251b..7dbf67b1cac 100644 --- a/test/unit/gateways/adyen_test.rb +++ b/test/unit/gateways/adyen_test.rb @@ -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'] @@ -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)