Sistine Docs

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:

ProviderCheckoutWebhook
Dodo/api/payments/checkout (provider chosen server-side)/api/payments/dodo/webhook
Waffosame 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:

PlanPriceCredits
Starter Monthly$29/mo1,000/month
Starter Yearly$290/yr12,000/year (1,000/month installments)
Pro Monthly$99/mo10,000/month
Pro Yearly$990/yr120,000/year (10,000/month installments)

One-Time Credit Packs

PackPriceCredits
200 Credits$5200

Payment Flow

  1. User clicks buy → frontend calls /api/payments/checkout with { key }
  2. Server resolves plan → product ID from constants/billing.ts (never from the request)
  3. Provider returns a hosted checkout URL → browser is redirected to it
  4. User pays → provider sends a signed webhook
  5. Webhook handler (same pipeline for both providers):
    • verify signature → 401 if it fails (retrying a bad signature is pointless)
    • normalize the provider payload into an internal event shape
    • claim the event by inserting into webhook_event first (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

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

On this page