DocsCore FeaturesBilling & Subscriptions

Billing & Subscriptions

Shipfastai includes a complete Stripe integration for subscriptions and one-time payments.

Features

Stripe Checkout integration

Subscription management

Usage-based billing

Customer portal

Webhook handling

Setting Up Products

1. Create Products in Stripe

Stripe Dashboard > Products > Add Product

Name: Starter Plan

Price: $29/month (recurring)

Note the price_id: price_xxx

2. Update Frontend Config

// lib/stripe-config.ts

export const PLANS = [

{

name: 'Starter',

priceId: 'price_xxx',

price: 29,

features: ['5,000 API calls', 'Basic support'],

},

// ...

];

Checkout Flow

Create Checkout Session

// API route

import Stripe from 'stripe';

export async function POST(req: Request) {

const stripe = new Stripe(process.env.STRIPE_SECRET_KEY!);

const session = await stripe.checkout.sessions.create({

mode: 'subscription',

payment_method_types: ['card'],

line_items: [{ price: priceId, quantity: 1 }],

success_url: ${origin}/dashboard?success=true,

cancel_url: ${origin}/pricing,

});

return Response.json({ url: session.url });

}

Frontend Redirect

const handleCheckout = async (priceId: string) => {

const res = await fetch('/api/checkout', {

method: 'POST',

body: JSON.stringify({ priceId }),

});

const { url } = await res.json();

window.location.href = url;

};

Webhook Handling

Handle Stripe events:

// api/stripe/webhook/route.ts

export async function POST(req: Request) {

const body = await req.text();

const sig = req.headers.get('stripe-signature')!;

const event = stripe.webhooks.constructEvent(

body, sig, process.env.STRIPE_WEBHOOK_SECRET!

);

switch (event.type) {

case 'checkout.session.completed':

await handleCheckoutComplete(event.data.object);

break;

case 'customer.subscription.updated':

await handleSubscriptionUpdate(event.data.object);

break;

}

return Response.json({ received: true });

}

Customer Portal

Let users manage their subscriptions:

const portalSession = await stripe.billingPortal.sessions.create({

customer: customerId,

return_url: ${origin}/dashboard/settings,

});