Stripe
Practical Stripe setup for subscriptions, credits, and one-time payments.
1. Stripe setup
Create a Stripe account
Create your account at Stripe.
Get your API keys
Retrieve your API keys from the Stripe dashboard.
Add environment variables
Add the following environment variables to your project:
STRIPE_SECRET_KEY=sk_live_or_test_key
STRIPE_WEBHOOK_SECRET=whsec_from_stripe_webhookNote: STRIPE_WEBHOOK_SECRET is needed for both production and local testing.
2. Create products with prices
Go to Stripe products
Navigate to the products section in your Stripe dashboard.
Create product
Click the button to create a new product.
Create product prices
Add the necessary price tiers for your new product.
Choose type
Select recurring with a billing period (month, year) or one-off for a one-time purchase.
Use cases
Subscription plans
Set up recurring billing profiles like monthly or yearly plans.
One time payment
Charge users a single time for features, access, or digital goods.
Credits
A usage-based billing approach where users burn credits for actions.
3. Stripe local testing
Forward events
Listen and forward webhook events to your local server.
stripe listen --forward-to localhost:3000/api/payments/webhook/stripeUpdate local .env file
Copy the webhook secret provided by the output of stripe listen and add it to your environment.
STRIPE_WEBHOOK_SECRET=whsec_...Trigger events
Trigger test events manually.
stripe trigger payment_intent.succeededOr finish the checkout flow manually. You can use Stripe test credit cards to complete the checkout.
4. Production
Go to Stripe Webhooks Dashboard
Navigate to the Webhooks page on your Stripe dashboard.
Add endpoint
Register your production URL for webhooks.
https://your-domain.com/api/payments/webhook/stripeSelect events to listen for
Choose the required events to track:
checkout.session.completedinvoice.payment_succeededcustomer.subscription.createdcustomer.subscription.updatedcustomer.subscription.deleted
Copy to environment variables
Copy the production webhook secret and add it to your live .env variables.
STRIPE_WEBHOOK_SECRET=whsec_...