Back to Handbook

Implementation · Intermediate

Adding a Paywall

Stripe & LemonSqueezy

The definitive guide to monetizing your vibe-coded app. Learn the 'Gated Route' pattern and how to use a Merchant of Record to handle taxes.

01

Merchant of Record (MoR) vs Processor

Don't build your own billing system. Use an MoR like LemonSqueezy or Paddle. They handle global sales tax, invoices, and compliance so you can just code.

  • Stripe: Powerful but requires you to handle Tax compliance manually in many cases.
  • LemonSqueezy: 'Vibe Coder friendly'. Acts as the reseller. Easy React components.
  • RevenueCat: Essential if you are building mobile apps.

02

The 'Gated Route' Pattern

The core architecture is simple: The user pays -> Webhook updates Database -> API Route checks Database before generating.

Prompt
// /api/generate/route.ts
export async function POST(req) {
  const user = await currentUser();
  // 1. Check Subscription in DB
  const subscription = await db.query('subscriptions')
    .where({ userId: user.id, status: 'active' })
    .first();

  if (!subscription) {
    return new Response("Upgrade to Pro", { status: 403 });
  }

  // 2. Only now do we call the expensive AI model
  const result = await ai.generate(...)
  return Response.json(result);
}

03

Pricing Strategies for AI

AI costs money per token. Your pricing must align with your costs.

ModelDescriptionProsCons
Flat Rate$20/mo for unlimitedPredictable RevenueHeavy users burn margins
Credit Based$10 for 500 gensProtects MarginsHigher friction for users
Hybrid50 free, then payBest ConversionComplex implementation

04

The Webhook Handler

The 'Secret Sauce' is the webhook. When Stripe/LemonSqueezy says 'Payment Succeeded', your database must instantly unlock the features.

  • Idempotency: Ensure the webhook processes the same event only once.
  • Security: Verify the webhook signature to prevent fake requests.
  • Sync: Update the 'subscription_status' column in your Users table immediately.