Sistine Docs

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 Pancake

Both 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

ProviderSchemeHeader
DodoStandard Webhooks (HMAC-SHA256 over id.timestamp.body)webhook-signature
WaffoRSA-SHA256 over t.bodyx-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 the webhook_event unique 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:

  1. webhook_event with 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.
  2. payment with 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

SituationResponseWhy
Bad signature401Retrying a bad signature just burns the retry schedule
Duplicate delivery200 {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 subscription409Re-reading and replaying once usually succeeds
Database wobble5xxThe 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

ProviderEventAction
Dodosubscription.active / renewed / updatedMove the subscription row, sync user.planKey
Dodosubscription.cancelled / expiredTerminate access, revoke un-granted installments
Dodosubscription.on_holdMaps to paused — no access, and it frees the single-active slot so the user can buy again
Dodopayment.succeededWrite payment, grant credits, schedule installments
Dodorefund.succeededReverse the credits that payment granted
Waffosubscription.activated / renewedMove the subscription row, sync user.planKey
Waffosubscription.cancelingStays active (access continues this period) and sets cancel_at_period_end
Waffosubscription.canceledTerminate access, revoke un-granted installments
Waffosubscription.payment_succeededWrite payment, grant credits — never touches the subscription row (this event carries no orderStatus)
Waffoorder.completedOne-time pack: grant credits, never create a subscription
bothrefund.*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.com

Or 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/webhook

Then 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   # Dodo

Debugging

If events are not arriving or not being applied:

  1. pnpm verify:signature https://your-domain.com — is the deployed secret the same one the provider signs with?
  2. pnpm webhooks:register --list — is the endpoint pointing at the current domain?
  3. Query webhook_event — every delivery is recorded with status (received / processed / ignored / failed) and last_error:
    select received_at, provider, event_type, status, attempts, last_error
    from webhook_event order by received_at desc limit 20;
  4. status = 'ignored' with last_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
  5. 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.
  6. 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.

On this page