Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nuvei: Update AFT request #5364

Merged
merged 2 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
javierpedrozaing marked this conversation as resolved.
Show resolved Hide resolved
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'))
javierpedrozaing marked this conversation as resolved.
Show resolved Hide resolved
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
Loading