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

# ワンタイム注文のキャンセル

> 支払い完了前の保留中ワンタイム注文をキャンセルする

保留中のワンタイム注文をキャンセルします。`pending` ステータスの注文のみキャンセル可能です。

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

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

## キャンセル動作

| 現在のステータス    | アクション   | 結果ステータス    |
| ----------- | ------- | ---------- |
| `pending`   | 即時キャンセル | `canceled` |
| `completed` | 拒否      | 変更なし（終端状態） |
| `canceled`  | 拒否      | 変更なし（終端状態） |

<Note>
  * **pending**: 注文は即時キャンセルされ、ステータスは `canceled` になります
  * 基盤の PSP checkout session は自動的に期限切れになり、PSP キャンセル API を別途呼び出す必要はありません
  * `completed` と `canceled` は終端状態で、再度キャンセルすることはできません
</Note>

## リクエストボディ

| フィールド     | 型      | 必須  | 説明                                    |
| --------- | ------ | --- | ------------------------------------- |
| `orderId` | string | Yes | ワンタイム注文 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.cancelOnetime({
    orderId: "ORD_2aUyqjCzEIiEcYMKj7TZtw",
  });

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

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

## 成功レスポンス (200)

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

### レスポンスフィールド

| フィールド     | 型      | 説明                            |
| --------- | ------ | ----------------------------- |
| `orderId` | string | 注文 ID（Short ID）               |
| `status`  | string | 新しい注文ステータス（成功時は常に `canceled`） |

## エラー

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

| ステータス | `errors[0].message`                           | 意味                                                   | 推奨処理                        |
| ----- | --------------------------------------------- | ---------------------------------------------------- | --------------------------- |
| 400   | `Missing required field: orderId`             | リクエストボディに `orderId` が含まれていない                         | リクエストボディを修正してから再送信          |
| 400   | `Expected format: ORD_xxx, got "..."`         | `orderId` Short ID のデコード失敗                           | `orderId` のフォーマットを修正してから再送信 |
| 400   | `Order cannot be canceled, current status: X` | 注文ステータスが `pending` ではない（`completed` や `canceled` など） | 注文はキャンセル不可                  |
| 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 回）  |
