Cancel order
Marks an existing Order as Cancelled when its current status is New.
/api/v1/orders/{orderId}/cancelCancelOrder transitions an existing order from New to Cancelled in Order APIServicev1.0.0Order APIAuthenticated Ordering service for Buyer profiles and the Order lifecycle,
creating Orders from baskets, snapshotting pr...PublishesGetBasketGrpc, GetBookGrpc +5SubscribesCreateOrder, CompleteOrder +11APIsOpenAPI, AsyncAPI, Carrier Service LevelsOwnercommerce-fulfillment-teamDiagramRepositoryOpen docs (PATCH /ordering/api/v1/orders/{orderId}/cancel) and triggers downstream cancellation orchestration through Kafka.
Overview
| Property | Value |
|---|---|
| Bounded Context | Ordering |
| Owner Service | Order APIServicev1.0.0Order APIAuthenticated Ordering service for Buyer profiles and the Order lifecycle, creating Orders from baskets, snapshotting pr...PublishesGetBasketGrpc, GetBookGrpc +5SubscribesCreateOrder, CompleteOrder +11APIsOpenAPI, AsyncAPI, Carrier Service LevelsOwnercommerce-fulfillment-teamDiagramRepositoryOpen docs |
| Protocol / Format | HTTP PATCH, application/json response |
| Gateway Endpoint | PATCH /ordering/api/v1/orders/{orderId}/cancel (service path /api/v1/orders/{orderId}/cancel) |
| Authentication & Authorization | Microsoft Entra ID JWT — customer or admin role plus scopes ordering_read, ordering_write |
| Idempotency / Concurrency | Required x-request-id header (Redis-backed 3600s TTL; returns 409 Conflict on duplicate); optimistic concurrency (412 Precondition Failed on conflict) |
| Rate Limit / Caching | Global concurrency (100), per-IP fixed-window (30 req/min), and per-user token bucket (30 burst, 20 per 10s, queue 5) |
| Contract Version | 1.0.0 (ApiVersions.V1) |
Request & Response Contract
Path Parameters & Headers
Accepts no request body.
| Name | Type | Required | Constraints | Description |
|---|---|---|---|---|
orderId | string (uuid) | Yes | Path parameter; valid UUID | Unique identifier of the order to cancel |
x-request-id | string | Yes | HTTP header; non-empty, non-whitespace | Client-generated idempotency key tracked in Redis for 3600 seconds |
Success Response (200 OK)
| Name | Type | Required | Constraints | Description |
|---|---|---|---|---|
id | string (uuid) | Yes | Valid UUID | Unique identifier of the cancelled order |
date | string (date-time) | Yes | ISO 8601 UTC timestamp | Creation timestamp |
total | number | Yes | Rounded to 2 decimal places | Sum of quantity * price across all order items |
status | string | Yes | "Cancelled" on success | Current lifecycle status |
items | object[] | Yes | Array of line items | Purchased items belonging to the order |
items[].id | string (uuid) | Yes | Valid UUID | Line item identifier |
items[].quantity | integer | Yes | > 0 | Purchased quantity for the item |
items[].price | number | Yes | >= 0, rounded to 2 decimal places | Unit price captured at order creation |
items[].name | string | null | No | Nullable | Book title (null in this response because catalog enrichment is not performed) |
Behavior & Side Effects
- Access scoping: Administrators can target any
Neworder; customers can only target orders matching their authenticated buyer ID. - State transition: Transitions
NewtoCancelled. Orders already inCancelledorCompletedstatus cannot transition again (admins receive404 Not Found; customers targeting their own non-Neworder receive500 Internal Server Error). - Event publishing: Appends the cancellation event to the event store and publishes Order cancelledEventv1.0.0Order cancelledReports that an Order transitioned from New to Cancelled.
Ownercommerce-fulfillment-teamSchemaDiagramOpen docs via transactional outbox to Order Cancellation Event ChannelChannelv1.0.0Order Cancellation Event ChannelKafka topic owned by the commerce-fulfillment-team carrying Order API events
when an order transitions from New to Cance...Ownercommerce-fulfillment-teamOpen docs (partitioned by
OrderId). - Idempotency key lifecycle: Claims the
x-request-idkey in Redis for 3600 seconds (409 Conflicton replay) and deletes the key if the operation fails with5xxso retries can proceed.
Error Responses
| Status / Code | Condition | Client Recovery Action |
|---|---|---|
400 Bad Request | Missing or whitespace x-request-id header, or invalid user identifier claim | Provide a non-empty x-request-id header and valid token claims; do not retry unchanged |
401 Unauthorized | Missing, expired, or invalid Entra ID bearer token | Acquire a fresh Entra ID access token and retry |
403 Forbidden | Caller lacks customer/admin role or ordering_read/ordering_write scopes | Request the required Entra ID role and scopes before retrying |
404 Not Found | Order does not exist, is soft-deleted, belongs to another buyer, or (for admin) is not in New status | Verify the orderId and current order status; do not retry unchanged |
409 Conflict | Duplicate x-request-id for this path within the 3600-second TTL | Treat as a duplicate submission and query order status before taking further action |
412 Precondition Failed | Concurrent update conflict on the order or event stream | Refresh order state and retry with a new x-request-id if still New |
429 Too Many Requests | Rate limit quota exceeded (Retry-After header included) | Wait for the Retry-After interval before retrying |
500 Internal Server Error | Customer attempted to cancel an owned order already in Cancelled or Completed status, or unhandled server failure | Inspect the order’s current status; do not retry non-New transitions |
Related Documentation
- Order APIServicev1.0.0Order APIAuthenticated Ordering service for Buyer profiles and the Order lifecycle, creating Orders from baskets, snapshotting pr...PublishesGetBasketGrpc, GetBookGrpc +5SubscribesCreateOrder, CompleteOrder +11APIsOpenAPI, AsyncAPI, Carrier Service LevelsOwnercommerce-fulfillment-teamDiagramRepositoryOpen docs — Service architecture, persistence, and endpoints.
- OrderEntityv1.0.0OrderDurable purchase record owned by a Buyer, capturing immutable purchase-time line items and governing order lifecycle tra...Ownercommerce-fulfillment-teamOpen docs — Order aggregate invariants and lifecycle statuses.
- Order cancelledEventv1.0.0Order cancelledReports that an Order transitioned from New to Cancelled. Ownercommerce-fulfillment-teamSchemaDiagramOpen docs — Kafka event emitted on cancellation.
- Order Cancellation Event ChannelChannelv1.0.0Order Cancellation Event ChannelKafka topic owned by the commerce-fulfillment-team carrying Order API events when an order transitions from New to Cance...Ownercommerce-fulfillment-teamOpen docs — Kafka topic specification.
- Complete orderCommandv1.0.0Complete orderMarks an existing Order as Completed when its current status is New.Ownercommerce-fulfillment-teamSchemaDiagramOpen docs — Transition a
Neworder toCompleted. - Delete orderCommandv1.0.0Delete orderSoft-deletes an Order by its identifier without changing its business status.Ownercommerce-fulfillment-teamSchemaDiagramOpen docs — Administrative soft-delete without status transition.
Cancel order schema
Path and header parameters for cancelling an Order. The operation has no request body.
Unique identifier of the Order to cancel.
Idempotency key for the cancellation request.