Skip to content

Commit

Permalink
Worldpay: Fix stored credentials unscheduled reason type
Browse files Browse the repository at this point in the history
Description
-------------------------
Unscheduled reason type should be sent in customer and merchant
initiated transactions, except when it's a customer initiated
transaction and usage=USED.

Unit tests
-------------------------
6119 tests, 80834 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications
100% passed

Remote tests
-------------------------
114 tests, 489 assertions, 3 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications
97.3684% passed

Failures not related to changes.

Rubocop
-------------------------
803 files inspected, no offenses detected
  • Loading branch information
Buitragox committed Dec 4, 2024
1 parent 2fe6ccb commit 80f1d1c
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
1 change: 0 additions & 1 deletion lib/active_merchant/billing/gateways/worldpay.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
40 changes: 35 additions & 5 deletions test/unit/gateways/worldpay_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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(/<storedCredentials usage\=\"USED\"\>/, data)
assert_match(/<storedCredentials usage\=\"USED\" merchantInitiatedReason\=\"UNSCHEDULED\"\>/, data)
assert_match(/<schemeTransactionIdentifier\>000000000000020005060720116005060\<\/schemeTransactionIdentifier\>/, data)
end.respond_with(successful_authorize_response)
assert_success response
Expand All @@ -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(/<storedCredentials usage\=\"USED\"\>/, data)
assert_match(/<storedCredentials usage\=\"USED\" merchantInitiatedReason\=\"UNSCHEDULED\"\>/, data)
assert_match(/<schemeTransactionIdentifier\>000000000000020005060720116005060\<\/schemeTransactionIdentifier\>/, data)
end.respond_with(successful_authorize_response)
assert_success response
Expand All @@ -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(/<storedCredentials usage\=\"USED\"\>/, data)
assert_match(/<storedCredentials usage\=\"USED\" merchantInitiatedReason\=\"UNSCHEDULED\"\>/, data)
assert_match(/<schemeTransactionIdentifier\>20005060720116005060\<\/schemeTransactionIdentifier\>/, data)
end.respond_with(successful_authorize_response)
assert_success response
Expand Down Expand Up @@ -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(/<storedCredentials usage="FIRST" merchantInitiatedReason="UNSCHEDULED">/, 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
Expand Down Expand Up @@ -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(/<storedCredentials usage\=\"FIRST\" customerInitiatedReason\=\"UNSCHEDULED\"\>/, 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'
Expand All @@ -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(/<storedCredentials usage\=\"USED\"\>/, data)
assert_not_match(/<schemeTransactionIdentifier\>000000000000020005060720116005060\<\/schemeTransactionIdentifier\>/, data)
end.respond_with(successful_authorize_response)
assert_success response
end
Expand Down

0 comments on commit 80f1d1c

Please sign in to comment.