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

Add the fundingDestination field and fundingSource to authorize call #5373

Merged
merged 1 commit into from
Jan 7, 2025
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
10 changes: 10 additions & 0 deletions lib/active_merchant/billing/gateways/adyen.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ def authorize(money, payment, options = {})
add_data_lodging(post, options)
add_metadata(post, options)
add_recurring_detail_reference(post, options)
add_fund_source(post, options)
add_fund_destination(post, options)
commit('authorise', post, options)
end

Expand Down Expand Up @@ -787,6 +789,7 @@ def add_fund_source(post, options)

post[:fundSource] = {}
post[:fundSource][:additionalData] = fund_source[:additional_data] if fund_source[:additional_data]
post[:fundSource][:shopperEmail] = fund_source[:shopper_email] if fund_source[:shopper_email]

if fund_source[:first_name] && fund_source[:last_name]
post[:fundSource][:shopperName] = {}
Expand All @@ -799,6 +802,13 @@ def add_fund_source(post, options)
end
end

def add_fund_destination(post, options)
return unless fund_destination = options[:fund_destination]

post[:fundDestination] = {}
post[:fundDestination][:additionalData] = fund_destination[:additional_data] if fund_destination[:additional_data]
end

def add_metadata(post, options = {})
return unless options[:metadata]

Expand Down
19 changes: 19 additions & 0 deletions test/remote/gateways/remote_adyen_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,25 @@ def test_successful_authorize_with_no_address
assert_equal 'Authorised', response.message
end

def test_successful_authorize_with_fund_source_and_fund_destination
fund_options = {
fund_source: {
additional_data: { fundingSource: 'Debit' },
first_name: 'Payer',
last_name: 'Name',
billing_address: @us_address,
shopper_email: 'john.smith@test.com'
},
fund_destination: {
additional_data: { walletIdentifier: '12345' }
}
}

response = @gateway.authorize(@amount, @credit_card, @options.merge!(fund_options))
assert_success response
assert_equal 'Authorised', response.message
end

def test_successful_authorize_with_credit_card_no_name
credit_card_no_name = ActiveMerchant::Billing::CreditCard.new({
number: '4111111111111111',
Expand Down
27 changes: 27 additions & 0 deletions test/unit/gateways/adyen_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,33 @@ def test_risk_data_sent
end.respond_with(successful_authorize_response)
end

def test_fund_source_and_fund_destination_sent
fund_options = {
fund_source: {
additional_data: { fundingSource: 'Debit' },
first_name: 'Payer',
last_name: 'Name',
billing_address: @us_address,
shopper_email: 'john.smith@test.com'
},
fund_destination: {
additional_data: { walletIdentifier: '12345' }
}
}

stub_comms do
@gateway.authorize(@amount, @credit_card, @options.merge(fund_options))
end.check_request do |_endpoint, data, _headers|
fund_source = JSON.parse(data)['fundSource']
fund_destination = JSON.parse(data)['fundDestination']
assert_equal 'john.smith@test.com', fund_source['shopperEmail']
assert_equal 'Payer', fund_source['shopperName']['firstName']
assert_equal 'Name', fund_source['shopperName']['lastName']
assert_equal 'Debit', fund_source['additionalData']['fundingSource']
assert_equal '12345', fund_destination['additionalData']['walletIdentifier']
end.respond_with(successful_authorize_response)
end

def test_manual_capture_sent
stub_comms do
@gateway.authorize(@amount, @credit_card, @options.merge(manual_capture: 'true'))
Expand Down
Loading