跳转到主要内容
为门店新增 Webhook 端点。每个门店在所有通道下最多可配置 20 个 Webhook
POST /v1/actions/store/add-webhook
认证方式: API Key(需要 owner 或 admin 角色)

请求体

字段类型必需说明
storeIdstringStore ID(Short ID 格式 STO_xxx
channelstring取值为 httpfeishudiscordtelegramslack 之一
urlstring目标 Webhook URL(HTTPS;商户需确保 URL 与所选通道匹配)
eventsstring[]订阅的事件类型 —— 例如 ["order.completed", "refund.succeeded"]。空数组表示不向该 Webhook 触发任何事件。
testModebooleantrue = 仅对测试交易触发;false = 仅对生产交易触发
secretstring | null通道特定凭据(如 Telegram 的 chat_id)。以不透明字符串形式存储。

请求示例

import { WaffoPancake } from "@waffo/pancake-ts";

const client = new WaffoPancake({
  merchantId: process.env.WAFFO_MERCHANT_ID!,
  privateKey: process.env.WAFFO_PRIVATE_KEY!,
});

// 标准 HTTPS Webhook(RSA 签名信封)
const { webhook } = await client.webhooks.add({
  storeId: "STO_2aUyqjCzEIiEcYMKj7TZtw",
  channel: "http",
  url: "https://example.com/webhooks/pancake",
  events: ["order.completed", "refund.succeeded"],
  testMode: false,
});

成功响应 (200)

{
  "data": {
    "webhook": {
      "id": "11111111-2222-3333-4444-555555555555",
      "storeId": "uuid-of-store",
      "channel": "http",
      "url": "https://example.com/webhooks/pancake",
      "events": ["order.completed", "refund.succeeded"],
      "testMode": false,
      "secret": null,
      "createdAt": "2026-05-07T00:00:00.000Z",
      "updatedAt": "2026-05-07T00:00:00.000Z"
    }
  }
}
返回的 webhook.id 是 UUID,而非 Short ID —— Webhook ID 不属于 IdPrefix 范围。请将其原样传入 update-webhookremove-webhook

响应字段

字段类型说明
idstringWebhook UUID
storeIdstring所属门店的 UUID
channelstringWebhook 通道(httpfeishudiscordtelegramslack
urlstring目标 Webhook URL
eventsstring[]订阅的事件类型
testModebooleantrue 对测试交易触发,false 对生产交易触发
secretstring | null通道特定凭据(不透明字符串),未设置时为 null
createdAtstring创建时间戳(ISO 8601)
updatedAtstring最后更新时间戳(ISO 8601)

错误响应

重试策略:4xx 一律不要重试 — 修正请求后重发。5xx 指数退避重试(起步 5s,最多 3 次)。
状态码errors[0].message含义推荐处理
400Missing required field: storeId未提供 storeId修正请求体后重发
400Expected format: STO_xxx, got "..."storeId Short ID 解码失败修正 storeId 格式后重发
400testMode must be a booleantestMode 不是布尔值传布尔值后重发
400Invalid channel: must be one of http, feishu, discord, telegram, slackchannel 不在允许列表使用允许的 channel
400Invalid URL formaturl 不是合法 URL修正 URL 后重发
400events must be a string arrayevents 不是字符串数组传字符串数组后重发
400secret must be a string or nullsecret 不是 string 或 null传 string 或 null 后重发
400Webhook limit reached (max 20 per store)门店已达 20 个 Webhook 上限先删除已有 Webhook
401Missing merchantId in request contextAPI Key 认证未解析出 merchant检查 API Key 请求头与签名
403Not authorized to manage webhooks for this store商户不是该门店的 owneradmin验证商户在该门店的角色
500Internal server error服务端意外失败指数退避重试(起步 5s,最多 3 次)