The design is close, but the payment step as written can charge a customer twice or charge them and leave no order record. Fix that on paper before you build; it changes steps 3 to 6, not the module layout. The code structure (separate modules, thin routes, `OrderCheckout` owning the flow) is right for this scale and team size and needs no changes.

## What to change before building

**1. Retrying on timeout can double-charge.**
A timeout means "we don't know", not "the charge failed".
- **Case:** the provider processes the charge in 6 s, the service gives up at 5 s and retries, and the second attempt succeeds too.
- **Wrong result:** the customer is charged twice for one order.
- **Expected:** one charge.
- **Fix:** send an idempotency key (the order id) with every charge attempt, so the provider treats retries as the same charge.

**2. Rolling back can erase the only record of a charged order.**
The `PENDING` insert sits inside a transaction that stays open across the payment call, so the row is never visible until the final commit.
- **Case:** all three attempts time out but one actually went through at the provider, or the service crashes after the charge and before the commit.
- **Wrong result:** the customer is charged, the order row is rolled back, and nothing in the database says it happened.
- **Expected:** an order row that survives, so the charge can be matched or refunded.
- **Fix:** commit the `PENDING` order first, charge outside any transaction, then update the status in a second short transaction. Mark failures `FAILED` instead of deleting them.

This also stops a database connection being held for up to 15 s per slow checkout.

```mermaid
flowchart TD
    A[POST /orders] --> B[Check stock in inventory cache]
    B --> C[Insert order as PENDING and commit]
    C --> D[Charge payment provider<br/>idempotency key = order id]
    D -->|success| E[Mark PAID and commit]
    D -->|declined| F[Mark FAILED and commit]
    D -->|still unknown after retries| G[Leave PENDING]
    E --> H[Send confirmation email]
    G --> I[Scheduled job asks provider<br/>for charge status and resolves]
```

**3. Stuck `PENDING` orders need an owner.**
With the fix above, an order can stay `PENDING` when the outcome is unknown. A small scheduled job that asks the provider for the charge status and resolves the order is enough.

**4. Test the failure paths, not only the happy path.**
The plan lists one integration test, for the happy path. Add integration tests for timeout then success on retry, declined card, and unknown outcome after all retries. These are the paths where the money goes wrong.

## Decide, but not blocking

- **Overselling:** the design checks stock but never reserves or decrements it, and the cache can be 5 minutes stale. Two customers can both buy the last unit. At 200 orders a day, accepting this and handling it by refund or backorder is reasonable; write down which you chose.
- **Email failure:** state that a failed confirmation email does not fail the order, and that it is retried.

VERDICT: READY WITH CHANGES
