Use Cases
Derived from model/model.yaml. The checkout service is built on develop (IQVO/checkout at 51e0379, checked 2026-12-02), released at v0.1.4 and applied to the k3s cluster: the api and the A2A agent are deployed, the MCP server is registered in warehouse-infra and switched off. Every Err... name, REST route and CloudEvents type of this context named on this page exists in the service; where the built service differs from the model's design, the page says so (As built) or the context's Service and operations section lists it.
One section per command of
contexts[checkout].aggregates[CheckoutSession].commands, plus the
ResolveInDoubtPlacements, ResolveStuckAuthorizations and RetryOwedVoids
policies. They are application services in
internal/application/usecases (as built). The step-by-step diagrams are on
Sequence Diagrams; the
payloads are on Domain Events;
the REST contract is storefront/apis/checkout/openapi.yaml.
Only OpenSession and ConfirmSession have a route. The seven Record...
and Expire commands are what the application service applies to the
aggregate after an outbound call has answered, so they are described as the
steps of the use case that drives them, and also once each below.
Reads are not use cases here: GET /checkout-sessions/{sessionId}
(GetSession) reads the repository directly. While a session is PLACING
after an in-doubt placement it is the endpoint the BFF polls. As built
(51e0379), GetSession is a use case in internal/application/usecases
that three inbound adapters share: the REST route, the MCP tool
get_checkout_session (cmd/mcp, L1 inform) and the A2A skill
checkout_session_status (cmd/a2a, L1 inform). No other use case has an
agent surface: OpenSession and ConfirmSession are REST only, so an agent
can ask where a session stands and can never open, confirm or expire one.
Triggers at a glance
| Use case | Trigger | Inbound adapter | Emits |
|---|---|---|---|
OpenSession | Shopper via storefront-bff | REST POST /checkout-sessions | CheckoutOpened |
ConfirmSession | Shopper via storefront-bff | REST POST /checkout-sessions/{sessionId}/confirmations | the outcome's event (see below) |
RecordAuthorization | The answer to AuthorizePayment | inside ConfirmSession | none |
RecordDecline | The answer to AuthorizePayment | inside ConfirmSession | CheckoutDeclined |
RecordPlacementInDoubt | PlaceOrder timed out or answered 503 | inside ConfirmSession or ResolveInDoubtPlacements | CheckoutPlacementInDoubt (first time only) |
RecordPlaced | PlaceOrder succeeded | inside ConfirmSession or ResolveInDoubtPlacements | CheckoutCompleted |
RecordRequoteRequired | PlaceOrder answered a definitive 409; sets voidOwed | inside ConfirmSession or ResolveInDoubtPlacements | CheckoutRequoteRequired |
RecordFailure | PlaceOrder answered 422; sets voidOwed | inside ConfirmSession or ResolveInDoubtPlacements | CheckoutFailed |
ExpireSession | Clock, policy ExpireOnQuoteExpiry | scheduler | CheckoutSessionExpired |
ResolveInDoubtPlacements | Clock, policy (backoff, alert at 20 h, give up and void at 22 h) | scheduler | as the Record... it ends in |
ResolveStuckAuthorizations | Clock, policy (AUTHORIZING over 2 minutes) | scheduler | as the Record... it ends in |
RetryOwedVoids | Clock, policy (every minute) | scheduler | none |
How save and publish commit
Every use case that changes the session loads it with its version, calls the
aggregate, then saves it inside one Postgres transaction. The save is
conditional on the version it loaded (UPDATE ... WHERE version = ?); a
conflict is retried once inside the use case, then surfaces as 409
concurrent-update. If an event is raised, the outbox row (outbox_events)
is written in the same transaction. A relay publishes outbox rows to
retailnetwork.checkout.events (CheckoutCompleted) and
retailnetwork.checkout.analytics (the other six) after the commit.
An outbound call is never inside a database transaction. The use cases
save the state they are about to act from (AUTHORIZING, PLACING with the
stored request), call out, then save the outcome. That is why a crash between
the two leaves a session a resolver can find: PLACING with a stored request.
Error responses use application/problem+json (RFC 9457) with type
/problems/<slug> per conventions.integration_rules: not-found 404,
illegal-transition 409, concurrent-update 409, validation-failed 422, plus
one kebab-case slug per Err in the model. Every write route takes an
Idempotency-Key header, minted by the BFF.
OpenSession
- Actor / trigger: the shopper, through
storefront-bff. - Inbound adapter: REST
POST /checkout-sessions, headerIdempotency-Keyrequired. - Input:
cartId,shopperId,shipToAddressId(a reference to a saved address incustomer-ordering(NG1), never the address). - Preconditions: the cart's checkout readiness holds; every selected
offer is still
QUOTEDand expires more than 2 minutes from now. - Main flow:
Idempotency-Keylookup; replay the stored response on a hit.GetCart(shopping-cart): the cart snapshot, its version, groups, selections and readiness.- Fail fast: if the snapshot's checkout readiness does not hold, answer
ErrCartNotCheckoutReadybefore calling anyone else (the aggregate enforces the same invariant in step 6). GetDeliveryOffer(delivery-promise) for each selected offer: stillQUOTEDand not expiring within 2 minutes; a failure here isErrOfferNotQuotable(422 offer-not-quotable, no session created, no state change). This check runs once, at open:ConfirmSessiondoes not repeat it.IssuePriceQuote(pricing): the bindingPriceQuote; the session recordspriceQuoteId,currency,totalMinorandquoteExpiresAt.CheckoutSession.OpenSession(cart, quote, now):ErrCartNotCheckoutReadyunless the readiness holds; lines numbered1..n, groups by the quote'sgroupNo(gap S1). In one transaction: insert the sessionOPEN, outboxCheckoutOpened, store the key response.- Answer
201with the session and its binding total.
- Errors:
| Error | HTTP | Problem type slug | Note |
|---|---|---|---|
ErrCartNotCheckoutReady | 409 | cart-not-checkout-ready | A group is unselected or an offer expired. |
| dependency unreachable | 503 | (503) | shopping-cart, delivery-promise or pricing; the shopper retries with the same Idempotency-Key. |
ErrOfferNotQuotable | 422 | offer-not-quotable | A selected offer is no longer QUOTED or expires within 2 minutes; no session is created, the BFF refreshes the cart's delivery quote. |
| invalid input | 422 | validation-failed | A missing cartId, shopperId or shipToAddressId. |
| version conflict | 409 | concurrent-update | Retried once inside the use case. |
- Events emitted:
CheckoutOpened(analytics). - Idempotency:
Idempotency-Key; the BFF mints one per open.
ConfirmSession
- Actor / trigger: the shopper, through
storefront-bff. - Inbound adapter: REST
POST /checkout-sessions/{sessionId}/confirmations, headerIdempotency-Keyrequired. - Input:
paymentMethodToken, the PSP token from the hosted fields, never a card number. - Preconditions: the session is
OPENorDECLINED; the price quote is unexpired. - Main flow:
Idempotency-Keylookup; replay the stored response on a hit.- Load
CheckoutSession(404not-found). ConfirmSession(now):ErrSessionClosedon a terminal state,ErrPlacementInDoubtwhilePLACING,ErrVoidPendingwhile a void is still owed,ErrPriceQuoteExpiredpastquoteExpiresAt;OPENorDECLINEDbecomesAUTHORIZING(fromDECLINED,authAttemptis incremented). Save. The offers are not re-checked here: the check ran at open, and an offer that expired between open and confirm comes back fromcustomer-orderingas aPLACING-time409requote (step 7).AuthorizePayment(customer-payments), key<sessionId>:auth:<authAttempt>, allocations per group. Declined:RecordDecline, answer200DECLINED. Authorized: continue.RecordAuthorization(authorizationId, totalMinor): if the authorized amount or currency is not the quote's, the session goes back toDECLINED(reasonauthorization-mismatch,CheckoutDeclinedraised) withvoidOwedset in the same save, and the call answers409 authorization-mismatch; otherwiseAUTHORIZINGbecomesPLACINGand the PII-free placement request is stored in the same save.PlaceOrder(customer-ordering) through the Anti-Corruption Layer,Idempotency-KeythesessionId,shipToAddressIdnever an inline address.- Map the answer: success to
RecordPlaced(COMPLETED, answer200); definitive409toRecordRequoteRequired(answer200REQUOTE_REQUIREDwithrequotedOffers);422toRecordFailureand an alert (answer200FAILED); timeout or503toRecordPlacementInDoubt(answer202, the session staysPLACING). For409and422the decision andvoidOwedare saved in one transaction, the void is then attempted at once, andRetryOwedVoidsretries it if it fails.
- Errors:
| Error | HTTP | Problem type slug | Note |
|---|---|---|---|
ErrSessionClosed | 409 | session-closed | COMPLETED, EXPIRED, FAILED or REQUOTE_REQUIRED; DECLINED is not closed. |
ErrPriceQuoteExpired | 422 | price-quote-expired | Checked at confirm; the session is OPEN or DECLINED; open a new session. |
ErrAuthorizationMismatch | 409 | authorization-mismatch | The authorized amount or currency is not the quote's; the session is DECLINED with the authorization owed a void (voidOwed). |
ErrVoidPending | 409 | void-pending | A new confirm while the void of a previous authorization is still owed; retry once RetryOwedVoids has voided it (one active authorization per session). |
ErrPlacementInDoubt | 409 | placement-in-doubt | A confirm or a void while PLACING: the semantic lock. |
| session not found | 404 | not-found | |
| invalid input | 422 | validation-failed | A missing paymentMethodToken. |
| version conflict | 409 | concurrent-update | Retried once inside the use case. |
- Events emitted: the event of the outcome:
CheckoutDeclined,CheckoutCompleted,CheckoutRequoteRequiredorCheckoutFailed; none for an in-doubt answer. - Idempotency:
Idempotency-Key, plus the deterministic downstream keys<sessionId>:auth:<authAttempt>(authAttemptstarts at 0), thesessionIdand<sessionId>:void. A repeated confirm returns the stored first response; a second authorize after a decline is a new attempt (authAttempt+ 1), so it is not answered with the first, declined response, while a stuck call replays the same key.
RecordAuthorization
- Trigger: the authorized answer to
AuthorizePayment, insideConfirmSession. - Main flow:
AUTHORIZING → PLACING; storeauthorizationIdand the placement request; save.ErrAuthorizationMismatchif the authorized amount or currency is not the quote's: the session goes back toDECLINED(reasonauthorization-mismatch) andvoidOwedis set in the same save. The use case alerts, attempts the void at once and answers409 authorization-mismatch;RetryOwedVoidsretries a failed void until it succeeds, and until then a new confirm is refused with409 void-pending. - Events emitted: none on success;
CheckoutDeclined(analytics) on a mismatch. - Idempotency: the transition is taken once; a replayed answer finds the
session already
PLACING.
RecordDecline
- Trigger: the declined answer to
AuthorizePayment. - Main flow:
AUTHORIZING → DECLINED; store the reason; save. The session stays open for another token while the price quote is valid; the nextConfirmSessionincrementsauthAttempt, andExpireOnQuoteExpirycan take it toEXPIRED. - Events emitted:
CheckoutDeclined(analytics). - Idempotency: a replayed confirm returns the stored response.
RecordPlacementInDoubt
- Trigger:
PlaceOrdertimed out or answered503; also each pass ofResolveInDoubtPlacementsthat still gets no definitive answer (the event is raised on the first one only). - Main flow:
PLACING → PLACING. No void and no new attempt: the semantic lock. The session answers202. - Events emitted:
CheckoutPlacementInDoubt(analytics; carriesplacingSince), on the first unknown outcome only; later passes ofResolveInDoubtPlacementsraise nothing. - Idempotency: the attempt counter and the next backoff are recorded on every pass; the event is written once.
RecordPlaced
- Trigger:
PlaceOrdersucceeded: the first call, or a replay answered with the first response. - Main flow: store
orderId;PLACING → COMPLETED; save. - Events emitted:
CheckoutCompleted(retailnetwork.checkout.events), consumed byshopping-cartandcustomer-payments. - Idempotency:
COMPLETEDhas no transition out (ErrSessionClosed); the event is written once.
RecordRequoteRequired
- Trigger:
PlaceOrderanswered a definitive409carrying re-quoted offers. - Main flow: store
requotedOffersand setvoidOwedto theauthorizationId;PLACING → REQUOTE_REQUIRED; save. The void (<sessionId>:void) is attempted at once and retried byRetryOwedVoids. - Events emitted:
CheckoutRequoteRequired(analytics). - Idempotency: terminal; the void is keyed
<sessionId>:void.
RecordFailure
- Trigger:
PlaceOrderanswered422, a contract bug. - Main flow: store the failure code, set
voidOwed, raise an alert;PLACING → FAILED; save. The void is attempted at once and retried byRetryOwedVoids. - Events emitted:
CheckoutFailed(analytics). - Idempotency: terminal; the void is keyed
<sessionId>:void.
ExpireSession
- Trigger: the
ExpireOnQuoteExpirypolicy: anOPENorDECLINEDsession expires with its price quote. - Inbound adapter: a scheduler, no route.
- Main flow:
OPEN → EXPIREDorDECLINED → EXPIRED; save. - Events emitted:
CheckoutSessionExpired(analytics). - Idempotency:
EXPIREDhas no transition out.
ResolveInDoubtPlacements (policy)
- Trigger: a scheduler, for every session in
PLACING. - Main flow:
- Load the session and its stored placement request.
- Re-send the stored body to
customer-orderingthrough the Anti-Corruption Layer with the sameIdempotency-Key(thesessionId);customer-orderingreplays its first response. - Apply the answer as in
ConfirmSessionstep 7:RecordPlaced, or a void thenRecordRequoteRequiredorRecordFailure, orRecordPlacementInDoubtagain. - Back off between passes; alert at 20 h (from
placingSince); give up and void at 22 h, beforecustomer-payments' 24 h backstop and the network's 24 h idempotency window.
- Errors: none surfaced to a shopper; the BFF polls
GetSession. - Idempotency: the same body and the same key on every pass, so a pass that
raced a slow first call cannot place a second order. The interplay with
customer-payments' 24 h void of an unbound authorization is ordered: alert at 20 h, give up and void at 22 h, backstop at 24 h.Voidis idempotent, so a race between the two is harmless.
ResolveStuckAuthorizations (policy)
- Trigger: a scheduler, for every session in
AUTHORIZINGfor more than 2 minutes (a crash or timeout between the save and the answer). - Main flow: re-call
AuthorizePaymentwith the SAME key<sessionId>:auth:<authAttempt>; it is idempotent and yields the true outcome. Apply it as inConfirmSession:RecordAuthorizationorRecordDecline. - Errors: none surfaced to a shopper; the BFF polls
GetSession. - Idempotency: the same key on every pass.
customer-payments' 24 h void stays the backstop.
RetryOwedVoids (policy)
- Trigger: a scheduler, every minute, for every session with
voidOwed. - Main flow: void the authorization named by
voidOwed(<sessionId>:void); on success clearvoidOwed. Covers theErrAuthorizationMismatchvoid and every definitive-rejection void. - Errors: none surfaced; retried until success.
- Idempotency:
Voidis idempotent.