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

# サブスクリプション製品の変更

> 既存サブスクリプション注文の製品を切り替える（近日公開）

有効なサブスクリプション注文に紐づく製品を切り替えます。

```
POST /v1/actions/subscription-order/change-product
```

**認証：** Session Token — [Customer Endpoints](/ja/api-reference/endpoints/auth/customer-endpoints) を参照（customer ロール）

<Warning>
  **近日公開** — このエンドポイントは未実装で、現在は `501 Not Implemented` を返却します。下記のリクエスト署名は暫定的なもので、GA 前に変更される可能性があります。未実装期間中はルートがロック状態になっており、呼び出してもサブスクリプションの状態は一切変更されません。
</Warning>

## リクエストボディ

| フィールド             | 型      | 必須 | 説明                                           |
| ----------------- | ------ | -- | -------------------------------------------- |
| `orderId`         | string | 必須 | 現在のサブスクリプション注文 ID（Short ID フォーマット `ORD_xxx`） |
| `targetProductId` | string | 必須 | 変更先の製品 ID（Short ID フォーマット `PROD_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.changeSubscriptionProduct({
    orderId: "ORD_2aUyqjCzEIiEcYMKj7TZtw",
    targetProductId: "PROD_36ZqlJPatGOsjz7AtYqAwj",
  });
  ```

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

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

  ```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","targetProductId":"PROD_36ZqlJPatGOsjz7AtYqAwj"}' \
    "https://api.waffo.ai/v1/actions/subscription-order/change-product"
  ```
</CodeGroup>

## 現在のレスポンス (501)

```json theme={"system"}
{
  "data": null,
  "errors": [
    {
      "message": "Not implemented",
      "layer": "order"
    }
  ]
}
```

### レスポンスフィールド（予定）

| フィールド     | 型      | 説明                       |
| --------- | ------ | ------------------------ |
| `orderId` | string | サブスクリプション注文 ID（Short ID） |
| `status`  | string | 製品変更後の注文ステータス            |

## エラー

> **リトライポリシー**：4xx は一切リトライしない — リクエストを修正してから再送信。5xx は指数バックオフでリトライ（5s 開始、最大 3 回）。

| ステータス | `errors[0].message`                       | 意味                                   | 推奨処理                        |
| ----- | ----------------------------------------- | ------------------------------------ | --------------------------- |
| 400   | `Missing required field: orderId`         | リクエストボディに `orderId` が含まれていない         | リクエストボディを修正してから再送信          |
| 400   | `Missing required field: targetProductId` | リクエストボディに `targetProductId` が含まれていない | リクエストボディを修正してから再送信          |
| 400   | `Expected format: ORD_xxx, got "..."`     | `orderId` Short ID のデコード失敗           | `orderId` のフォーマットを修正してから再送信 |
| 401   | `Authentication failed`                   | Session token が無効、期限切れ、または不正な形式      | Issue Session Token で再発行    |
| 403   | `Order does not belong to user`           | 所有権チェック失敗                            | 呼び出し元が注文を所有しているか確認          |
| 404   | `Order not found`                         | 注文が存在しない                             | order ID を確認                |
| 501   | `Not implemented`                         | エンドポイントは未提供                          | GA を待つ — リトライしない            |
| 500   | `Internal server error`                   | サーバ側の予期しない障害                         | 指数バックオフでリトライ（5s 開始、最大 3 回）  |
