A customer clicks Pay. Five seconds later, your server gives up waiting for the payment provider. The charge may have gone through. The customer is still looking at your checkout screen.
I'd show "We're checking your payment" and give them an order status page they can refresh. Keep the payment attempt pending there until you can confirm what happened.
Reuse the same payment attempt
For order ORD-42, save payment attempt PAY-7 and its provider idempotency key before you send the charge request. If the customer double-clicks or the request times out, the handler or worker can load that attempt again. If your provider supports idempotent retries, reuse the same key and check how long the provider honors it.
Once the provider confirms a decline, the customer can try another card with a new attempt ID. If the first charge is still unresolved, check its status before starting another attempt. Both cards could otherwise end up charged.
Handle a success that comes in twice
The webhook handler and the reconciliation worker may hear about the same successful charge a few seconds apart. Have both use the same database operation to move PAY-7 from pending to succeeded. Record the webhook event IDs you've processed and update the attempt only if it's still pending. In that transaction, also record the work that should follow, such as releasing the order for fulfillment.
You can queue that work. Have the fulfillment handler check whether it already acted on the order. A worker can send the instruction and then crash before acknowledging the message.
For the first test, have the provider simulator record a successful charge and drop the connection before replying. Retry from the client while two copies of the success webhook come in. Check that the customer sees one successful payment and the warehouse gets one fulfillment instruction.


