This is a Next.js project bootstrapped with create-next-app
.
First, run the development server:
yarn dev
Open http://localhost:3000 with your browser to see the result.
- A Stripe account (create one at stripe.com)
- The Stripe CLI installed (installation guide)
- Login to your Stripe account in the CLI:
stripe login
- Start the webhook listener:
stripe listen --forward-to localhost:3000/api/webhooks/stripe
- Copy the webhook signing secret shown in the CLI and add it to your
.env
:
STRIPE_WEBHOOK_SECRET=whsec_xxxxx
STRIPE_SECRET_KEY=sk_test_xxxxx
NEXT_PUBLIC_APP_URL=http://localhost:3000
In a new terminal, you can trigger test events:
# Test successful subscription
stripe trigger checkout.session.completed
# Test subscription cancellation
stripe trigger customer.subscription.deleted
Use these cards in test mode:
- Success: 4242 4242 4242 4242
- Decline: 4000 0000 0000 0002
- 3D Secure: 4000 0000 0000 3220
To learn more about Next.js, take a look at the following resources:
The easiest way to deploy your Next.js app is to use the Vercel Platform.