diff --git a/lib/active_merchant/billing/gateways/adyen.rb b/lib/active_merchant/billing/gateways/adyen.rb index b53e350cbc5..f71cbfe5337 100644 --- a/lib/active_merchant/billing/gateways/adyen.rb +++ b/lib/active_merchant/billing/gateways/adyen.rb @@ -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 @@ -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 @@ -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 @@ -569,18 +571,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, diff --git a/test/remote/gateways/remote_adyen_test.rb b/test/remote/gateways/remote_adyen_test.rb index 37589d0008f..f2e66686782 100644 --- a/test/remote/gateways/remote_adyen_test.rb +++ b/test/remote/gateways/remote_adyen_test.rb @@ -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') @@ -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 @@ -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 @@ -1592,6 +1593,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', diff --git a/test/unit/gateways/adyen_test.rb b/test/unit/gateways/adyen_test.rb index 7d3160411b8..57ac13eab93 100644 --- a/test/unit/gateways/adyen_test.rb +++ b/test/unit/gateways/adyen_test.rb @@ -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=' @@ -1382,6 +1391,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