POST /v1/actions/coupon/deactivate-coupon
停用是不可恢复的。已停用的优惠券无法重新启用,优惠券也不能删除。如需再次提供这项优惠,请新建优惠券。
请求体
| 字段 | 类型 | 必需 | 说明 |
|---|---|---|---|
id | string | 是 | 优惠券 ID(Short ID 格式 CPN_xxx) |
请求示例
const { coupon } = await client.coupons.deactivate({ id: "CPN_5dXBtmF2HLlHfbPNm0Wcnz" });
console.log(coupon.status); // => "inactive"
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"
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)
{
"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"
}
}
}
响应字段
与创建优惠券的响应相同,但不含promotionCodes。
已有订单不受影响。已挂在订阅上的优惠会继续生效,直到该订阅下一次更换方案。对已停用的优惠券再次调用会返回
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 次) |