Skip to content

Commit

Permalink
Revert "OPPS-225 Worldpay Idempotency key fix"
Browse files Browse the repository at this point in the history
This reverts commit bd5245f.
  • Loading branch information
jherreraa committed Dec 4, 2024
1 parent bd5245f commit bfb4833
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 18 deletions.
1 change: 0 additions & 1 deletion CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@
* FlexCharge: Update homePage url [javierpedrozaing] #5351
* Nuvei: Fix send savePM in false by default [javierpedrozaing] #5353
* Decidir and DecicirPlus: Add the wallet_id field [yunnydang] #5354
* Worldpay: Idempotency key fix [jherreraa] #5343

== Version 1.137.0 (August 2, 2024)
* Unlock dependency on `rexml` to allow fixing a CVE (#5181).
Expand Down
7 changes: 1 addition & 6 deletions lib/active_merchant/billing/gateways/worldpay.rb
Original file line number Diff line number Diff line change
Expand Up @@ -954,12 +954,7 @@ def headers(options)
cookie = options[:cookie] || cookie
headers['Cookie'] = cookie if cookie

# Required because Worldpay does not accept duplicate idempotency keys
# for different transactions, such as in the case of an authorize => capture flow.
if idempotency_key
headers['Idempotency-Key'] = idempotency_key
options[:idempotency_key] = SecureRandom.uuid
end
headers['Idempotency-Key'] = idempotency_key if idempotency_key
headers
end

Expand Down
10 changes: 5 additions & 5 deletions test/remote/gateways/remote_worldpay_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -306,17 +306,17 @@ def test_unsucessfull_authorize_without_token_number_apple_pay
response = @gateway.authorize(@amount, @apple_pay_network_token, @options)

assert_failure response
assert_equal response.error_code, '2'
assert_match "Missing required elements 'tokenNumber'", response.message
assert_equal response.error_code, '5'
assert_equal "Element 'tokenNumber' must have valid numeric content.", response.message
end

def test_unsucessfull_authorize_with_token_number_as_empty_string_apple_pay
@apple_pay_network_token.number = ''
response = @gateway.authorize(@amount, @apple_pay_network_token, @options)

assert_failure response
assert_equal response.error_code, '2'
assert_match "Missing required elements 'tokenNumber'", response.message
assert_equal response.error_code, '5'
assert_equal "Element 'tokenNumber' must have valid numeric content.", response.message
end

def test_unsucessfull_authorize_with_invalid_token_number_apple_pay
Expand Down Expand Up @@ -1342,7 +1342,7 @@ def test_failed_refund_synchronous_response

refund = @cftgateway.refund(@amount * 2, auth.authorization, authorization_validated: true)
assert_failure refund
assert_equal 'Invalid amount: The refund amount should be equal to the captured value', refund.message
assert_equal 'Refund amount too high', refund.message
end

def test_successful_purchase_with_options_synchronous_response
Expand Down
6 changes: 0 additions & 6 deletions test/unit/gateways/worldpay_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -223,12 +223,6 @@ def test_payment_type_for_credit_card
assert_equal payment, :credit
end

def test_idempotency_header
options = { idempotency_key: 'test123' }
headers = @gateway.send(:headers, options)
assert_not_equal options[:idempotency_key], headers['Idempotency-Key']
end

def test_successful_authorize
response = stub_comms do
@gateway.authorize(@amount, @credit_card, @options)
Expand Down

0 comments on commit bfb4833

Please sign in to comment.