> ## 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.

# 恢复订阅

> 恢复处于周期末取消（canceling）状态的订阅

恢复当前处于 `canceling` 状态的订阅。预约在周期末的取消会被撤销，订阅按原计划继续续费。

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

**认证方式：** Session Token — 见 [Customer Endpoints](/zh/api-reference/endpoints/auth/customer-endpoints)（customer 或 customer 角色）

## 恢复行为

| 当前状态                                          | 操作                      | 结果状态     |
| --------------------------------------------- | ----------------------- | -------- |
| `canceling`                                   | 撤销周期末取消（通过 PSP）         | `active` |
| `canceled`                                    | 不允许 — 已完全取消             | —        |
| `pending` / `active` / `past_due` / `expired` | 不允许 — 仅 `canceling` 可恢复 | —        |

<Note>
  * 仅 `canceling`（已预约周期末取消）状态的订阅可恢复。
  * 已完全取消（`canceled`）的订阅无法恢复 — 请创建新订阅。
  * 无额外费用 — 当前计费周期继续，并按原计划恢复续费。
</Note>

## 请求体

| 字段        | 类型     | 必需 | 说明                             |
| --------- | ------ | -- | ------------------------------ |
| `orderId` | string | 是  | 订阅订单 ID（Short ID 格式 `ORD_xxx`） |

## 请求示例

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

  const client = new WaffoPancake({
    sessionToken: window.WAFFO_SESSION_TOKEN, // 由商户门户注入
    environment: "prod",
  });

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

  console.log(result.orderId); // "ORD_2aUyqjCzEIiEcYMKj7TZtw"
  console.log(result.status);  // "active"
  ```

  ```typescript TypeScript (Manual) theme={"system"}
  const result = await fetch("https://api.waffo.ai/v1/actions/subscription-order/reactivate-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/reactivate-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/reactivate-order"
  ```
</CodeGroup>

## 成功响应 (200)

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

### 响应字段

| 字段        | 类型     | 说明               |
| --------- | ------ | ---------------- |
| `orderId` | string | 订单 ID（Short ID）  |
| `status`  | string | 新的订单状态（`active`） |

## 错误响应

> **重试策略**：4xx 一律不要重试 — 修正请求后重发。5xx 指数退避重试（起步 5s，最多 3 次）。

| 状态码 | `errors[0].message`                               | 含义                                                 | 推荐处理                        |
| --- | ------------------------------------------------- | -------------------------------------------------- | --------------------------- |
| 400 | `Missing required field: orderId`                 | 请求体未提供 `orderId`                                   | 修正请求体后重新提交                  |
| 400 | `Expected format: ORD_xxx, got "..."`             | `orderId` Short ID 解码失败                            | 修正 `orderId` 格式后重新提交        |
| 400 | `Only canceling subscriptions can be reactivated` | 订单状态非 `canceling`（如 `canceled`、`active`、`expired`） | 该订阅不可恢复                     |
| 401 | `Authentication failed`                           | Session token 无效、过期或格式错误                           | 通过 Issue Session Token 重新签发 |
| 403 | `Order does not belong to user`                   | 归属校验失败                                             | 验证调用方拥有该订单                  |
| 404 | `Order not found`                                 | 订单不存在                                              | 验证 order ID                 |
| 500 | `Internal server error`                           | 服务端意外失败                                            | 指数退避重试（起步 5s，最多 3 次）        |
