Build Stripe Checkout Integration
fullstack
TypeScript
scaffolding
corporate_pm
Implement complete Stripe payment flow with checkout sessions, webhooks, and customer portal.
By david_kim
12/8/2025
Prompt
Build a complete Stripe Checkout integration for [APPLICATION_NAME] with the following specifications:
Requirements
- Application name: [APPLICATION_NAME]
- Payment type: [One-time/Subscription/Both]
- Products/Plans: [PRODUCT_1], [PRODUCT_2], [PRODUCT_3]
- Currency: [USD/EUR/GBP]
- Framework: [Express/Next.js/Remix/SvelteKit]
- Database: [PostgreSQL/MySQL/MongoDB]
- Success URL: [SUCCESS_PAGE_PATH]
- Cancel URL: [CANCEL_PAGE_PATH]
- Webhook events to handle: [checkout.session.completed, invoice.payment_succeeded, customer.subscription.deleted, etc.]
Deliverables
Generate complete Stripe integration code with:
Stripe initialization:
- Import and configure Stripe SDK with secret key
- Environment variables setup (.env.example)
- TypeScript types for Stripe objects
Checkout session creation endpoint:
- API route: POST /api/create-checkout-session
- Create session for [PAYMENT_TYPE]
- Line items configuration for [PRODUCTS]
- Price data with [CURRENCY] and amounts
- Recurring configuration if subscription
- Success and cancel URLs with session_id
- Customer metadata (userId, email, etc.)
- Return checkout URL to client
Client-side checkout flow:
- Function to call checkout session API
- Redirect to Stripe Checkout hosted page
- Error handling and loading states
- Success/cancel page handling
Webhook endpoint:
- POST /webhooks/stripe with raw body parsing
- Signature verification with webhook secret
- Event type handling for:
- checkout.session.completed: fulfill order
- invoice.payment_succeeded: renew subscription
- customer.subscription.deleted: cancel subscription
- payment_intent.payment_failed: handle failure
- Response with received: true
Order fulfillment function:
- Extract metadata from session
- Update database with:
- Stripe customer ID
- Subscription ID
- Subscription status
- Payment status
- Plan details
- Send confirmation email
Customer portal endpoint:
- API route: POST /api/create-portal-session
- Create billing portal session
- Allow customers to manage subscriptions
- Return portal URL
Database schema updates for user/subscription tracking
Output production-ready Stripe integration with proper error handling and security.
Tags
stripe
payments
checkout
saas
Tested Models
gpt-4
claude-3-5-sonnet