A checkout we reviewed marked orders as paid when the customer landed on /return?status=success after 3DS. It looked fine in testing, because the redirect and the gateway result always agreed.
In production they drifted apart in three ways:
- The customer pressed Back during the challenge and later reopened the return URL from browser history. The order flipped to paid on a stale redirect.
- The bank's ACS confirmed the challenge, but the authorization then declined at the issuer. The redirect still said the 3DS step succeeded, so the order was marked paid while no money moved.
- Anyone could edit the query string. Changing status=failed to status=success worked on a test order, because the handler never checked a signature.
The redirect only tells you the browser came back. It says nothing about the transaction.
What we changed: the return page now shows "checking your payment" and never writes order state. State changes only from the signed webhook, or from a server-side status call by transaction id when the webhook is late. The page polls our own order status for up to about 20 seconds, then tells the customer we'll email them.
The unpaid-but-shipped orders stopped, and so did the paid-but-not-fulfilled ones.
Do you let the return URL touch order state at all, or is that strictly webhook territory in your system?
Payneteasy handles this kind of payment flow for merchants and PSPs — see how it works.
Top comments (3)
Case 2 is the one that bites even when nobody is doing anything wrong. Two things I'd add to the webhook-only rule. Make the state change idempotent and one-directional: store the provider's transaction ID with a unique constraint and only move an order forward (pending, then paid, then refunded), so a duplicated or late event can't fulfill twice or flip a paid order back. And when you fall back to the server-side status call, treat "pending" as a real answer rather than an error, since some 3DS and bank flows stay pending for a while. Having the return page poll your own order table, like you describe, keeps the browser out of the decision entirely. Do you also run a periodic sweep for orders stuck in pending past some cutoff?
Strictly webhook territory here too, by the same reasoning from another business. On a prepaid top-up platform, the equivalent of your return URL was the cashier's screen: it showed what the terminal believed, not what the carrier did. And with the carriers there was no status call at all, only a reconciliation file every 24 hours, so an operation could sit "in progress" until the next day. You at least have the status call by transaction id.
The part your fix doesn't mention is the second attempt. In top-ups the double didn't need a wrong state write: it only needed the cashier to press again while the first one was still unknown. What helped was one id from the terminal through every hop, and a retry button that asked about that id first and showed "in progress, don't repeat it" instead of sending a new top-up.
When your page gives up after about 20 seconds and says you'll email them, what happens if the customer goes back to checkout and pays again for the same order? Is the new attempt tied to the pending one, or is it a fresh payment?
Editing status=failed to status=success and watching it work is the kind of test result that ends a debate.