Add payments and subscription billing to your application. Scaffolds Stripe checkout, customer portal, webhook handling, and subscription management.
Complete payments platform with subscriptions, invoicing, and checkout
STRIPE_SECRET_KEYSTRIPE_WEBHOOK_SECRETCreate a checkout session
Start a Stripe Checkout session for a subscription
import { stripe } from '@/lib/stripe'
const session = await stripe.checkout.sessions.create({
mode: 'subscription',
line_items: [{
price: priceId,
quantity: 1,
}],
success_url: `${baseUrl}/billing?success=true`,
cancel_url: `${baseUrl}/pricing`,
customer_email: user.email,
})Handle webhooks
Process Stripe webhook events
import { stripe } from '@/lib/stripe'
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 })
}Add stripe to your Primstack project with a single command:
prim stripe init