> ## 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/coupon/deactivate-coupon
```

**認証：** API Key

> [!WARNING]
>
> 無効化は**取り消せません**。無効化したクーポンを再度有効にすることはできず、クーポンを削除することもできません。同じ割引を再び提供するには、新しいクーポンを作成してください。

## リクエストボディ

| フィールド | 型 | 必須 | 説明 |
| - | - | - | - |
| `id` | string | はい | クーポン ID（Short ID 形式 `CPN_xxx`） |

## リクエスト例

```typescript SDK theme={"system"}
const { coupon } = await client.coupons.deactivate({ id: "CPN_5dXBtmF2HLlHfbPNm0Wcnz" });
console.log(coupon.status); // => "inactive"
```

```bash cURL theme={"system"}
MERCHANT_ID="MER_2aUyqjCzEIiEcYMKj7TZtw"
TIMESTAMP=$(date +%s)
BODY='{"id":"CPN_5dXBtmF2HLlHfbPNm0Wcnz"}'
BODY_HASH=$(echo -n "$BODY" | openssl dgst -sha256 -binary | base64 | tr -d '\n')
CANONICAL_REQUEST="POST
/v1/actions/coupon/deactivate-coupon
$TIMESTAMP
$BODY_HASH"

SIGNATURE=$(echo -n "$CANONICAL_REQUEST" | openssl dgst -sha256 -sign private_key.pem | base64 | tr -d '\n')

curl -X POST "https://api.waffo.ai/v1/actions/coupon/deactivate-coupon" \
  -H "Content-Type: application/json" \
  -H "X-Merchant-Id: $MERCHANT_ID" \
  -H "X-Timestamp: $TIMESTAMP" \
  -H "X-Signature: $SIGNATURE" \
  -d "$BODY"
```

```python Python theme={"system"}
import hashlib, time, base64, json, requests
from cryptography.hazmat.primitives import hashes, serialization
from cryptography.hazmat.primitives.asymmetric import padding

merchant_id = "MER_2aUyqjCzEIiEcYMKj7TZtw"
timestamp = str(int(time.time()))
body = {"id": "CPN_5dXBtmF2HLlHfbPNm0Wcnz"}

body_json = json.dumps(body, separators=(",", ":"))
body_hash = base64.b64encode(hashlib.sha256(body_json.encode()).digest()).decode()
path = "/v1/actions/coupon/deactivate-coupon"
canonical = f"POST\n{path}\n{timestamp}\n{body_hash}"

with open("private_key.pem", "rb") as f:
    private_key = serialization.load_pem_private_key(f.read(), password=None)

signature = base64.b64encode(
    private_key.sign(canonical.encode(), padding.PKCS1v15(), hashes.SHA256())
).decode()

resp = requests.post(
    f"https://api.waffo.ai{path}",
    headers={
        "Content-Type": "application/json",
        "X-Merchant-Id": merchant_id,
        "X-Timestamp": timestamp,
        "X-Signature": signature,
    },
    data=body_json,
)
print(resp.json())
```

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

```json theme={"system"}
{
  "data": {
    "coupon": {
      "id": "CPN_5dXBtmF2HLlHfbPNm0Wcnz",
      "storeId": "STO_2aUyqjCzEIiEcYMKj7TZtw",
      "name": "Black Friday 20% off",
      "code": "BF2026",
      "status": "inactive",
      "discountType": "percentage",
      "percentOff": 20,
      "amountOff": null,
      "duration": "repeating",
      "durationInPeriods": 3,
      "productIds": [],
      "maxRedemptions": 1000,
      "redeemBy": "2026-12-01T00:00:00.000Z",
      "createdAt": "2026-11-01T08:00:00.000Z",
      "updatedAt": "2026-12-02T10:00:00.000Z"
    }
  }
}
```

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

[クーポンの作成のレスポンス](https://docs.waffo.ai/ja/api-reference/endpoints/coupons/create-coupon.md)と同じです（`promotionCodes` を除く）。

> [!NOTE]
>
> 既存の注文には影響しません。サブスクリプションに適用済みの割引は、そのサブスクリプションの次回のプラン変更まで引き続き適用されます。すでに無効化されたクーポンに対して呼び出すと、クーポンは変更されずに `200` が返ります。

## エラー

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

| ステータス | `errors[0].message` | 意味 | 推奨処理 |
| - | - | - | - |
| 400 | `Missing or invalid header: x-context-environment` | 環境 header が欠落、または `test` / `prod` ではない | `X-Environment` を `test` または `prod` に設定 |
| 400 | `Invalid JSON body` | ボディが正しい JSON ではない | ボディを修正して再送信 |
| 400 | `Missing required field: id` | `id` が指定されていない | `id` を追加して再送信 |
| 400 | `Expected format: CPN_xxx, got "X"` | `id` が正しい Short ID ではない | `CPN_` 接頭辞付きの Short ID を使用 |
| 401 | `Authentication required` | 認証失敗 | API Key、タイムスタンプ、署名を確認 |
| 404 | `Coupon not found` | クーポンが存在しない、他のマーチャントに属する、または別の環境にある | `id` と API Key の環境を確認 |
| 409 | `Coupon is not active (status: pending)` | クーポンが `pending`：クーポン作成のリクエストがまだ処理中、または中断されてまだクリーンアップされていない | クーポン作成のリクエストが終わってからリトライ。中断されたクーポンはクリーンアップ後に `failed` になり、無効化は不要になる |
| 409 | `Coupon creation failed; there is nothing to deactivate` | クーポンは `failed` で、一度も有効になっておらず、コードも解放済み | 対応不要 |
| 500 | `Internal server error` | サーバ側の予期しない障害 | 指数バックオフでリトライ（5s 開始、最大 3 回） |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.