pending 状态的订单可以取消。
POST /v1/actions/onetime-order/cancel-order
取消行为
| 当前状态 | 操作 | 结果状态 |
|---|---|---|
pending | 立即取消 | canceled |
completed | 拒绝 | 不变(终态) |
canceled | 拒绝 | 不变(终态) |
- pending:订单立即取消,状态变为
canceled - 底层 PSP checkout session 会自动过期,无需单独调用 PSP 取消接口
completed与canceled是终态,不能再次取消
请求体
| 字段 | 类型 | 必需 | 说明 |
|---|---|---|---|
orderId | string | 是 | 一次性订单 ID(Short ID 格式 ORD_xxx) |
请求示例
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"
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());
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"}'
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"
成功响应 (200)
{
"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 次) |