wasAsked.

Design a React and ASP.NET Core checkout flow that remains safe when a customer submits the same payment twice.

Zoho · Full Stack Developer · 3-4-years · technical

Published

Year not specified · .NET, React, System Design

Community answers

Posted by wasAsked editorial collection

The key is idempotency: the same payment request processed twice must charge the customer only once. Frontend (React) - Disable the Pay button and show progress after the first click. - Generate an idempotency key (a UUID) when the checkout attempt starts, and send it with every retry of that attempt, for example in an Idempotency-Key header. - On a timeout, do not create a new attempt automatically; poll the order status or retry with the same key. Backend (ASP.NET Core) 1. Create the order first with status PendingPayment, inside a transaction. 2. Store the idempotency key with a unique constraint (user or merchant + key). If the key already exists, return the stored result instead of processing again; if it is still in progress, return 409 or 202 with the current status. 3. Call the payment provider and pass the same idempotency key — Stripe, Razorpay and most gateways support this, so even provider retries are safe. 4. Record the result and move the order to Paid or Failed. Webhooks - The provider confirms payment asynchronously. Verify the webhook signature, de-duplicate by provider event ID, and make the status update idempotent ("set Paid if not already Paid"). - Treat the webhook as the source of truth; the redirect back to the site can be lost. Concurrency and consistency - Use optimistic concurrency (a rowversion column) on the order so two parallel requests cannot both move it from Pending to Paid. - Use the outbox pattern to publish "OrderPaid" events reliably for emails and fulfilment. Reconciliation - A scheduled job compares orders stuck in Pending with the provider's records and fixes or refunds them. Also mention security: never trust amounts from the client; compute totals on the server, use HTTPS, and keep card data with the provider (PCI scope reduction).

Ravindra Wadile · · 0 likes

Sign in to add your answer

Related interview topics