Add these to your .env.local file:
# Stripe API Keys (get from https://dashboard.stripe.com/apikeys)
STRIPE_SECRET_KEY=sk_test_your_secret_key_here
NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY=pk_test_your_public_key_here
# Webhook secret (get from https://dashboard.stripe.com/webhooks)
STRIPE_WEBHOOK_SECRET=whsec_your_webhook_secret_here
# App URL for payment redirects
NEXT_PUBLIC_APP_URL=http://localhost:3000- Go to https://dashboard.stripe.com/apikeys
- Copy your Secret Key →
STRIPE_SECRET_KEY - Copy your Publishable Key →
NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY
- Go to https://dashboard.stripe.com/webhooks
- Click "Add endpoint"
- Set URL to:
https://yourdomain.com/api/webhooks/stripe - Select events to listen to:
checkout.session.completedcustomer.subscription.deleted(optional for cancellation)
- Copy the Signing Secret →
STRIPE_WEBHOOK_SECRET
For local development, use Stripe CLI to forward webhook events:
stripe listen --forward-to localhost:3000/api/webhooks/stripeCopy the webhook signing secret and add to .env.local
- Start the app:
npm run dev - Go to
/premiumpage - Click "Start Free Trial" on Pro plan
- You'll be redirected to
/premium-payment - Use Stripe test card:
4242 4242 4242 4242 - Use any future expiry date and any CVC
- After payment, you'll be marked as Pro
- Visa: 4242 4242 4242 4242
- Failed payment: 4000 0000 0000 0002
- Expiry: Any future date
- CVC: Any 3 digits
- User clicks "Start Free Trial" on Pro plan
- Redirected to
/premium-paymentpage - Stripe embedded checkout loads
- User enters payment details
- After successful payment:
- Stripe sends webhook to
/api/webhooks/stripe - User added to
pro_memberstable - User redirected to success page
- Profile shows Pro badge
- Stripe sends webhook to
To enable email receipts, you can integrate with:
- Resend (recommended for Next.js):
npm install resend - SendGrid:
npm install @sendgrid/mail - Mailgun:
npm install mailgun.js
Then uncomment and implement the email sending in:
lib/email.tssrc/app/api/stripe/verify-payment/route.ts
Example with Resend:
// lib/email.ts
import { Resend } from 'resend';
const resend = new Resend(process.env.RESEND_API_KEY);
export async function sendReceiptEmail(email: string, session: Stripe.Checkout.Session) {
await resend.emails.send({
from: '[email protected]',
to: email,
subject: 'Welcome to SkyDark Pro!',
html: generateReceiptHtml(session),
});
}Then add RESEND_API_KEY=your_key_here to .env.local