**Not ready as written, but it can be by tomorrow.** The payment steps (3 to 6) can charge a customer twice or charge them with no order on record. The fixes are known and small, and the rest (module boundaries, thin routes, single Postgres at 2,000 orders a day) is sound.

## Must change before writing payment code

**1. Retrying on timeout can double-charge.**
A timeout means "no answer", not "no charge". For example, the provider charges the card in 6 s, the service gives up at 5 s and retries, and the customer is charged twice for one order.
- **Fix:** send an idempotency key (the order id) with every charge attempt, so the provider treats retries as the same charge.
- **To confirm:** check today that your provider supports idempotency keys. Most do, and this is the only item that depends on someone outside the team.

**2. A rollback can erase the order after the money has moved.**
The `PENDING` insert and the charge sit in one open transaction. For example, the charge succeeds, then the service crashes or the commit fails, and the customer is charged while the database has no trace of the order. The same happens when all three retries time out but one charge actually went through.
- **Fix:** commit the `PENDING` order first, call the provider outside any transaction, then update to `PAID` or `FAILED` in a second short transaction.
- **Side benefit:** a database connection is no longer held for up to 20 s per slow checkout.

**3. Nothing recovers an order stuck in `PENDING`.**
Once fix 2 is in, a crash mid-charge leaves a `PENDING` row.
- **Fix:** add a scheduled job that asks the provider for the charge status of any order `PENDING` longer than a few minutes and settles it.

**4. A repeated `POST /orders` creates a second order and a second charge.**
For example, the customer double-clicks "Pay", or the mobile client retries on a flaky network.
- **Fix:** have the client send an idempotency key, and put a unique constraint on it.

## Revised flow

```mermaid
flowchart TD
    A[POST /orders with client idempotency key] --> B[Check stock]
    B --> C[Insert order as PENDING and commit]
    C --> D[Charge provider, order id as idempotency key, retry on timeout]
    D -->|success| E[Mark PAID, commit]
    D -->|declined| F[Mark FAILED, commit, return error]
    D -->|still unknown| G[Leave PENDING, return 'processing']
    E --> H[Send confirmation email]
    G --> I[Scheduled job asks provider and settles the order]
```

## Decide, but not blocking

- **Overselling:** the flow checks stock but never reserves or decrements it, and the cache is up to 5 minutes old. Two customers can both buy the last unit. At 200 orders a day that may be acceptable, but the doc should say what happens then (refund and apologise, or backorder).
- **Lost confirmation email:** if the send fails after commit, nothing retries it. A `confirmation_sent` flag picked up by the same scheduled job would cover it.
- **Backups:** nightly-only means a disk failure at 5 pm loses the day's paid orders. Continuous WAL archiving closes that gap cheaply.

## Test plan gap

One happy-path integration test leaves every failure above uncovered. Add integration tests against a fake provider, written before the code, for:
- timeout then success, asserting one charge;
- a declined card;
- a crash after the charge, asserting the scheduled job settles the order;
- a duplicate `POST`, asserting one order.

VERDICT: READY WITH CHANGES
