Basket Lifecycle

A POS basket represents a single retail transaction. Understanding its lifecycle is critical for correct POS integration.

State Machine

                    POST /baskets
                         │
                         ▼
                    ┌─────────┐
                    │ Created │
                    └────┬────┘
                         │
           ┌─────────────┴─────────────┐
           │                           │
           ▼                           ▼
    POST .../finalize           POST .../void
           │                           │
           ▼                           ▼
     ┌──────────┐               ┌───────────┐
     │Finalized │               │   Voided  │
     └──────────┘               └───────────┘
StateDescription
CreatedBasket created, offers applied, pending payment
FinalizedPayment captured, loyalty points eligible
VoidedTransaction cancelled, no loyalty impact

Idempotency

Basket creation is idempotent on posTransactionId. This protects against network retries and duplicate submissions.

ScenarioRequestResponse
First submissionPOST /baskets with posTransactionId: TXN-001201 Created + basket object
Retry same transactionPOST /baskets with posTransactionId: TXN-001200 OK + existing basket (no duplicate)
New transactionPOST /baskets with posTransactionId: TXN-002201 Created + new basket

Always use a unique posTransactionId per transaction. Using the same ID for a genuinely different transaction will silently return the old basket.

Finalizing a Basket

Call finalize after payment is successfully captured. This locks the basket for reconciliation and makes the transaction eligible for loyalty point earn.

curl -X POST "http://localhost:5003/pos/api/v1/baskets/{basketId}/finalize" \
  -H "X-Api-Key: rsa_live_..."

Returns 204 No Content on success.

Voiding a Basket

Call void if the transaction is cancelled at any point before finalization:

curl -X POST "http://localhost:5003/pos/api/v1/baskets/{basketId}/void" \
  -H "X-Api-Key: rsa_live_..."

A finalized basket cannot be voided. To reverse a finalized transaction, create a reversal loyalty transaction via POST /pos/api/v1/loyalty/earn with a negative points value.

Retrieving a Basket

curl "http://localhost:5003/pos/api/v1/baskets/{basketId}" \
  -H "X-Api-Key: rsa_live_..."

Returns basket details including items, applied offers, totals, and current state.