diff --git a/CHANGELOG b/CHANGELOG index aee70445e52..dc749a529d1 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -101,6 +101,7 @@ * Decidir and DecicirPlus: Add the wallet_id field [yunnydang] #5354 * Worldpay: Update where to pass shopperIPAddress [almalee24] #5348 * Braintree: Account for BraintreeError [almalee24] #5346 +* Worldpay: Fix stored credentials unscheduled reason type [Buitragox] #5352 == Version 1.137.0 (August 2, 2024) * Unlock dependency on `rexml` to allow fixing a CVE (#5181). diff --git a/lib/active_merchant/billing/gateways/worldpay.rb b/lib/active_merchant/billing/gateways/worldpay.rb index 495aead6d37..47b958f1090 100644 --- a/lib/active_merchant/billing/gateways/worldpay.rb +++ b/lib/active_merchant/billing/gateways/worldpay.rb @@ -1169,7 +1169,6 @@ def generate_stored_credential_params(is_initial_transaction, reason = nil, init stored_credential_params = {} stored_credential_params['usage'] = is_initial_transaction ? 'FIRST' : 'USED' - return stored_credential_params unless %w(RECURRING INSTALMENT).include?(reason) return stored_credential_params if customer_or_merchant == 'customerInitiatedReason' && stored_credential_params['usage'] == 'USED' stored_credential_params[customer_or_merchant] = reason if reason diff --git a/test/unit/gateways/worldpay_test.rb b/test/unit/gateways/worldpay_test.rb index 9b49ae02b67..d0e500b704c 100644 --- a/test/unit/gateways/worldpay_test.rb +++ b/test/unit/gateways/worldpay_test.rb @@ -422,7 +422,7 @@ def test_authorize_passes_stored_credential_options response = stub_comms do @gateway.authorize(@amount, @credit_card, options) end.check_request do |_endpoint, data, _headers| - assert_match(//, data) + assert_match(//, data) assert_match(/000000000000020005060720116005060\<\/schemeTransactionIdentifier\>/, data) end.respond_with(successful_authorize_response) assert_success response @@ -437,7 +437,7 @@ def test_authorize_with_nt_passes_stored_credential_options response = stub_comms do @gateway.authorize(@amount, @nt_credit_card, options) end.check_request do |_endpoint, data, _headers| - assert_match(//, data) + assert_match(//, data) assert_match(/000000000000020005060720116005060\<\/schemeTransactionIdentifier\>/, data) end.respond_with(successful_authorize_response) assert_success response @@ -448,7 +448,7 @@ def test_authorize_with_nt_passes_standard_stored_credential_options 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(//, data) assert_match(/20005060720116005060\<\/schemeTransactionIdentifier\>/, data) end.respond_with(successful_authorize_response) assert_success response @@ -495,6 +495,19 @@ def test_authorize_passes_correct_stored_credentials_for_first_installment assert_success response end + def test_authorize_passes_correct_stored_credentials_for_first_unscheduled + options = @options.merge( + stored_credential_usage: 'FIRST', + stored_credential_initiated_reason: 'UNSCHEDULED' + ) + response = stub_comms do + @gateway.authorize(@amount, @credit_card, options) + end.check_request do |_endpoint, data, _headers| + assert_match(//, data) + end.respond_with(successful_authorize_response) + assert_success response + end + def test_authorize_passes_sub_merchant_data options = @options.merge(@sub_merchant_options) response = stub_comms do @@ -1715,10 +1728,28 @@ def test_authorize_prefers_options_for_ntid assert_success response end + def test_authorize_stored_credentials_for_initial_customer_transaction + options = @options.merge!( + { + stored_credential: { + initial_transaction: true, + reason_type: 'unscheduled', + initiator: 'cardholder' + } + } + ) + + response = stub_comms do + @gateway.authorize(@amount, @credit_card, options) + end.check_request do |_endpoint, data, _headers| + assert_match(//, data) + end.respond_with(successful_authorize_response) + assert_success response + end + def test_authorize_stored_credentials_for_subsequent_customer_transaction options = @options.merge!({ stored_credential: { - network_transaction_id: '3812908490218390214124', initial_transaction: false, reason_type: 'recurring', initiator: 'cardholder' @@ -1729,7 +1760,6 @@ def test_authorize_stored_credentials_for_subsequent_customer_transaction @gateway.authorize(@amount, @credit_card, options) end.check_request do |_endpoint, data, _headers| assert_match(//, data) - assert_not_match(/000000000000020005060720116005060\<\/schemeTransactionIdentifier\>/, data) end.respond_with(successful_authorize_response) assert_success response end