A simple Next.js demo showing Stripe subscriptions with feature entitlements, coupons, and promotion codes. No user authentication - just email-based customer matching for demo purposes.
- Creates tiered subscription plans (Core £3/month, Plus £5/month, Ultra £10/month)
- Shows different features per tier using Stripe's entitlements system
- Handles subscriptions via Stripe Checkout with coupon/promo code support
- Demonstrates discount application with coupons and promotion codes
- Immediate access suspension on payment failures with automatic restoration
- Discord webhook logging for subscription events and payment monitoring
- Basic demo - customer identification by email only
pnpm install- Sign up at stripe.com
- Go to Dashboard > API Keys
- Copy your test keys (pk_test_... and sk_test_...)
For subscription event monitoring:
- Create a Discord server and channel for logs
- Create a Discord bot:
- Go to Discord Developer Portal
- Create new application → Bot → Copy bot token
- Enable bot permissions:
Send Messages,Use Slash Commands - Invite bot to your server with these permissions
- Get your log channel ID:
- Enable Developer Mode in Discord settings
- Right-click your log channel → Copy ID
NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY=pk_test_your_key_here
STRIPE_SECRET_KEY=sk_test_your_key_here
STRIPE_WEBHOOK_SECRET=whsec_your_webhook_secret_here
# Discord logging (optional)
DISCORD_BOT_TOKEN=your_bot_token_here
STRIPE_LOG_CHANNEL_ID=your_channel_id_here
DISCORD_WEBHOOK_URL=your_webhook_url_hereImportant: Webhooks don't work in local development by default. You need Stripe CLI:
- Install Stripe CLI
- Login:
stripe login - Forward webhooks to your local server:
stripe listen --forward-to localhost:3000/api/webhooks/stripe- Copy the webhook signing secret from the CLI output to your
.envfile
# Create everything at once (recommended)
pnpm run create:all
# Or create individually:
pnpm run create:feat # Create features first
pnpm run create:prod # Then create products
pnpm run create:coup # Create coupons
pnpm run create:promo # Create promotion codes
pnpm run create:logs # Create Discord webhook (optional)pnpm run devVisit http://localhost:3000
Setup:
pnpm run create:all- Create features, products, coupons, promotion codes, and Discord webhookpnpm run create:feat- Create Stripe features onlypnpm run create:prod- Create Stripe products onlypnpm run create:coup- Create Stripe coupons onlypnpm run create:promo- Create Stripe promotion codes onlypnpm run create:logs- Create Discord webhook for logging only
Development:
pnpm run dev- Start development serverpnpm run build- Build for production
Cleanup:
pnpm run clean- Remove incomplete subscriptions, unpaid invoices, failed paymentspnpm run wipe-⚠️ DANGER: Completely wipe all Stripe test data (products, customers, subscriptions, everything!)
- Enter any email address
- Choose Core (£3/month), Plus (£5/month), or Ultra (£10/month)
- Apply promotion codes if desired
- Use any test card like
4242 4242 4242 4242 - Any future expiry date and any 3-digit CVC
- Immediate lockout on first payment failure
- Automatic restoration when payment succeeds
- Suspended entitlements preserved during suspension
- Multiple retry attempts handled gracefully
- Discord notifications for payment failures and recoveries
Automatic logging for:
- ✅ Successful subscriptions - Customer details, plan, billing cycle, discounts
- ❌ Subscription cancellations - Reason, feedback, duration, customer comments
- 🚨 Payment failures - Failed amount, attempt count, customer details
- 💰 Payment recoveries - Successful retry notifications
Rich embed format with:
- Customer information (name, email, ID)
- Plan details (name, billing cycle, amount)
- Cancellation insights (reason, feedback, duration)
- Discount information when applicable
- Technical references (subscription/invoice IDs)
- Demo only - No real authentication, just email matching
- Test mode - No real payments processed
- Local webhooks - Must use Stripe CLI for local development
- Discord logging - Optional but recommended for monitoring
- Cleanup scripts - Use
cleanfor minor cleanup,wipeto reset everything - Promotion codes - Test various discount scenarios with provided codes
- Webhooks not working: Make sure Stripe CLI is running with
stripe listen - "Feature not found": Run
pnpm run create:featfirst - Products missing: Run
pnpm run create:prodafter creating features - Coupons not working: Run
pnpm run create:coupandpnpm run create:promo - Discord logging not working: Check bot permissions and webhook URL
- Need fresh start: Use
pnpm run wipethenpnpm run create:all
/api/stripe/create-subscription- Create new subscription/api/stripe/products- Fetch available products and pricing/api/stripe/verify-promo- Verify promo code is allowed for user's email/api/stripe/verify-payment- Verify payment status/api/stripe/verify-subscription- Verify subscription status/api/stripe/webhooks- Handle Stripe webhooks and Discord logging
Happy Path:
- Subscribe with promotion code
- Verify discounted pricing
- Complete payment successfully
- Check feature access
- Monitor Discord logs for success notification
Payment Failure:
- Subscribe with failing card (
4000000000000002) - Verify immediate access suspension
- Check Discord notification for payment failure
- Update payment method
- Verify automatic access restoration
- Monitor Discord logs for recovery notification
Cancellation Testing:
- Create successful subscription
- Cancel via Stripe Dashboard with reason/feedback
- Monitor Discord logs for cancellation details
- Verify customer feedback and duration tracking
Discount Validation:
- Try expired promotion codes
- Test usage limits
- Verify discount calculations
- Check recurring vs one-time discounts
- Monitor Discord logs for discount application
- Channel organization: Create separate channels for different event types
- Bot permissions: Ensure bot has
Send MessagesandEmbed Linkspermissions - Webhook vs Bot: Script creates webhook automatically, but you can also use bot token directly
- Message formatting: Rich embeds provide better readability than plain text
- Rate limiting: Discord has rate limits, but normal subscription volume shouldn't hit them