Initial Setup
Stripe
Setting up Stripe
API Keys
web/.env
To get your Stripe API keys:
- Create a Stripe account
- Go to the Developers section in your Stripe Dashboard
- Under “API keys” you’ll find both your publishable and secret keys
- For development, use the test mode keys
- For production, switch to live mode to get production keys
Webhook Setup
Webhooks are essential for handling Stripe events (successful payments, subscription updates, etc.).
-
Install the Stripe CLI to get your webhook secret
-
Login to the Stripe CLI:
- Open a new terminal and start listening for webhooks:
This command will output your webhook signing secret - copy it to
web/.env
Products and Prices Setup
Creating Products
- Go to Products in your Stripe Dashboard
- Click “Add product”
- Create two products (example):
- Starter Plan
- Pro Plan
Setting Up Prices
For each product, you’ll need to create multiple prices:
web/.env
For each product:
- Click “Add price”
- Create recurring prices:
- Monthly subscription (e.g., $9/month)
- Annual subscription (e.g., $90/year)
- Create one-time prices if needed
- Copy the price IDs to your
.env
Price ID Location
To find your price IDs:
- Go to Products
- Click on a product
- Under “Pricing”, you’ll see all prices for that product
- Click the ”…” menu next to each price
- Select “Copy ID” - it will look like
price_XXXXXXXXXXXXXXXXX
Webhooks
Webhooks are essential for handling Stripe events (successful payments, subscription updates, etc.).
-
Open webhooks in the Stripe Dashboard
-
Click “Add webhook”
-
Set your webhook URL to:
https://yourdomain.com/api/webhooks/stripe
-
Add the following events:
Testing
Use Stripe’s test cards for payments:
- Success:
4242 4242 4242 4242
- Decline:
4000 0000 0000 0002
- Use any future date for expiry and any 3 digits for CVC
See Stripe Testing for more information.
Going Live
Before going live:
- Complete Stripe’s account activation process
- Switch to live mode in the Stripe Dashboard
- Update your environment variables with live mode keys
- Set up production webhooks
- Test the entire payment flow in live mode with a real card (use a small amount)
- Monitor your Stripe Dashboard for real transactions
Common Issues
- Webhook errors: Ensure your webhook endpoint is accessible and the signing secret is correct
- Payment failures: Check the Events section in Stripe Dashboard
- Price ID issues: Verify you’re using the correct price IDs for test/live mode in combination with the correct stripe keys