Storefront has been decoupled into micro-frontends with a dedicated commerce app and shared shell.

Read the architecture guide →

Cancel order

Marks an existing Order as Cancelled when its current status is New.

Order Lifecycle
PATCH/api/v1/orders/{orderId}/cancel

CancelOrder 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

PropertyValue
Bounded ContextOrdering
Owner ServiceOrder 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 / FormatHTTP PATCH, application/json response
Gateway EndpointPATCH /ordering/api/v1/orders/{orderId}/cancel (service path /api/v1/orders/{orderId}/cancel)
Authentication & AuthorizationMicrosoft Entra ID JWT — customer or admin role plus scopes ordering_read, ordering_write
Idempotency / ConcurrencyRequired x-request-id header (Redis-backed 3600s TTL; returns 409 Conflict on duplicate); optimistic concurrency (412 Precondition Failed on conflict)
Rate Limit / CachingGlobal concurrency (100), per-IP fixed-window (30 req/min), and per-user token bucket (30 burst, 20 per 10s, queue 5)
Contract Version1.0.0 (ApiVersions.V1)

Request & Response Contract

Path Parameters & Headers

Accepts no request body.

NameTypeRequiredConstraintsDescription
orderIdstring (uuid)YesPath parameter; valid UUIDUnique identifier of the order to cancel
x-request-idstringYesHTTP header; non-empty, non-whitespaceClient-generated idempotency key tracked in Redis for 3600 seconds

Success Response (200 OK)

NameTypeRequiredConstraintsDescription
idstring (uuid)YesValid UUIDUnique identifier of the cancelled order
datestring (date-time)YesISO 8601 UTC timestampCreation timestamp
totalnumberYesRounded to 2 decimal placesSum of quantity * price across all order items
statusstringYes"Cancelled" on successCurrent lifecycle status
itemsobject[]YesArray of line itemsPurchased items belonging to the order
items[].idstring (uuid)YesValid UUIDLine item identifier
items[].quantityintegerYes> 0Purchased quantity for the item
items[].pricenumberYes>= 0, rounded to 2 decimal placesUnit price captured at order creation
items[].namestring | nullNoNullableBook title (null in this response because catalog enrichment is not performed)

Behavior & Side Effects

  • Access scoping: Administrators can target any New order; customers can only target orders matching their authenticated buyer ID.
  • State transition: Transitions New to Cancelled. Orders already in Cancelled or Completed status cannot transition again (admins receive 404 Not Found; customers targeting their own non-New order receive 500 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-id key in Redis for 3600 seconds (409 Conflict on replay) and deletes the key if the operation fails with 5xx so retries can proceed.

Error Responses

Status / CodeConditionClient Recovery Action
400 Bad RequestMissing or whitespace x-request-id header, or invalid user identifier claimProvide a non-empty x-request-id header and valid token claims; do not retry unchanged
401 UnauthorizedMissing, expired, or invalid Entra ID bearer tokenAcquire a fresh Entra ID access token and retry
403 ForbiddenCaller lacks customer/admin role or ordering_read/ordering_write scopesRequest the required Entra ID role and scopes before retrying
404 Not FoundOrder does not exist, is soft-deleted, belongs to another buyer, or (for admin) is not in New statusVerify the orderId and current order status; do not retry unchanged
409 ConflictDuplicate x-request-id for this path within the 3600-second TTLTreat as a duplicate submission and query order status before taking further action
412 Precondition FailedConcurrent update conflict on the order or event streamRefresh order state and retry with a new x-request-id if still New
429 Too Many RequestsRate limit quota exceeded (Retry-After header included)Wait for the Retry-After interval before retrying
500 Internal Server ErrorCustomer attempted to cancel an owned order already in Cancelled or Completed status, or unhandled server failureInspect the order’s current status; do not retry non-New transitions

Cancel order schema

2 properties

Path and header parameters for cancelling an Order. The operation has no request body.

orderIdstring
required

Unique identifier of the Order to cancel.

x-request-idstring
required

Idempotency key for the cancellation request.