Documentation Index
Fetch the complete documentation index at: https://waffo.com/docs/llms.txt
Use this file to discover all available pages before exploring further.
幂等性确保当同一个请求被执行多次时,其结果与仅执行一次相同。在支付场景中,这可以防止因网络超时触发重试而导致的重复扣款。
幂等键
Waffo 使用 paymentRequestId(支付)和 subscriptionRequest(订阅)作为幂等键。
- 最大长度:32 个字符
- 每个新请求必须生成唯一值
- 必须在发送请求之前持久化到数据库
- 重试时,复用原始幂等键;不要生成新的
// 1. 生成不超过 32 字符的唯一幂等键
const paymentRequestId = generateUniqueRequestId();
// 2. Persist (before sending the request!)
await db.order.create({ paymentRequestId, status: 'PENDING' });
// 3. Send the request
try {
const response = await waffo.order().create({ paymentRequestId, ... });
} catch (e) {
if (e instanceof WaffoUnknownStatusException) {
// 4. Unknown status: inquire, do not retry create
const inquiry = await waffo.order().inquiry({ paymentRequestId });
}
}
常见错误