Payments Overview
Subscription billing and one-time purchases with Dodo Payments or Waffo.
Overview
Sistine Starter supports two payment providers — Dodo Payments and Waffo Pancake — through one provider-agnostic business layer. Both are Merchants of Record, so they handle sales tax and act as the seller of record.
You pick one with PAYMENTS_PROVIDER:
PAYMENTS_PROVIDER="dodo" # or "waffo"Both webhook routes stay live either way, because events for existing subscriptions must keep landing even after you switch providers:
| Provider | Checkout | Webhook |
|---|---|---|
| Dodo | /api/payments/checkout (provider chosen server-side) | /api/payments/dodo/webhook |
| Waffo | same endpoint | /api/payments/waffo/webhook |
The frontend only ever calls /api/payments/checkout with { key }. It never sends a
product ID or a price — both come from server config, otherwise anyone could turn a
$99 plan into a $0.01 order.
Subscription Plans
Configured in constants/billing.ts:
| Plan | Price | Credits |
|---|---|---|
| Starter Monthly | $29/mo | 1,000/month |
| Starter Yearly | $290/yr | 12,000/year (1,000/month installments) |
| Pro Monthly | $99/mo | 10,000/month |
| Pro Yearly | $990/yr | 120,000/year (10,000/month installments) |
One-Time Credit Packs
| Pack | Price | Credits |
|---|---|---|
| 200 Credits | $5 | 200 |
Payment Flow
- User clicks buy → frontend calls
/api/payments/checkoutwith{ key } - Server resolves plan → product ID from
constants/billing.ts(never from the request) - Provider returns a hosted checkout URL → browser is redirected to it
- User pays → provider sends a signed webhook
- Webhook handler (same pipeline for both providers):
- verify signature →
401if it fails (retrying a bad signature is pointless) - normalize the provider payload into an internal event shape
- claim the event by inserting into
webhook_eventfirst (idempotency, not "check then process" — two concurrent retries would both pass a check) - apply to
subscription/payment/credit_ledger - grant credits, then send the purchase email after the transaction commits
- verify signature →
Credits Are Granted by Payment Events, Not Status Events
Both providers send two events for the first payment (a subscription status event
and a payment event). Crediting on the status event would hand out the first
month twice, so only payment events grant credits. Status events only move the
subscription row and user.planKey.
Annual Subscription Installments
Annual plans don't grant all credits at once:
- Year plan purchased → first month's credits granted immediately
- Remaining 11 months → scheduled in
subscriptionCreditSchedule - Cron (
/api/cron/subscription-grants) grants each due installment - Cancelling or expiring revokes the un-granted schedule but never claws back credits already granted — those are already in the user's balance
The cron also treats subscription.status as authoritative: a schedule that is still
in the table but whose subscription is no longer access-granting will not be paid out.
Refunds
A refund looks up how many credits that specific payment actually granted (from
credit_ledger), not what the plan config says today — configs change, ledgers don't.
Partial refunds are prorated and rounded up. If the user already spent the credits,
the balance stops at zero and the shortfall is recorded on the payment row for manual
review rather than being silently written off.
Testing
Both providers have test modes; no real money moves.
DODO_PAYMENTS_ENVIRONMENT="test_mode" # Dodo test card: 4242 4242 4242 4242
WAFFO_ENVIRONMENT="test"Useful commands:
pnpm verify:payments:dodo # real route + real signature + real DB
pnpm verify:payments:waffo
pnpm verify:payments:grants # credit grants, installments, refunds
pnpm payments:replay # re-deliver any payment event stored as ignored