- POST /api/checkout creates a live Dodo checkout session from an allowlisted product slug (weekly/monthly/pro/pro_annual/team), never a client-supplied product id. - POST /api/webhooks/dodo verifies the Standard Webhooks signature (webhook-id.webhook-timestamp.body, 5-min replay window) against a secret stored only as a Worker secret, records each delivery idempotently by webhook-id in D1, and upserts a per-customer entitlement row on subscription lifecycle events. - GET /api/entitlement is an internal-only lookup gated by a shared-secret header, for Recoder's app / Rithub to check a customer's billing state. - GET /api/portal resolves a checkout session's email, looks up the Dodo customer id from our own entitlements table, and redirects into Dodo's hosted customer portal -- no bespoke billing UI. - New /thanks page with a "Manage subscription" link; pricing cards now trigger checkout via one click (no form -- Dodo's hosted page collects email/card). - New D1 database recoder-billing (webhook_events + entitlements tables). This re-points recoder.xyz at a real backend: the live Dodo webhook (ep_3L0eElSCHnxNsth2aIBRdObJJzT) was 404ing against the old pure-static site. Verified live: bad signature -> 401, correctly-signed test event -> 200 + D1 row + idempotent replay, all 5 live checkout URLs return 200 on Dodo's hosted page, pricing/thanks screenshot clean at 1440 and 390 with no console errors. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
22 lines
537 B
SQL
22 lines
537 B
SQL
-- RCD-MON: billing storage for recoder.xyz (Dodo Payments webhooks + entitlements)
|
|
|
|
CREATE TABLE IF NOT EXISTS webhook_events (
|
|
id TEXT PRIMARY KEY,
|
|
event_type TEXT NOT NULL,
|
|
received_at TEXT NOT NULL,
|
|
payload TEXT NOT NULL
|
|
);
|
|
|
|
CREATE TABLE IF NOT EXISTS entitlements (
|
|
customer_id TEXT PRIMARY KEY,
|
|
email TEXT,
|
|
product_id TEXT,
|
|
product_name TEXT,
|
|
status TEXT NOT NULL,
|
|
subscription_id TEXT,
|
|
period_end TEXT,
|
|
updated_at TEXT NOT NULL
|
|
);
|
|
|
|
CREATE INDEX IF NOT EXISTS idx_entitlements_email ON entitlements(email);
|