Subscriptions

Subscription Plans

Available Plans

The starter kit includes predefined subscription plans in lib/payment/plans.ts. You can customize these plans or add new ones:

export const plans = {
  free: {
    name: "Free",
    description: "Basic features",
    price: "$0",
    features: ["Limited AI interactions", "Basic support"]
  },
  pro: {
    name: "Pro",
    description: "Advanced features",
    price: "$10/month",
    features: ["Unlimited AI interactions", "Priority support"]
  }
};

Payment Flow

Checkout Process

  1. User selects a plan or credit bundle
  2. System creates a Stripe checkout session
  3. User completes payment on Stripe's hosted page
  4. Webhook receives payment confirmation
  5. System updates user's credits or subscription status

Example: Processing a Payment

// Client-side: Initiating checkout
async function handleCheckout() {
  const response = await fetch('/api/stripe/checkout/subscription', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({ priceId: plans[0].yearly.priceId })
  });
  const { url } = await response.json();
  window.location.href = url;
}