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