Skip to content

Commit

Permalink
Add the fundingDestination field and fundingSource to authorize call
Browse files Browse the repository at this point in the history
  • Loading branch information
yunnydang authored and rachelkirk committed Jan 7, 2025
1 parent b99cdd0 commit 9a46606
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
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: '[email protected]'
},
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: '[email protected]'
},
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 '[email protected]', 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

0 comments on commit 9a46606

Please sign in to comment.