From 8be37fddf5345d6f5f453c1056856c5353ef2c36 Mon Sep 17 00:00:00 2001 From: Javier Pedroza Date: Tue, 22 Oct 2024 10:48:21 -0500 Subject: [PATCH] Nuvei: Add card holder name verification params Description ------------------------- [SER-1456](https://spreedly.atlassian.net/browse/SER-1456) This commit add Cardholder name verification for request with transation type "Auth" Unit test ------------------------- Finished in 0.082292 seconds. 23 tests, 123 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications 100% passed 279.49 tests/s, 1494.68 assertions/s Remote test ------------------------- Finished in 131.369427 seconds. 33 tests, 101 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications 100% passed 0.25 tests/s, 0.77 assertions/s Rubocop ------------------------- 801 files inspected, no offenses detected --- lib/active_merchant/billing/gateways/nuvei.rb | 17 ++++++++++++++ test/remote/gateways/remote_nuvei_test.rb | 6 +++++ test/unit/gateways/nuvei_test.rb | 23 +++++++++++++++++++ 3 files changed, 46 insertions(+) diff --git a/lib/active_merchant/billing/gateways/nuvei.rb b/lib/active_merchant/billing/gateways/nuvei.rb index 5121c776eb6..f7202db9ec7 100644 --- a/lib/active_merchant/billing/gateways/nuvei.rb +++ b/lib/active_merchant/billing/gateways/nuvei.rb @@ -42,9 +42,11 @@ def authorize(money, payment, options = {}, transaction_type = 'Auth') add_address(post, payment, options) add_customer_ip(post, options) add_stored_credentials(post, payment, options) + add_cardholder_name_verification(post, payment, transaction_type, options) post[:userTokenId] = options[:user_token_id] if options[:user_token_id] post[:isPartialApproval] = options[:is_partial_approval] ? 1 : 0 post[:authenticationOnlyType] = options[:authentication_only_type] if options[:authentication_only_type] + if options[:execute_threed] execute_3ds_flow(post, money, payment, transaction_type, options) else @@ -258,6 +260,21 @@ def add_address(post, payment, options) }.compact end + def add_cardholder_name_verification(post, payment, transaction_type, options) + return unless transaction_type == 'Auth' + + post[:cardHolderNameVerification] = { performNameVerification: 'true' } if options[:perform_name_verification] + + cardholder_data = { + firstName: options[:cardholder_first_name], + middleName: options[:cardholder_middle_name], + lastName: options[:cardholder_last_name] + }.compact + + post[:billingAddress] ||= {} + post[:billingAddress].merge!(cardholder_data) + end + def execute_3ds_flow(post, money, payment, transaction_type, options = {}) post_3ds = post.dup diff --git a/test/remote/gateways/remote_nuvei_test.rb b/test/remote/gateways/remote_nuvei_test.rb index 30a840d1175..794aec33c46 100644 --- a/test/remote/gateways/remote_nuvei_test.rb +++ b/test/remote/gateways/remote_nuvei_test.rb @@ -325,4 +325,10 @@ def test_successful_purchase_with_google_pay assert_equal 'APPROVED', response.message assert_not_nil response.params[:paymentOption][:userPaymentOptionId] end + + def test_successful_authorize_with_cardholder_name_verification + response = @gateway.authorize(0, @credit_card, @options.merge({ perform_name_verification: true, cardholder_first_name: 'John', cardholder_middle_name: 'Due', cardholder_last_name: 'Tester' })) + assert_success response + assert_match 'APPROVED', response.message + end end diff --git a/test/unit/gateways/nuvei_test.rb b/test/unit/gateways/nuvei_test.rb index 1120356452b..8f3cc62781c 100644 --- a/test/unit/gateways/nuvei_test.rb +++ b/test/unit/gateways/nuvei_test.rb @@ -335,6 +335,29 @@ def test_successful_purchase_with_google_pay end.respond_with(successful_purchase_response) end + def test_successful_authorize_cardholder_name_verification + @options.merge!( + perform_name_verification: true, + cardholder_first_name: 'John', + cardholder_middle_name: 'M', + cardholder_last_name: 'Doe' + ) + + stub_comms(@gateway, :ssl_request) do + @gateway.authorize(@amount, @credit_card, @options) + end.check_request do |_method, endpoint, data, _headers| + json_data = JSON.parse(data) + if /payment/.match?(endpoint) + assert_match(%r(/payment), endpoint) + assert_match(/Auth/, json_data['transactionType']) + assert_equal 'true', json_data['cardHolderNameVerification']['performNameVerification'] + assert_equal 'John', json_data['billingAddress']['firstName'] + assert_equal 'M', json_data['billingAddress']['middleName'] + assert_equal 'Doe', json_data['billingAddress']['lastName'] + end + end.respond_with(successful_authorize_response) + end + private def three_ds_assertions(payment_option_card)