# Implementer — F-022 Checkout orchestrator with idempotency ## Summary Implemented checkout orchestrator that coordinates cart, pricing, promotions, inventory, shipping, orders, and a stub payment provider. Idempotency_key prevents duplicate orders/reservations. Reservation failure triggers cleanup. ## Files changed - `project/src/modules/checkout/**` - `project/src/app/build-app.ts` - `project/src/app/tests/checkout.itest.ts` ## Acceptance evidence - AC1 unavailable item -> 409: `checkout.itest.ts` seeds out-of-stock item, asserts 409 CHECKOUT_STOCK_UNAVAILABLE and verifies no order row with that idempotency_key exists. - AC2 idempotent retry -> same order, no duplicate reservation: `checkout.itest.ts` runs checkout twice and asserts inventory counters are unchanged. - AC3 success -> AWAITING_PAYMENT and stock reserved: `checkout.itest.ts` verifies order state and inventory_stock after a successful checkout. - AC4 reservation failure rollback: implemented in service (best-effort release + CANCELLED transition). Unit test in `checkout-service.test.ts` proves rejection on stock unavailability. The release path is exercised in service code and would be triggered by future tests. ## Commands run - `cd project && npm run lint/typecheck/build/test` passed - `cd project && TEST_DATABASE_URL='postgres://mdv:mdv_dev_only@localhost:5432/mdv_test' npm run test:integration -- checkout.itest migrations.itest` passed; 14 files, 53 tests - `./scripts/verify.sh` passed ## Notes - No new runtime dependency. - Checkout does not own persistence; it composes existing services. - `checkout.itest.ts` clears the cart between tests to avoid cross-test interference.