Skip to main content

Use Cases

Released at v0.1.4, applied to the k3s cluster

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 caseTriggerInbound adapterEmits
OpenSessionShopper via storefront-bffREST POST /checkout-sessionsCheckoutOpened
ConfirmSessionShopper via storefront-bffREST POST /checkout-sessions/{sessionId}/confirmationsthe outcome's event (see below)
RecordAuthorizationThe answer to AuthorizePaymentinside ConfirmSessionnone
RecordDeclineThe answer to AuthorizePaymentinside ConfirmSessionCheckoutDeclined
RecordPlacementInDoubtPlaceOrder timed out or answered 503inside ConfirmSession or ResolveInDoubtPlacementsCheckoutPlacementInDoubt (first time only)
RecordPlacedPlaceOrder succeededinside ConfirmSession or ResolveInDoubtPlacementsCheckoutCompleted
RecordRequoteRequiredPlaceOrder answered a definitive 409; sets voidOwedinside ConfirmSession or ResolveInDoubtPlacementsCheckoutRequoteRequired
RecordFailurePlaceOrder answered 422; sets voidOwedinside ConfirmSession or ResolveInDoubtPlacementsCheckoutFailed
ExpireSessionClock, policy ExpireOnQuoteExpiryschedulerCheckoutSessionExpired
ResolveInDoubtPlacementsClock, policy (backoff, alert at 20 h, give up and void at 22 h)scheduleras the Record... it ends in
ResolveStuckAuthorizationsClock, policy (AUTHORIZING over 2 minutes)scheduleras the Record... it ends in
RetryOwedVoidsClock, policy (every minute)schedulernone

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, header Idempotency-Key required.
  • Input: cartId, shopperId, shipToAddressId (a reference to a saved address in customer-ordering (NG1), never the address).
  • Preconditions: the cart's checkout readiness holds; every selected offer is still QUOTED and expires more than 2 minutes from now.
  • Main flow:
    1. Idempotency-Key lookup; replay the stored response on a hit.
    2. GetCart (shopping-cart): the cart snapshot, its version, groups, selections and readiness.
    3. Fail fast: if the snapshot's checkout readiness does not hold, answer ErrCartNotCheckoutReady before calling anyone else (the aggregate enforces the same invariant in step 6).
    4. GetDeliveryOffer (delivery-promise) for each selected offer: still QUOTED and not expiring within 2 minutes; a failure here is ErrOfferNotQuotable (422 offer-not-quotable, no session created, no state change). This check runs once, at open: ConfirmSession does not repeat it.
    5. IssuePriceQuote (pricing): the binding PriceQuote; the session records priceQuoteId, currency, totalMinor and quoteExpiresAt.
    6. CheckoutSession.OpenSession(cart, quote, now): ErrCartNotCheckoutReady unless the readiness holds; lines numbered 1..n, groups by the quote's groupNo (gap S1). In one transaction: insert the session OPEN, outbox CheckoutOpened, store the key response.
    7. Answer 201 with the session and its binding total.
  • Errors:
ErrorHTTPProblem type slugNote
ErrCartNotCheckoutReady409cart-not-checkout-readyA group is unselected or an offer expired.
dependency unreachable503(503)shopping-cart, delivery-promise or pricing; the shopper retries with the same Idempotency-Key.
ErrOfferNotQuotable422offer-not-quotableA selected offer is no longer QUOTED or expires within 2 minutes; no session is created, the BFF refreshes the cart's delivery quote.
invalid input422validation-failedA missing cartId, shopperId or shipToAddressId.
version conflict409concurrent-updateRetried 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, header Idempotency-Key required.
  • Input: paymentMethodToken, the PSP token from the hosted fields, never a card number.
  • Preconditions: the session is OPEN or DECLINED; the price quote is unexpired.
  • Main flow:
    1. Idempotency-Key lookup; replay the stored response on a hit.
    2. Load CheckoutSession (404 not-found).
    3. ConfirmSession(now): ErrSessionClosed on a terminal state, ErrPlacementInDoubt while PLACING, ErrVoidPending while a void is still owed, ErrPriceQuoteExpired past quoteExpiresAt; OPEN or DECLINED becomes AUTHORIZING (from DECLINED, authAttempt is 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 from customer-ordering as a PLACING-time 409 requote (step 7).
    4. AuthorizePayment (customer-payments), key <sessionId>:auth:<authAttempt>, allocations per group. Declined: RecordDecline, answer 200 DECLINED. Authorized: continue.
    5. RecordAuthorization(authorizationId, totalMinor): if the authorized amount or currency is not the quote's, the session goes back to DECLINED (reason authorization-mismatch, CheckoutDeclined raised) with voidOwed set in the same save, and the call answers 409 authorization-mismatch; otherwise AUTHORIZING becomes PLACING and the PII-free placement request is stored in the same save.
    6. PlaceOrder (customer-ordering) through the Anti-Corruption Layer, Idempotency-Key the sessionId, shipToAddressId never an inline address.
    7. Map the answer: success to RecordPlaced (COMPLETED, answer 200); definitive 409 to RecordRequoteRequired (answer 200 REQUOTE_REQUIRED with requotedOffers); 422 to RecordFailure and an alert (answer 200 FAILED); timeout or 503 to RecordPlacementInDoubt (answer 202, the session stays PLACING). For 409 and 422 the decision and voidOwed are saved in one transaction, the void is then attempted at once, and RetryOwedVoids retries it if it fails.
  • Errors:
ErrorHTTPProblem type slugNote
ErrSessionClosed409session-closedCOMPLETED, EXPIRED, FAILED or REQUOTE_REQUIRED; DECLINED is not closed.
ErrPriceQuoteExpired422price-quote-expiredChecked at confirm; the session is OPEN or DECLINED; open a new session.
ErrAuthorizationMismatch409authorization-mismatchThe authorized amount or currency is not the quote's; the session is DECLINED with the authorization owed a void (voidOwed).
ErrVoidPending409void-pendingA new confirm while the void of a previous authorization is still owed; retry once RetryOwedVoids has voided it (one active authorization per session).
ErrPlacementInDoubt409placement-in-doubtA confirm or a void while PLACING: the semantic lock.
session not found404not-found
invalid input422validation-failedA missing paymentMethodToken.
version conflict409concurrent-updateRetried once inside the use case.
  • Events emitted: the event of the outcome: CheckoutDeclined, CheckoutCompleted, CheckoutRequoteRequired or CheckoutFailed; none for an in-doubt answer.
  • Idempotency: Idempotency-Key, plus the deterministic downstream keys <sessionId>:auth:<authAttempt> (authAttempt starts at 0), the sessionId and <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, inside ConfirmSession.
  • Main flow: AUTHORIZING → PLACING; store authorizationId and the placement request; save. ErrAuthorizationMismatch if the authorized amount or currency is not the quote's: the session goes back to DECLINED (reason authorization-mismatch) and voidOwed is set in the same save. The use case alerts, attempts the void at once and answers 409 authorization-mismatch; RetryOwedVoids retries a failed void until it succeeds, and until then a new confirm is refused with 409 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 next ConfirmSession increments authAttempt, and ExpireOnQuoteExpiry can take it to EXPIRED.
  • Events emitted: CheckoutDeclined (analytics).
  • Idempotency: a replayed confirm returns the stored response.

RecordPlacementInDoubt​

  • Trigger: PlaceOrder timed out or answered 503; also each pass of ResolveInDoubtPlacements that 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 answers 202.
  • Events emitted: CheckoutPlacementInDoubt (analytics; carries placingSince), on the first unknown outcome only; later passes of ResolveInDoubtPlacements raise nothing.
  • Idempotency: the attempt counter and the next backoff are recorded on every pass; the event is written once.

RecordPlaced​

  • Trigger: PlaceOrder succeeded: 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 by shopping-cart and customer-payments.
  • Idempotency: COMPLETED has no transition out (ErrSessionClosed); the event is written once.

RecordRequoteRequired​

  • Trigger: PlaceOrder answered a definitive 409 carrying re-quoted offers.
  • Main flow: store requotedOffers and set voidOwed to the authorizationId; PLACING → REQUOTE_REQUIRED; save. The void (<sessionId>:void) is attempted at once and retried by RetryOwedVoids.
  • Events emitted: CheckoutRequoteRequired (analytics).
  • Idempotency: terminal; the void is keyed <sessionId>:void.

RecordFailure​

  • Trigger: PlaceOrder answered 422, 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 by RetryOwedVoids.
  • Events emitted: CheckoutFailed (analytics).
  • Idempotency: terminal; the void is keyed <sessionId>:void.

ExpireSession​

  • Trigger: the ExpireOnQuoteExpiry policy: an OPEN or DECLINED session expires with its price quote.
  • Inbound adapter: a scheduler, no route.
  • Main flow: OPEN → EXPIRED or DECLINED → EXPIRED; save.
  • Events emitted: CheckoutSessionExpired (analytics).
  • Idempotency: EXPIRED has no transition out.

ResolveInDoubtPlacements (policy)​

  • Trigger: a scheduler, for every session in PLACING.
  • Main flow:
    1. Load the session and its stored placement request.
    2. Re-send the stored body to customer-ordering through the Anti-Corruption Layer with the same Idempotency-Key (the sessionId); customer-ordering replays its first response.
    3. Apply the answer as in ConfirmSession step 7: RecordPlaced, or a void then RecordRequoteRequired or RecordFailure, or RecordPlacementInDoubt again.
    4. Back off between passes; alert at 20 h (from placingSince); give up and void at 22 h, before customer-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. Void is idempotent, so a race between the two is harmless.

ResolveStuckAuthorizations (policy)​

  • Trigger: a scheduler, for every session in AUTHORIZING for more than 2 minutes (a crash or timeout between the save and the answer).
  • Main flow: re-call AuthorizePayment with the SAME key <sessionId>:auth:<authAttempt>; it is idempotent and yields the true outcome. Apply it as in ConfirmSession: RecordAuthorization or RecordDecline.
  • 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 clear voidOwed. Covers the ErrAuthorizationMismatch void and every definitive-rejection void.
  • Errors: none surfaced; retried until success.
  • Idempotency: Void is idempotent.