> ## Documentation Index
> Fetch the complete documentation index at: https://docs.waffo.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Cancel Subscription (Customer)

> Customer-side cancellation of a subscription using a session token

This is the customer-token call path of the same endpoint described in [Cancel Subscription (Merchant API Key)](/api-reference/endpoints/subscriptions/cancel-subscription). Behavior, request body, and response shape are identical — only the auth surface and the call site differ.

```
POST /v1/actions/subscription-order/cancel-order
```

**Authentication:** Session Token — see [Customer Endpoints](/api-reference/endpoints/auth/customer-endpoints) (customer or customer role)

<Note>
  The `orderId` must belong to the customer that the session token was minted for. Tokens minted for one customer cannot cancel another customer's subscription.
</Note>

## Cancellation Behavior

| Current Status | Action                         | Result Status                          |
| -------------- | ------------------------------ | -------------------------------------- |
| `pending`      | Immediate cancel               | `canceled`                             |
| `active`       | Cancel at period end (via PSP) | `canceling` → `canceled` at period end |

## Request Body

| Field     | Type   | Required | Description                                       |
| --------- | ------ | -------- | ------------------------------------------------- |
| `orderId` | string | Yes      | Subscription order ID (Short ID format `ORD_xxx`) |

## Example Request

<CodeGroup>
  ```typescript TypeScript (SDK) theme={"system"}
  import { WaffoPancake } from "@waffo/pancake-ts";

  const client = new WaffoPancake({
    sessionToken: window.WAFFO_SESSION_TOKEN, // injected by the merchant's portal
    environment: "prod",
  });

  const result = await client.orders.cancelSubscription({
    orderId: "ORD_2aUyqjCzEIiEcYMKj7TZtw",
  });

  console.log(result.orderId); // "ORD_2aUyqjCzEIiEcYMKj7TZtw"
  console.log(result.status);  // "canceling" or "canceled"
  ```

  ```typescript TypeScript (Manual) theme={"system"}
  const result = await fetch("https://api.waffo.ai/v1/actions/subscription-order/cancel-order", {
    method: "POST",
    headers: {
      "Authorization": `Bearer ${SESSION_TOKEN}`,
      "Content-Type": "application/json",
      "X-Environment": "prod",
    },
    body: JSON.stringify({
      orderId: "ORD_2aUyqjCzEIiEcYMKj7TZtw",
    }),
  }).then(r => r.json());
  ```

  ```bash cURL theme={"system"}
  curl -X POST "https://api.waffo.ai/v1/actions/subscription-order/cancel-order" \
    -H "Authorization: Bearer $SESSION_TOKEN" \
    -H "Content-Type: application/json" \
    -H "X-Environment: prod" \
    -d '{"orderId":"ORD_2aUyqjCzEIiEcYMKj7TZtw"}'
  ```

  ```bash wget theme={"system"}
  wget -qO- \
    --header="Authorization: Bearer $SESSION_TOKEN" \
    --header="Content-Type: application/json" \
    --header="X-Environment: prod" \
    --post-data='{"orderId":"ORD_2aUyqjCzEIiEcYMKj7TZtw"}' \
    "https://api.waffo.ai/v1/actions/subscription-order/cancel-order"
  ```
</CodeGroup>

## Success Response (200)

```json theme={"system"}
{
  "data": {
    "orderId": "ORD_2aUyqjCzEIiEcYMKj7TZtw",
    "status": "canceling"
  }
}
```

### Response Fields

| Field     | Type   | Description                                  |
| --------- | ------ | -------------------------------------------- |
| `orderId` | string | Order ID (Short ID)                          |
| `status`  | string | New order status (`canceling` or `canceled`) |

## Errors

> **Retry policy:** Never retry 4xx — fix the request and resubmit. Retry 5xx with exponential backoff (start 5s, max 3 attempts).

| Status | `errors[0].message`                                  | What it means                                                                               | Recommended handling                                      |
| ------ | ---------------------------------------------------- | ------------------------------------------------------------------------------------------- | --------------------------------------------------------- |
| 400    | `Missing required field: orderId`                    | `orderId` was not provided in the body                                                      | Fix the body, resubmit                                    |
| 400    | `Expected format: ORD_xxx, got "..."`                | `orderId` Short ID could not be decoded                                                     | Fix the `orderId` format, resubmit                        |
| 400    | `Subscription cannot be canceled, current status: X` | Order status is not `pending` or `active` (e.g. already `canceled`, `canceling`, `expired`) | The subscription is no longer cancellable                 |
| 401    | `Authentication failed`                              | Session token invalid, expired, or malformed                                                | Re-mint the session token via Issue Session Token         |
| 403    | `Order does not belong to user`                      | The token's customer is not the order owner                                                 | Mint a token for the correct customer                     |
| 404    | `Order not found`                                    | Order does not exist                                                                        | Verify the order ID                                       |
| 500    | `Internal server error`                              | Unexpected server-side failure                                                              | Retry with exponential backoff (start 5s, max 3 attempts) |
| 502    | `Failed to cancel subscription`                      | Local update or PSP cancellation failed                                                     | Retry with exponential backoff (start 5s, max 3 attempts) |
