Skip to content

Commit

Permalink
Enabling of recurring_detail_reference gateway specific field in othe…
Browse files Browse the repository at this point in the history
…r transactions like purchase or refund for Adyen Gateway
  • Loading branch information
rubenmarindev committed Oct 11, 2024
1 parent d579b24 commit 3579503
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 6 deletions.
19 changes: 15 additions & 4 deletions lib/active_merchant/billing/gateways/adyen.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ def authorize(money, payment, options = {})
add_data_airline(post, options)
add_data_lodging(post, options)
add_metadata(post, options)
add_recurring_detail_reference(post, options)
commit('authorise', post, options)
end

Expand Down Expand Up @@ -115,7 +116,7 @@ def credit(money, payment, options = {})
post[:dateOfBirth] = options[:date_of_birth] if options[:date_of_birth]
post[:nationality] = options[:nationality] if options[:nationality]
end

add_recurring_detail_reference(post, options)
commit(action, post, options)
end

Expand All @@ -132,6 +133,7 @@ def adjust(money, authorization, options = {})
add_invoice_for_modification(post, money, options)
add_reference(post, authorization, options)
add_extra_data(post, nil, options)
add_recurring_detail_reference(post, options)
commit('adjustAuthorisation', post, options)
end

Expand Down Expand Up @@ -568,18 +570,27 @@ def add_invoice_for_modification(post, money, options)
end

def add_payment(post, payment, options, action = nil)
if payment.is_a?(String)
case payment
when String
_, _, recurring_detail_reference = payment.split('#')
post[:selectedRecurringDetailReference] = recurring_detail_reference
options[:recurring_contract_type] ||= 'RECURRING'
elsif payment.is_a?(Check)
when Check
add_bank_account(post, payment, options, action)
else
add_network_tokenization_card(post, payment, options) if payment.is_a?(NetworkTokenizationCreditCard) || options[:wallet_type] == :google_pay
add_network_tokenization_card(post, payment, options) if network_tokenization_payment?(payment, options)
add_card(post, payment)
end
end

def network_tokenization_payment?(payment, options)
payment.is_a?(NetworkTokenizationCreditCard) || options[:wallet_type] == :google_pay
end

def add_recurring_detail_reference(post, options)
post[:selectedRecurringDetailReference] = options[:recurring_detail_reference] if options[:recurring_detail_reference].present?
end

def add_bank_account(post, bank_account, options, action)
bank = {
bankAccountNumber: bank_account.account_number,
Expand Down
12 changes: 10 additions & 2 deletions test/remote/gateways/remote_adyen_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ def setup

@bank_account = check(account_number: '123456789', routing_number: '121000358')

@adyen_bank_account = check(account_number: '9876543210', routing_number: '021000021')

@declined_bank_account = check(account_number: '123456789', routing_number: '121000348')

@general_bank_account = check(name: 'A. Klaassen', account_number: '123456789', routing_number: 'NL13TEST0123456789')
Expand Down Expand Up @@ -1036,7 +1038,6 @@ def test_successful_store_with_bank_account

def test_successful_unstore
assert response = @gateway.store(@credit_card, @options)

assert !response.authorization.split('#')[2].nil?
assert_equal 'Authorised', response.message

Expand All @@ -1051,7 +1052,7 @@ def test_successful_unstore
end

def test_successful_unstore_with_bank_account
assert response = @gateway.store(@bank_account, @options)
assert response = @gateway.store(@adyen_bank_account, @options)

assert !response.authorization.split('#')[2].nil?
assert_equal 'Authorised', response.message
Expand Down Expand Up @@ -1594,6 +1595,13 @@ def test_successful_purchase_with_level_2_data
assert_equal '[capture-received]', response.message
end

def test_successful_response_with_recurring_detail_reference
response = @gateway.purchase(@amount, @credit_card, @options.merge(recurring_detail_reference: '12345'))

assert_success response
assert_equal '[capture-received]', response.message
end

def test_successful_authorize_with_level_3_data
level_3_data = {
total_tax_amount: '12800',
Expand Down
16 changes: 16 additions & 0 deletions test/unit/gateways/adyen_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,15 @@ def test_successful_authorize_with_shopper_interaction_ecommerce
end.respond_with(successful_authorize_response)
end

def test_successful_authorize_with_recurring_detail_reference
stub_comms do
@gateway.authorize(100, @credit_card, @options.merge(recurring_detail_reference: '12345'))
end.check_request do |_endpoint, data, _headers|
assert_equal 'john.smith@test.com', JSON.parse(data)['shopperEmail']
assert_equal '12345', JSON.parse(data)['selectedRecurringDetailReference']
end.respond_with(successful_authorize_response)
end

def test_adds_3ds1_standalone_fields
eci = '05'
cavv = '3q2+78r+ur7erb7vyv66vv\/\/\/\/8='
Expand Down Expand Up @@ -1374,6 +1383,13 @@ def test_successful_purchase_with_network_token
assert_success response
end

def test_successful_purchase_with_recurring_detail_reference
response = stub_comms do
@gateway.purchase(@amount, @credit_card, @options.merge(recurring_detail_reference: '12345'))
end.respond_with(successful_authorize_response, successful_capture_response)
assert_success response
end

def test_supports_network_tokenization
assert_instance_of TrueClass, @gateway.supports_network_tokenization?
end
Expand Down

0 comments on commit 3579503

Please sign in to comment.