Every SaaS project eventually needs the same thing, a way to charge people. Stripe handles the actual payment processing, but wiring it into Next.js correctly, especially getting webhooks right, is where most of the real work sits.

Here is the setup I use for checkout and subscriptions in every SaaS project.

1. The Stripe Client

// lib/stripe.ts

import Stripe from 'stripe';