From a849db64a824129bdc5262e151a53df1107c2d68 Mon Sep 17 00:00:00 2001 From: aenand <89794007+aenand@users.noreply.github.com> Date: Wed, 8 May 2024 10:43:55 -0400 Subject: [PATCH] Worldpay: Update stored creds (#5114) * Worldpay: Update stored creds COMP-42 Adds tests to ensure stored credentials are passed for network tokens and adds the ability to override the NTID from the standard framework Test Summary Local: 5867 tests, 79281 assertions, 0 failures, 23 errors, 0 pendings, 0 omissions, 0 notifications 99.608% passed Unit: 117 tests, 662 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications 100% passed Remote: 104 tests, 447 assertions, 2 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications 98.0769% passed * remove ntid override * add test * changelog * rubocop --- CHANGELOG | 1 + .../billing/gateways/worldpay.rb | 1 + test/remote/gateways/remote_worldpay_test.rb | 8 ++++++ test/unit/gateways/worldpay_test.rb | 26 +++++++++++++++++++ 4 files changed, 36 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index b01a064f129..0e092e22a19 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -162,6 +162,7 @@ * Litle: Update commodity code and line item total fields [yunnydang] #5115 * Cybersource Rest: Add support for network tokens [aenand] #5107 * Decidir: Add support for customer object [rachelkirk] #5071 +* Worldpay: Add support for stored credentials with network tokens [aenand] #5114 == Version 1.135.0 (August 24, 2023) diff --git a/lib/active_merchant/billing/gateways/worldpay.rb b/lib/active_merchant/billing/gateways/worldpay.rb index f23cfcf3831..4171469544e 100644 --- a/lib/active_merchant/billing/gateways/worldpay.rb +++ b/lib/active_merchant/billing/gateways/worldpay.rb @@ -613,6 +613,7 @@ def add_network_tokenization_card(xml, payment_method, options) eci = eci_value(payment_method) xml.eciIndicator eci if eci.present? end + add_stored_credential_options(xml, options) end end diff --git a/test/remote/gateways/remote_worldpay_test.rb b/test/remote/gateways/remote_worldpay_test.rb index d03d4f8b7dc..3646d7ab1e2 100644 --- a/test/remote/gateways/remote_worldpay_test.rb +++ b/test/remote/gateways/remote_worldpay_test.rb @@ -180,6 +180,14 @@ def test_successful_purchase_with_network_token assert_equal 'SUCCESS', response.message end + def test_successful_purchase_with_network_token_and_stored_credentials + stored_credential_params = stored_credential(:initial, :unscheduled, :merchant) + + assert response = @gateway.purchase(@amount, @nt_credit_card, @options.merge({ stored_credential: stored_credential_params })) + assert_success response + assert_equal 'SUCCESS', response.message + end + def test_successful_purchase_with_network_token_without_eci_visa assert response = @gateway.purchase(@amount, @visa_nt_credit_card_without_eci, @options) assert_success response diff --git a/test/unit/gateways/worldpay_test.rb b/test/unit/gateways/worldpay_test.rb index 53c20f25e9e..f6215960a8a 100644 --- a/test/unit/gateways/worldpay_test.rb +++ b/test/unit/gateways/worldpay_test.rb @@ -330,6 +330,32 @@ def test_authorize_passes_stored_credential_options assert_success response end + def test_authorize_with_nt_passes_stored_credential_options + options = @options.merge( + stored_credential_usage: 'USED', + stored_credential_initiated_reason: 'UNSCHEDULED', + stored_credential_transaction_id: '000000000000020005060720116005060' + ) + response = stub_comms do + @gateway.authorize(@amount, @nt_credit_card, options) + end.check_request do |_endpoint, data, _headers| + assert_match(//, data) + assert_match(/000000000000020005060720116005060\<\/schemeTransactionIdentifier\>/, data) + end.respond_with(successful_authorize_response) + assert_success response + end + + def test_authorize_with_nt_passes_standard_stored_credential_options + stored_credential_params = stored_credential(:used, :unscheduled, :merchant, network_transaction_id: 20_005_060_720_116_005_060) + response = stub_comms do + @gateway.authorize(@amount, @nt_credit_card, @options.merge({ stored_credential: stored_credential_params })) + end.check_request do |_endpoint, data, _headers| + assert_match(//, data) + assert_match(/20005060720116005060\<\/schemeTransactionIdentifier\>/, data) + end.respond_with(successful_authorize_response) + assert_success response + end + def test_authorize_passes_correct_stored_credential_options_for_first_recurring options = @options.merge( stored_credential_usage: 'FIRST',