Skip to content

setup-stripe

Access: /template setup-stripe or /t setup-stripe

Configure Stripe billing and subscription management for your MakerKit SaaS.

License Required

MakerKit is a commercial product that requires a license. Visit https://makerkit.dev for licensing information.

Overview

The setup-stripe command integrates Stripe for subscription billing, including webhooks, customer portal, and pricing plans. It follows MakerKit's billing architecture patterns.

Usage

bash
/template setup-stripe "Pricing plan descriptions"

Examples

bash
# Basic SaaS tiers
/template setup-stripe "Basic ($9/mo), Pro ($29/mo), Enterprise (custom)"

# Usage-based pricing
/template setup-stripe "Starter (free), Growth ($49/mo + $0.01 per API call)"

# Feature-based tiers
/template setup-stripe "Solo (1 user), Team (5 users), Business (unlimited)"

What Gets Configured

  1. Environment Variables - Stripe API keys
  2. Webhook Endpoints - /api/stripe/webhook
  3. Customer Portal - Settings and redirect
  4. Pricing Plans - Products and prices in Stripe
  5. Database Schema - Subscription tracking tables
  6. UI Components - Pricing page and billing settings
  7. Server Actions - Checkout and portal actions

Prerequisites

  • MakerKit project with authentication
  • Stripe account with API keys
  • Valid MakerKit license

Configuration Steps

  1. Add Stripe keys to .env.local:

    bash
    STRIPE_SECRET_KEY=sk_test_...
    STRIPE_PUBLISHABLE_KEY=pk_test_...
    STRIPE_WEBHOOK_SECRET=whsec_...
  2. Run the command to set up billing

  3. Configure products in Stripe Dashboard

  4. Test webhook endpoints

Example Implementation

typescript
// src/lib/stripe/plans.ts
export const PRICING_PLANS = [
  {
    id: 'basic',
    name: 'Basic',
    price: 9,
    currency: 'USD',
    interval: 'month',
    features: [
      '5 projects',
      '1 team member',
      'Basic support'
    ],
    stripePriceId: process.env.STRIPE_BASIC_PRICE_ID
  },
  // ... more plans
];

Webhook Handling

typescript
// app/api/stripe/webhook/route.ts
export async function POST(request: Request) {
  const signature = request.headers.get('stripe-signature')!;
  const event = stripe.webhooks.constructEvent(
    await request.text(),
    signature,
    process.env.STRIPE_WEBHOOK_SECRET!
  );
  
  switch (event.type) {
    case 'checkout.session.completed':
      // Handle successful subscription
      break;
    case 'customer.subscription.updated':
      // Handle plan changes
      break;
  }
}

Best Practices

  • Use test mode during development
  • Implement proper error handling
  • Log all billing events
  • Set up email notifications
  • Handle edge cases (failed payments, cancellations)

Testing

bash
# Test webhook locally
stripe listen --forward-to localhost:3000/api/stripe/webhook

# Trigger test events
stripe trigger payment_intent.succeeded

See Also

Built with ❤️ for the AI Coding community, by Praney Behl