From df3c92c3e240516139b89e2bb03051e6c3e495ef Mon Sep 17 00:00:00 2001 From: Javier Pedroza Date: Mon, 9 Dec 2024 15:51:07 -0500 Subject: [PATCH] Nuvei: Update AFT request Description ------------------------- [SER-1543](https://spreedly.atlassian.net/browse/SER-1543) This commit update the AFT request to support non-domestic AFT Unit test ------------------------- Finished in 1.325061 seconds. 28 tests, 148 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications 100% passed 21.13 tests/s, 111.69 assertions/s Remote test ------------------------- Finished in 116.599139 seconds. 42 tests, 136 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications 100% passed 0.36 tests/s, 1.17 assertions/s Rubocop ------------------------- 806 files inspected, no offenses detected --- lib/active_merchant/billing/gateways/nuvei.rb | 11 ++++++++++- test/remote/gateways/remote_nuvei_test.rb | 4 ++-- test/unit/gateways/nuvei_test.rb | 13 +++++++++---- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/lib/active_merchant/billing/gateways/nuvei.rb b/lib/active_merchant/billing/gateways/nuvei.rb index e7029f900c2..c0ee2f40468 100644 --- a/lib/active_merchant/billing/gateways/nuvei.rb +++ b/lib/active_merchant/billing/gateways/nuvei.rb @@ -152,11 +152,20 @@ def add_account_funding_transaction(post, payment, options = {}) return unless options[:is_aft] recipient_details = { + firstName: options[:aft_recipient_first_name], + lastName: options[:aft_recipient_last_name] + }.compact + + address_details = { firstName: payment.first_name, lastName: payment.last_name, - country: options.dig(:billing_address, :country) + country: options.dig(:billing_address, :country), + address: options.dig(:billing_address, :address1), + city: options.dig(:billing_address, :city), + state: options.dig(:billing_address, :state) }.compact + post[:billingAddress].merge!(address_details) post[:recipientDetails] = recipient_details unless recipient_details.empty? end diff --git a/test/remote/gateways/remote_nuvei_test.rb b/test/remote/gateways/remote_nuvei_test.rb index d988baac128..c8f9c086077 100644 --- a/test/remote/gateways/remote_nuvei_test.rb +++ b/test/remote/gateways/remote_nuvei_test.rb @@ -416,13 +416,13 @@ def test_successful_purchase_with_google_pay end def test_purchase_account_funding_transaction - response = @gateway.purchase(@amount, @credit_card, @options.merge(is_aft: true)) + response = @gateway.purchase(@amount, @credit_card, @options.merge(is_aft: true, aft_recipient_first_name: 'John', aft_recipient_last_name: 'Doe')) assert_success response assert_equal 'APPROVED', response.message end def test_refund_account_funding_transaction - purchase_response = @gateway.purchase(@amount, @credit_card, @options) + purchase_response = @gateway.purchase(@amount, @credit_card, @options.merge(is_aft: true, aft_recipient_first_name: 'John', aft_recipient_last_name: 'Doe')) assert_success purchase_response refund_response = @gateway.refund(@amount, purchase_response.authorization) diff --git a/test/unit/gateways/nuvei_test.rb b/test/unit/gateways/nuvei_test.rb index 1ee7f5f34e7..77114beedc2 100644 --- a/test/unit/gateways/nuvei_test.rb +++ b/test/unit/gateways/nuvei_test.rb @@ -395,13 +395,18 @@ def test_successful_purchase_with_google_pay def test_successful_account_funding_transactions stub_comms(@gateway, :ssl_request) do - @gateway.purchase(@amount, @credit_card, @options.merge(is_aft: true)) + @gateway.purchase(@amount, @credit_card, @options.merge(is_aft: true, aft_recipient_first_name: 'John', aft_recipient_last_name: 'Doe')) end.check_request do |_method, endpoint, data, _headers| if /payment/.match?(endpoint) json_data = JSON.parse(data) - assert_match(@credit_card.first_name, json_data['recipientDetails']['firstName']) - assert_match(@credit_card.last_name, json_data['recipientDetails']['lastName']) - assert_match(@options[:billing_address][:country], json_data['recipientDetails']['country']) + assert_match('John', json_data['recipientDetails']['firstName']) + assert_match('Doe', json_data['recipientDetails']['lastName']) + assert_match(@credit_card.first_name, json_data['billingAddress']['firstName']) + assert_match(@credit_card.last_name, json_data['billingAddress']['lastName']) + assert_match(@options[:billing_address][:address1], json_data['billingAddress']['address']) + assert_match(@options[:billing_address][:city], json_data['billingAddress']['city']) + assert_match(@options[:billing_address][:state], json_data['billingAddress']['state']) + assert_match(@options[:billing_address][:country], json_data['billingAddress']['country']) end end.respond_with(successful_purchase_response) end