Skip to content

Instantly share code, notes, and snippets.

@swsouth
swsouth / README.md
Created April 29, 2026 17:06
Raztrix Stripe reference — webhook + checkout + portal + entitlement (for steveshub billing-svc port)

Raztrix Stripe reference — for steveshub billing-svc port

Reference implementation from raztrix's production code (Next.js + Drizzle + Postgres). Anonymized: no secrets, no tenant data. Logger calls left in for shape — replace with your logger.

Files in this gist

  1. lib-stripe.tslazy SDK init. Use the Proxy pattern. Module-level new Stripe() breaks Next.js standalone builds and crash-loops on missing env vars at boot.
  2. webhook-route.ts — Stripe event handler. Signature verification, switch on event type, 5 handlers (checkout.session.completed, customer.subscription.{created,updated,deleted}, invoice.payment_{succeeded,failed}).
  3. create-checkout-session-route.ts — POST endpoint. Creates Stripe customer if absent, opens subscription Checkout with 14-day trial, promo codes enabled, success/cancel URLs.