用途:接收并验证 Square Webhook,用于处理支付、退款、发票、订单、客户等电商事件,以及调试签名校验失败问题。
主要能力:Square 对每个 Webhook 使用 HMAC-SHA256 签名,签名内容为通知 URL 拼接原始请求体(notificationUrl + rawBody,顺序已通过测试确认),base64 编码后放在 x-square-hmacsha256-signature 头中。通知 URL 属于签名内容,必须与订阅中配置的 URL 逐字节一致。务必校验原始请求体,不要先 JSON.parse。
使用方式:HMAC 密钥使用订阅的 Signature Key(较短,如 qfjakbt2uWB8DKAMECF-EA),而非 OAuth access token(EAAA…)。Node 可参考官方 SDK: const { WebhooksHelper } = require('square'); const isValid = await WebhooksHelper.verifySignature({ requestBody: rawBody, signatureHeader: req.headers['x-square-hmacsha256-signature'], signatureKey: process.env.SQUARE_WEBHOOK_SIGNATURE_KEY, notificationUrl: process.env.SQUARE_WEBHOOK_URL, }); if (!isValid) return res.status(400).send('Invalid signature'); Python 可手动实现 timing-safe 校验,对 url.encode() + raw_body 做 HMAC-SHA256 后 base64 比较。环境变量:SQUARE_WEBHOOK_SIGNATURE_KEY、SQUARE_WEBHOOK_URL。本地开发可用 npx hookdeck-cli listen 3000 square --path /webhooks/square,并把 SQUARE_WEBHOOK_URL 设为隧道公网 URL。
适用场景:设置 Square 支付、退款、发票、订单等相关 Webhook 处理器;调试签名校验失败;处理 payment.updated、refund.created 等事件。事件类型在请求体的 type 字段中,不在请求头。
限制:Flat 文档仅说明 SHA-256 头,2026-08 的沙箱投递还带有未记录的 x-square-signature(HMAC-SHA1)头,不应依赖。基于该技能的完整处理器、路由接线、事件分发与测试示例见 examples/express/、examples/nextjs/、examples/fastapi/;参考材料见 references/overview.md、setup.md、verification.md。建议搭配 webhook-handler-patterns 技能处理幂等、错误与重试。此技能的收费、价格与官方支持情况暂未提供。