Build a complete subscription SaaS platform with Next.js App Router, Tailwind, PostgreSQL, and Stripe checkout.
Build an end-to-end commercial software product: user onboarding, subscription billing tiers, customer dashboard, API key generation, and webhook processing.
Process checkout.session.completed and customer.subscription.updated events securely.
123456789101112131415161718192021222324import { headers } from "next/headers";import Stripe from "stripe";import { prisma } from "@/lib/prisma";const stripe = new Stripe(process.env.STRIPE_SECRET_KEY!, { apiVersion: "2023-10-16" });export async function POST(req: Request) {const body = await req.text();const signature = headers().get("Stripe-Signature") as string;let event: Stripe.Event;try {event = stripe.webhooks.constructEvent(body, signature, process.env.STRIPE_WEBHOOK_SECRET!);} catch (err: any) {return new Response(`Webhook Error: ${err.message}`, { status: 400 });}if (event.type === "checkout.session.completed") {const session = event.data.object as Stripe.Checkout.Session;// Upgrade user subscription tier in database}return new Response("OK", { status: 200 });}