Skip to content

cancel-order ​

Method: POST
Path: /orders/{order_number}/cancel

Tags: Orders

Summary ​

Cancel order

Description ​

Cancels an order. Only available when is_cancellation_allowed is true on the order. Returns the updated OrderDetail object. A paid order is refunded what its payments have left, as cancellation_refund_details shows: by bank transfer to bank_account_id (required then) when its payment_mode is bank-transfer, else back through the payment gateway. A cash or other offline payment is handed back by the store in the way it was paid, with no bank account needed for it: the store owes it (a pending refund with payment_mode manual) until it does. Money held for an admin's review is not refunded at once: it is refunded when the review releases it. When the refund can't be made at that moment, the cancel fails with a 409 and nothing is changed: retry, or try again later.

Storefront SDK Usage ​

SDK Method: sdk.order.cancelOrder()

Example:

typescript
const { data, error } = await sdk.order.cancelOrder(
  { order_number: "ORD-2024-001" },
  {
    cancellation_reason: "Customer requested cancellation",
    refund_mode: "original_payment_mode",
    feedback: "Customer changed their mind about the purchase"
  }
);

if (error) {
  console.error("Failed to cancel order:", error.message);
} else {
  console.log("Order cancelled successfully");
  console.log("Updated order status:", data.order?.status);
  console.log("Cancellation reason:", data.order?.cancellation_reason);
}

TypeScript Definition ​

typescript
"cancel-order": {
        parameters: {
            query?: never;
            header?: {
                /** @description A ULID you propose as the `event_id` of the first entry this request returns in `events`. Used only when it is a valid ULID minted within a day of now and not already used; otherwise the server mints one. The `event_id` returned in `events` is the one to send. */
                "X-CE-Event-ID"?: components["parameters"]["ProposedEventId"];
            };
            path: {
                /** @description order number */
                order_number: string;
            };
            cookie?: never;
        };
        requestBody: {
            content: {
                "application/json": {
                    cancellation_reason: string;
                    /**
                     * @description The refund follows the order's `cancellation_refund_details.payment_mode`, whatever is sent here.
                     * @enum {string}
                     */
                    refund_mode: "original-payment-mode" | "bank-transfer";
                    /** @description The customer's verified bank account the refund is paid to. Required when `cancellation_refund_details.payment_mode` is `bank-transfer`. */
                    bank_account_id?: string;
                    /** @description feedback text */
                    feedback?: string;
                };
            };
        };
        responses: {
            /** @description OK */
            200: {
                headers: {
                    [name: string]: unknown;
                };
                content: {
                    "application/json": {
                        /** @default order details */
                        message: $Read<string>;
                        success: $Read<boolean>;
                        content: {
                            order?: components["schemas"]["OrderDetail"];
                        };
                        /** @description Analytics events to emit for the change this request made, each with a server-issued `event_id`. Replay them to your analytics destinations so your client-side and server-side copies of the same action dedupe. Empty when the request produced no analytics event. */
                        events: components["schemas"]["StorefrontResponseEvent"][];
                    };
                };
            };
            401: components["responses"]["Unauthorized"];
            404: components["responses"]["NotFound"];
            /** @description The paid order's refund can't be made at the moment: its payment changed since it was read, it is being reviewed by an admin, or refunds are briefly unavailable. Nothing is changed. */
            409: {
                headers: {
                    [name: string]: unknown;
                };
                content: {
                    "application/json": {
                        /**
                         * @example The order's payment was just updated. Please try again.
                         * @example This order's payment is being reviewed. Please try again later.
                         * @example A paid order's cancel waits for the payment ledger update to finish; try again shortly
                         */
                        message: string;
                        /** @default false */
                        success: boolean;
                    };
                };
            };
        };
    };

Component References ​

ReferenceResolves To
components["parameters"]["ProposedEventId"]ProposedEventId
components["schemas"]["OrderDetail"]OrderDetail
components["schemas"]["StorefrontResponseEvent"]StorefrontResponseEvent
components["responses"]["Unauthorized"]Unauthorized
components["responses"]["NotFound"]NotFound

Parameters ​

  • X-CE-Event-ID (header): A ULID you propose as the event_id of the first entry this request returns in events. Used only when it is a valid ULID minted within a day of now and not already used; otherwise the server mints one. The event_id returned in events is the one to send.
  • order_number (path): order number

Request Body ​

Content Types: application/json

Responses ​

200 ​

OK

401 ​

Not authorized for given operation on the Resource

404 ​

Requested resource not found

409 ​

The paid order's refund can't be made at the moment: its payment changed since it was read, it is being reviewed by an admin, or refunds are briefly unavailable. Nothing is changed.

OpenAPI Definition ​

json
{
  "tags": [
    "Orders"
  ],
  "operationId": "cancel-order",
  "summary": "Cancel order",
  "description": "Cancels an order. Only available when `is_cancellation_allowed` is `true` on the order. Returns the updated `OrderDetail` object. A paid order is refunded what its payments have left, as `cancellation_refund_details` shows: by bank transfer to `bank_account_id` (required then) when its `payment_mode` is `bank-transfer`, else back through the payment gateway. A cash or other offline payment is handed back by the store in the way it was paid, with no bank account needed for it: the store owes it (a `pending` refund with `payment_mode` `manual`) until it does. Money held for an admin's review is not refunded at once: it is refunded when the review releases it. When the refund can't be made at that moment, the cancel fails with a 409 and nothing is changed: retry, or try again later.",
  "externalDocs": {
    "url": "https://llm-docs.commercengine.io/storefront/operations/cancel-order",
    "description": "API reference for the cancel-order operation"
  },
  "parameters": [
    {
      "$ref": "#/components/parameters/ProposedEventId"
    },
    {
      "name": "order_number",
      "in": "path",
      "description": "order number",
      "required": true,
      "schema": {
        "type": "string"
      }
    }
  ],
  "requestBody": {
    "required": true,
    "content": {
      "application/json": {
        "schema": {
          "type": "object",
          "required": [
            "cancellation_reason",
            "refund_mode"
          ],
          "properties": {
            "cancellation_reason": {
              "type": "string"
            },
            "refund_mode": {
              "description": "The refund follows the order's `cancellation_refund_details.payment_mode`, whatever is sent here.",
              "type": "string",
              "enum": [
                "original-payment-mode",
                "bank-transfer"
              ]
            },
            "bank_account_id": {
              "description": "The customer's verified bank account the refund is paid to. Required when `cancellation_refund_details.payment_mode` is `bank-transfer`.",
              "type": "string"
            },
            "feedback": {
              "description": "feedback text",
              "type": "string"
            }
          }
        }
      }
    }
  },
  "responses": {
    "200": {
      "description": "OK",
      "content": {
        "application/json": {
          "schema": {
            "type": "object",
            "required": [
              "message",
              "success",
              "content",
              "events"
            ],
            "properties": {
              "message": {
                "type": "string",
                "default": "order details",
                "readOnly": true
              },
              "success": {
                "type": "boolean",
                "readOnly": true
              },
              "content": {
                "properties": {
                  "order": {
                    "$ref": "#/components/schemas/OrderDetail"
                  }
                },
                "type": "object"
              },
              "events": {
                "description": "Analytics events to emit for the change this request made, each with a server-issued `event_id`. Replay them to your analytics destinations so your client-side and server-side copies of the same action dedupe. Empty when the request produced no analytics event.",
                "type": "array",
                "items": {
                  "$ref": "#/components/schemas/StorefrontResponseEvent"
                }
              }
            }
          }
        }
      }
    },
    "401": {
      "$ref": "#/components/responses/Unauthorized"
    },
    "404": {
      "$ref": "#/components/responses/NotFound"
    },
    "409": {
      "description": "The paid order's refund can't be made at the moment: its payment changed since it was read, it is being reviewed by an admin, or refunds are briefly unavailable. Nothing is changed.",
      "content": {
        "application/json": {
          "schema": {
            "type": "object",
            "required": [
              "message",
              "success"
            ],
            "properties": {
              "message": {
                "type": "string",
                "examples": [
                  "The order's payment was just updated. Please try again.",
                  "This order's payment is being reviewed. Please try again later.",
                  "A paid order's cancel waits for the payment ledger update to finish; try again shortly"
                ]
              },
              "success": {
                "type": "boolean",
                "default": false
              }
            }
          }
        }
      }
    }
  },
  "security": [
    {
      "Authorization": []
    }
  ],
  "x-speakeasy-group": "orders",
  "x-speakeasy-ignore": false,
  "x-speakeasy-name-override": "cancelOrder"
}

Auto-generated from OpenAPI spec and TypeScript definitions

Last updated: