Webhook có được retry không?
Có. Endpoint phải idempotent và trả 2xx cho event đã xử lý.
Webhooks
Nhận sự kiện subscription, xác thực chữ ký số, deduplicate theo event_id và cập nhật entitlement an toàn. Loại bỏ hoàn toàn phụ thuộc vào browser redirect.
Bắt đầu miễn phíKết quả
Kiểm tra chữ ký bằng signing secret đã lưu một lần.
Lưu event_id trước khi thay đổi entitlement.
Xử lý created, updated và canceled theo subscription_id.
API key là secret của server. Không đặt key trong browser hoặc mobile app.
if (!verifySignature(rawBody, signature, signingSecret)) {
return new Response("invalid signature", { status: 401 })
}
if (await events.exists(payload.event_id)) return new Response("ok")
await subscriptions.apply(payload)
return new Response("ok")Có. Endpoint phải idempotent và trả 2xx cho event đã xử lý.
Không dùng browser redirect làm bằng chứng thanh toán; hãy xác thực webhook hoặc đối soát bằng API.