Skip to content

Commit

Permalink
Nuvei: Update AFT request (#5364)
Browse files Browse the repository at this point in the history
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

Co-authored-by: Nick Ashton <nashton@gmail.com>
  • Loading branch information
javierpedrozaing and naashton authored Dec 12, 2024
1 parent e09bf17 commit 1dd6531
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
11 changes: 10 additions & 1 deletion lib/active_merchant/billing/gateways/nuvei.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions test/remote/gateways/remote_nuvei_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
13 changes: 9 additions & 4 deletions test/unit/gateways/nuvei_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1dd6531

Please sign in to comment.