stripe
Stripe — Next.js App Router
Complete Stripe integration patterns for Next.js App Router with Server Actions and Route Handlers.
Setup (3 steps)
Step 1: Install
npm install stripe @stripe/stripe-js @stripe/react-stripe-js
Step 2: Environment variables
Copy templates/env-example.txt → .env.local and fill in your keys from Stripe Dashboard.
| Env Variable | Value | Exposed to Client |
|---|---|---|
STRIPE_SECRET_KEY |
sk_test_... or sk_live_... |
NO |
NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY |
pk_test_... or pk_live_... |
Yes |
STRIPE_WEBHOOK_SECRET |
whsec_... |
NO |
NEXT_PUBLIC_APP_URL |
http://localhost:3000 |
Yes |
Step 3: Initialize SDK
Copy templates/stripe-server.ts → lib/stripe.ts and templates/stripe-client.ts → lib/stripe-client.ts.
Load references/setup.md for details.
Quick Patterns
| Task | Approach | Reference |
|---|---|---|
| One-time payment | Checkout Session → redirect to Stripe | references/checkout.md |
| Custom payment UI | Payment Intents + Stripe Elements | references/payment-intents.md |
| Recurring billing | Subscriptions + Invoices | references/subscriptions.md |
| Receive events | Webhook Route Handler | references/webhooks.md |
| Self-service billing | Customer Portal session | references/customer-portal.md |
| Products & pricing | Products + Prices API | references/products-prices.md |
| Marketplace splits | Stripe Connect | references/connect.md |
| Auto tax calc | Stripe Tax | references/tax.md |
| Fraud prevention | Radar rules + 3D Secure | references/radar-fraud.md |
| Usage-based billing | Billing Meter + usage records | references/billing-meter.md |
| Pricing page | Server-fetched prices + checkout button | references/pricing-page.md |
| Stripe ↔ DB sync | Webhook → database update patterns | references/database-sync.md |
| Paywall / auth guard | Middleware + Server Component guards | references/middleware-guard.md |
Essential Webhook Events
| Event | When | Action |
|---|---|---|
checkout.session.completed |
Payment captured | Fulfill order |
invoice.paid |
Subscription renewed | Extend access |
invoice.payment_failed |
Payment failed | Notify user, retry |
customer.subscription.updated |
Plan changed | Update entitlements |
customer.subscription.deleted |
Cancelled | Revoke access |
payment_intent.succeeded |
Custom flow completed | Confirm order |
charge.dispute.created |
Dispute opened | Alert + evidence |
Load references/webhooks.md for handler implementation.
Test Cards
| Number | Result |
|---|---|
4242 4242 4242 4242 |
Success |
4000 0000 0000 0002 |
Generic decline |
4000 0000 0000 9995 |
Insufficient funds |
4000 0000 0000 0069 |
Expired card |
4000 0025 0000 3155 |
3D Secure required |
4000 0000 0000 3220 |
3D Secure 2 required |
Load references/testing.md for full test cards + Stripe CLI workflow.
Stripe CLI
stripe login
stripe listen --forward-to localhost:3000/api/webhooks/stripe
stripe trigger checkout.session.completed
stripe trigger invoice.payment_failed
stripe logs tail --filter status:400
Templates
| Template | Copy To | Description |
|---|---|---|
templates/stripe-server.ts |
lib/stripe.ts |
Server-side Stripe instance |
templates/stripe-client.ts |
lib/stripe-client.ts |
Client-side Stripe.js (lazy) |
templates/webhook-handler.ts |
app/api/webhooks/stripe/route.ts |
Webhook Route Handler |
templates/checkout-action.ts |
app/actions/checkout.ts |
Server Action: Checkout Session |
templates/subscription-action.ts |
app/actions/subscription.ts |
Server Actions: subscription CRUD |
templates/customer-portal-action.ts |
app/actions/portal.ts |
Server Action: portal session |
templates/env-example.txt |
.env.local |
Environment variables |
Error Handling
Load references/error-handling.md for Stripe error types and retry patterns.
Security
Load references/security.md for PCI compliance, idempotency, and key management.
All References
references/setup.md— SDK init, singleton, TypeScript configreferences/checkout.md— Checkout Sessions, hosted vs embeddedreferences/payment-intents.md— Payment Intents, 3D Secure, capturereferences/subscriptions.md— Recurring billing, trials, prorationreferences/webhooks.md— Signature verification, event routing, idempotencyreferences/customer-portal.md— Self-service portal setupreferences/products-prices.md— Products, Prices, coupons, promo codesreferences/connect.md— Marketplace, platform fees, payoutsreferences/tax.md— Automatic tax calculationreferences/radar-fraud.md— Fraud detection, disputesreferences/billing-meter.md— Usage-based billingreferences/error-handling.md— Error types, retry logicreferences/testing.md— Test cards, CLI, test clocksreferences/security.md— PCI, keys, idempotency, CSPreferences/pricing-page.md— Pricing page component patternreferences/database-sync.md— Stripe ↔ DB sync patternsreferences/middleware-guard.md— Auth middleware for paid routes
More from clownnvd/claude-code-skills
prisma-better-auth-nextjs
Prisma 7 + Better Auth + Next.js App Router. Email/password, OAuth, 2FA, rate limiting, audit logging. Triggers: add auth, better auth, prisma auth, nextjs login, sign-up/sign-in, auth scaffold.
14ui-ux-pro-max
UI/UX design intelligence. 93 styles, 121 palettes, 81 font pairings, 35 charts, 79 components, 62 animations, 65 WCAG criteria, 46 responsive patterns, 46 dark mode rules, 60 design tokens, 13 stacks. Actions: plan, build, create, design, implement, review, fix, improve, optimize, enhance, refactor, check. Styles: glassmorphism, brutalism, neumorphism, bento, dark mode, view transitions, scroll-driven, container queries, AI-native, liquid glass, neo-minimalism, mesh gradient, geometric abstraction. Topics: color, accessibility, animation, layout, typography, spacing, shadow, gradient, responsive, dark mode, WCAG 2.2, design tokens, components, spring physics, kinetic typography, container queries, popover API, semantic tokens.
9nextjs
Next.js 16 App Router patterns, proxy.ts, use cache, async APIs, 37 documented errors with fixes, ecosystem compatibility, postinstall patches.
8vercel-react-best-practices
React and Next.js performance optimization guidelines from Vercel Engineering. This skill should be used when writing, reviewing, or refactoring React/Next.js code to ensure optimal performance patterns. Triggers on tasks involving React components, Next.js pages, data fetching, bundle optimization, or performance improvements.
8agent-browser
Browser automation CLI for AI agents. Use when the user needs to interact with websites, including navigating pages, filling forms, clicking buttons, taking screenshots, extracting data, testing web apps, or automating any browser task. Triggers include requests to "open a website", "fill out a form", "click a button", "take a screenshot", "scrape data from a page", "test this web app", "login to a site", "automate browser actions", or any task requiring programmatic web interaction.
7ui-clone
Clone any app UI from PageFlows. WAT framework: capture screenshots → analyze+build with visual diff → package as reusable skill. Works for any app.
2