Handling payment API timeouts without double charges or duplicate orders
When a customer clicks Pay and the server times out waiting for the payment provider, the charge may already have succeeded. The author recommends showing a 'checking your payment' status page and keeping the attempt pending until the outcome is confirmed. Each payment attempt should be saved with a provider idempotency key before the charge request is sent, so retries reuse the same attempt. Webhook and reconciliation handlers should update the attempt from pending to succeeded in one conditional database operation, recording processed event IDs and queuing fulfillment work. Testing should simulate a successful charge with a dropped connection, retried requests, and duplicate webhooks to confirm the customer is charged once and fulfillment happens once.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in