Found this in a basket flow where the customer could edit the cart after a failed payment attempt.
The client generated the idempotency key once per checkout session and reused it for every attempt. First attempt: $80, soft decline from the issuer. The customer removed an item and retried at $60 with the same key.
The gateway did what idempotency is supposed to do. It matched the key and replayed the stored response, which was the original decline for $80. The customer saw "declined" again, tried a different card, got the same replay, and then opened a ticket. Nothing reached the issuer on attempts 2 and 3. Our logs showed three POSTs and three failures, so it looked like three real declines.
Some gateways return a 4xx when the key matches but the body differs. Others just replay the first response, and you only notice if you compare the amount in the response to the amount you sent.
The fix was small. The key is now derived from order_id plus a hash of amount, currency and payment method, and the client asserts that the response amount equals the request amount before it trusts the result.
Does your gateway reject a mismatched body on a reused key, or does it replay silently? Did you find out in testing or in production?
Payneteasy runs this kind of gateway for PSPs and payment companies — see how it works.
Top comments (1)
Deriving the key from order_id plus a hash of amount, currency and payment method is the right shape, because an edited cart is a new charge and deserves a new key. Stripe takes the opposite failure mode from your gateway: it rejects a reused key whose parameters differ instead of replaying the old result, which surfaces the bug but turns into a hard error if anything volatile, like a user-agent in metadata, ends up in the request. One cheap extra check is logging the key next to the charge ID that comes back, so three POSTs returning the same ID read as replays rather than three declines. Did you also change what support sees, so a replayed decline is labelled differently from a fresh one?