**Not ready to build as written, but the fixes are small.** A few edits to the flow, about half a day of design work, would make it buildable. The payment steps can charge a customer twice or take their money without leaving an order.

## Must fix before coding

**1. Retrying the charge can double-charge the customer (step 4).**
- **Failing case:** the charge succeeds at the provider, but the response takes longer than 5 s. We time out and retry. The provider has no way to know it's the same attempt, so it charges again. The customer pays 2 to 4 times for one order.
- **Expected:** every attempt for one order sends the same idempotency key, for example the order id. The provider then returns the first result instead of charging again.
- **Design change:** state the key explicitly, and say what happens when all retries time out. The design doesn't say whether the order is paid in that case.

**2. A crash after the charge leaves a paid customer with no order (steps 3 to 6).**
- The `PENDING` insert and the charge sit inside one open transaction. If the service crashes, the database commit fails, or step 6 rolls back after a timeout that actually charged the card, the order row disappears but the money is taken.
- **Design change:** commit the `PENDING` order first, in its own short transaction. Then call the provider outside any transaction. Then record the result (`PAID`, `PAYMENT_FAILED`, or `PAYMENT_UNKNOWN`).
- Add a small job that finds old `PENDING` or `PAYMENT_UNKNOWN` orders and checks them against the provider.
- This also stops the transaction holding a database connection for up to 20 s while waiting on the provider (4 attempts at 5 s each).

**3. Stock handling is undefined (step 2).**
- The cache is up to 5 minutes old, and nothing says the order reduces stock. Two customers can buy the last item. At 2,000 orders a day that may be acceptable, but the design has to say so.
- **Design change:** either decrement the cached stock (or reserve it) when the order is created, or write down that overselling is accepted and what we do about it (cancel and refund, or backorder).

**4. Duplicate submissions from the client are not handled.**
- A double-click or a client retry on `POST /orders` creates two orders.
- **Design change:** accept a client-supplied idempotency key on `POST /orders` and return the existing order when it sees the same key again.

## Should fix (can be decided on day one)

- **Confirmation email:** it is sent in the request path after the commit. If the email fails, the customer's request fails even though they have paid. Send it after the response, or from the same retry job as above.
- **Backups:** nightly backups on a single instance mean a failure can lose up to a day of orders and payments. Either move to point-in-time recovery (WAL archiving), or accept the loss and say so.
- **Missing pieces:**
  - the request and response shapes
  - the error codes the client sees
  - the full list of order states
  - how refunds and cancellations work
  - authentication

## Tests (your standard says tests come first)

The test plan is one happy-path integration test plus per-module unit tests. That would not catch problems 1, 2 or 4. Add tests for:
- a charge timeout that retries with the same idempotency key
- a crash between the charge and the commit
- a duplicate `POST /orders`
- an oversell
- an email failure after payment

The code structure is sound: separate modules, thin routes, and an `OrderCheckout` class. The one note is to keep `OrderCheckout` as an orchestrator so it doesn't grow into a large class that does everything.

VERDICT: READY WITH CHANGES
