Production-ready SvelteKit template with Stripe Checkout, webhooks, customer portal, and subscription management.
# Clone
git clone https://github.com/kszongic/sveltekit-stripe-starter.git
cd sveltekit-stripe-starter
# Install
npm install
# Configure
cp .env.example .env
# Add your Stripe keys to .env
# Run
npm run dev
your-domain.com/api/webhooks/stripeConfigure these webhook events in Stripe Dashboard:
checkout.session.completedcustomer.subscription.createdcustomer.subscription.updatedcustomer.subscription.deletedinvoice.payment_succeededinvoice.payment_failedPUBLIC_STRIPE_PUBLISHABLE_KEY=pk_test_...
STRIPE_SECRET_KEY=sk_test_...
STRIPE_WEBHOOK_SECRET=whsec_...
STRIPE_PRICE_ID_MONTHLY=price_...
STRIPE_PRICE_ID_YEARLY=price_...
PUBLIC_BASE_URL=http://localhost:5173
src/
āāā lib/
ā āāā server/
ā ā āāā stripe.ts # Stripe client instance
ā ā āāā webhooks.ts # Webhook event handlers
ā āāā config.ts # Environment config
ā āāā types.ts # Shared types
āāā routes/
ā āāā +page.svelte # Landing/pricing page
ā āāā +layout.svelte # App layout
ā āāā api/
ā ā āāā checkout/+server.ts # Create checkout session
ā ā āāā portal/+server.ts # Customer portal session
ā ā āāā webhooks/stripe/+server.ts # Webhook handler
ā āāā success/+page.svelte # Post-checkout success
ā āāā cancel/+page.svelte # Checkout cancelled
āāā app.html
āāā app.d.ts
POST /api/checkoutCreates a Stripe Checkout session. Body: { priceId, mode?, customerEmail? }
POST /api/portalCreates a Stripe Customer Portal session. Body: { customerId }
POST /api/webhooks/stripeHandles incoming Stripe webhook events with signature verification.
Update your price IDs in .env and modify the pricing page in src/routes/+page.svelte.
Add your preferred DB (Prisma, Drizzle, etc.) and store customer/subscription data in the webhook handlers at src/lib/server/webhooks.ts.
Pair with any auth solution (Lucia, Auth.js, Clerk) ā the checkout and portal routes accept customer identifiers.
# Install Stripe CLI
brew install stripe/stripe-cli/stripe
# Forward webhooks to local dev
npm run stripe:listen
# In another terminal
npm run dev
Works out of the box with:
@sveltejs/adapter-node@sveltejs/adapter-cloudflareRemember to set environment variables and update webhook URLs in Stripe Dashboard.
MIT ā see LICENSE