Payments Module

What payments-basic installs

$ asa install payments-basic

Real billing UI, real webhook architecture, real entitlement checks. Production billing — not a Stripe tutorial.

This is real output from our architecture service — not a downloadable template.

Billing Page

domains/billing/subscribe/ui/BillingSubscribe.tsx

Current Plan

Free

Active

Available Plans

Pro

$29/mo

  • Unlimited projects
  • Priority support
  • Advanced analytics

Business

$99/mo

  • Everything in Pro
  • Team management
  • Custom integrations

How it works: Clicking "Upgrade" creates a Stripe Checkout session server-side and redirects. No Stripe SDK in the browser.

Webhook Processing — Inbox Pattern

The #1 billing failure in AI-built apps: inline webhook processing

Typical AI Output

Webhook route:

  • 1. Verify signature
  • 2. switch(event.type)
  • 3. Process inline
  • 4. Update DB
  • 5. Return 200

Stripe times out at 10s. Events get lost.

ASA Inbox Pattern

1. Webhook Route

  • Verify Stripe signature
  • INSERT into webhook_events
  • Status: pending
  • Return 200 immediately

2. Async Processor

  • Pick pending events
  • Lock with SELECT FOR UPDATE
  • Process idempotently
  • Update status: processed/failed
  • Retry on failure

Entitlement Checks

shared/billing/entitlements.ts — separated from raw Stripe status

// In any handler — check if user can access a feature:
const entitled = await checkEntitlement(userId, 'projects.create');

if (!entitled.allowed) {
  return NextResponse.json(
    { error: 'Upgrade to Pro to create more projects' },
    { status: 403 }
  );
}

// Dunning-safe: user keeps access during grace period
// even if payment failed. Configurable per plan.

Why not check plan directly? Lint rule ENT-001 blocks plan === 'pro'. Entitlements are decoupled from Stripe status — supports grace periods, trials, and plan changes.

Automatic Reconciliation

shared/billing/reconciliation.ts — Stripe can drift from your DB

// Scheduled job (Supabase Cron / Vercel Cron):
// 1. Fetch active subscriptions from DB
// 2. Fetch current state from Stripe API
// 3. Compare and detect drift
// 4. Auto-repair: update local DB to match Stripe
// 5. Log drift events for monitoring

// Catches: missed webhooks, manual Stripe changes,
// status transitions that happened while server was down.

Production billing. Not a Stripe tutorial.

Install payments-basic and get webhook inbox, entitlements, and reconciliation.