When is a payment safe to turn into an order?
Check money on the server and record each payment once.
- The problem
- A stale browser total or a repeated payment notification must not create an incorrect order or consume inventory twice. The customer's confirmation and Stripe's automatic payment notification, called a webhook, can arrive together. Either can retry after a network failure.
- The approach
- The server reloads prices and calculates totals in cents. Payment amounts, currency, and order totals must agree. A database lock lets one request record a payment at a time; later requests return the existing order.
- Why this approach
- The browser requests a purchase; the server decides the price. The database prevents the same payment from consuming stock twice. Overlapping carts lock product codes, also called SKUs, in a consistent order.
- Another option
- Use a unique payment identifier to reject duplicate inserts. That prevents duplicate rows, but stock changes still need the same transaction.
- The tradeoff
- Checkout pauses if server data is unavailable. Stock is allocated after payment, so an item can move to preorder during processing; confirmation explains the change.
How it was checked. Local tests reject mismatched amounts, duplicate items, malformed quantities, and stale expectations. Database checks inspect SQL locking structure; simultaneous live transactions were not exercised.
More about the evidence
- Repository reviewServer checkout, payment-integrity validation, and the database recording transaction enforce the accounting and replay rules.

