Webhooks
How Dodo Payments and Waffo webhooks are verified and processed.
Endpoints
POST /api/payments/dodo/webhook # Dodo Payments
POST /api/payments/waffo/webhook # Waffo PancakeBoth are always live. Switching PAYMENTS_PROVIDER does not disable the other
route — subscriptions sold under the old provider still need their renewal, cancel and
refund events processed.
Security
Signature verification
| Provider | Scheme | Header |
|---|---|---|
| Dodo | Standard Webhooks (HMAC-SHA256 over id.timestamp.body) | webhook-signature |
| Waffo | RSA-SHA256 over t.body | x-waffo-signature |
Two decisions worth knowing:
- Dodo's signature is verified by hand, not via the SDK helper. The SDK delegates to
standardwebhooks, which hardcodes a 5-minute tolerance, while Dodo retries for roughly 18 hours reusing the original timestamp. A 5-minute window turns every later retry into a 401, which looks like "our endpoint is broken" while the events are actually lost. Our tolerance is 24 hours; replay protection comes from thewebhook_eventunique index, not from the time window. - Waffo's timestamp is in milliseconds and the tolerance is 45 minutes — that is the provider's own retry schedule, and retries reuse the stamp once set. Shrinking it below the schedule loses events.
Waffo's public key is platform-wide — the same key verifies events for every store
on the platform. So after verifying the signature we also check storeId matches
WAFFO_STORE_ID and mode matches WAFFO_ENVIRONMENT; a mismatch returns 403
(the signature is genuine, so retrying will never help).
Idempotency
Two layers, on purpose:
webhook_eventwith a unique index on(provider, event_type, event_id)— the event is inserted before it is processed. The reverse order lets two concurrent retries both pass a "have I seen this?" check and grant credits twice.paymentwith a unique index on(provider, provider_payment_id)— one payment can arrive as several events with different event IDs, which layer 1 cannot catch.
Response codes
| Situation | Response | Why |
|---|---|---|
| Bad signature | 401 | Retrying a bad signature just burns the retry schedule |
| Duplicate delivery | 200 {duplicate:true} | Already handled |
| Not retryable (unknown user, already-active subscription, unmatched plan) | 200 {flagged:…} | Retrying will never succeed; the row stays in webhook_event for review |
| Concurrent write to the same subscription | 409 | Re-reading and replaying once usually succeeds |
| Database wobble | 5xx | The only case where a provider retry can help |
Returning 200 for "not retryable" rather than 5xx matters: a 5xx makes the
provider retry for hours, which blocks the queue behind it, for an event that can never
succeed.
Events we act on
| Provider | Event | Action |
|---|---|---|
| Dodo | subscription.active / renewed / updated | Move the subscription row, sync user.planKey |
| Dodo | subscription.cancelled / expired | Terminate access, revoke un-granted installments |
| Dodo | subscription.on_hold | Maps to paused — no access, and it frees the single-active slot so the user can buy again |
| Dodo | payment.succeeded | Write payment, grant credits, schedule installments |
| Dodo | refund.succeeded | Reverse the credits that payment granted |
| Waffo | subscription.activated / renewed | Move the subscription row, sync user.planKey |
| Waffo | subscription.canceling | Stays active (access continues this period) and sets cancel_at_period_end |
| Waffo | subscription.canceled | Terminate access, revoke un-granted installments |
| Waffo | subscription.payment_succeeded | Write payment, grant credits — never touches the subscription row (this event carries no orderStatus) |
| Waffo | order.completed | One-time pack: grant credits, never create a subscription |
| both | refund.* | Reverse credits by looking up credit_ledger for that payment |
Setup
pnpm webhooks:register --list # what's registered
pnpm webhooks:register --url https://your-domain.comOr set the URL by hand in the provider dashboard:
Dodo : https://your-domain.com/api/payments/dodo/webhook
Waffo: https://your-domain.com/api/payments/waffo/webhookThen check that the secret/key the provider has actually matches what is deployed — a mismatch surfaces only as "the provider says your endpoint keeps returning 401":
pnpm verify:signature https://your-domain.com # DodoDebugging
If events are not arriving or not being applied:
pnpm verify:signature https://your-domain.com— is the deployed secret the same one the provider signs with?pnpm webhooks:register --list— is the endpoint pointing at the current domain?- Query
webhook_event— every delivery is recorded withstatus(received/processed/ignored/failed) andlast_error:select received_at, provider, event_type, status, attempts, last_error from webhook_event order by received_at desc limit 20; status = 'ignored'withlast_error = 'payment-applier-not-implemented'means the order was received before the applier existed. Replay it with:pnpm payments:replay --dry-run pnpm payments:replay- Webhooks must not sit behind an auth wall. On Vercel, Deployment Protection intercepts every request and returns a login page — which looks like "all 401 from the provider". Turn it off for the production domain.
- If you front the app with a CDN proxy (Cloudflare orange cloud), the request body can be modified in transit and the signature will never verify. Use DNS-only.