Subscriptions & Stripe
Launchway uses Stripe for subscriptions and payments. Using your Stripe API key and webhook secret, your app will handle displaying pricing pages, checking out subscriptions, upgrading and downgrading subscriptions and allowing users to update their billing information in the Stripe billing portal.
STRIPE_SECRET_KEY=
STRIPE_WEBHOOK_SECRET=
Setup
Once you have your STRIPE_SECRET_KEY
configured, you can run the npm run stripe:setup
script. This will walk you through setting up pricing, products and the customer portal where customers can manage their subscription.
At the end of it, you'll have a multi-product, multi-price subscription setup that could end up something like this. You decide the different tier names, prices and features.
- Basic Plan - $10/month
- Pro Plan - $20/month
- Enterprise Plan - $50/month
The setup script is totally optional. If you prefer you can setup the products and prices manually in the Stripe dashboard yourself.
Webhooks
There are some essential webhooks that the app listens to:
checkout.session.completed
- This handles inserting subscriptions into your database so the user can access your appcustomer.subscription.updated
- This handles upgrades/downgradescustomer.subscription.deleted
- This handles cancellations
To create a new webhook for your production app, you can run npm run stripe:setup
to generate a live webhook that points to your production app.
The webhook script is also optional. If you prefer the Stripe dashboard you can use this instead
Receiving webhooks locally
By default, Stripe sends webhooks only to your live environment. To test your app locally, you can use the built-in npm run stripe:listen
command. This command intercepts webhooks meant for your live environment and forwards them to your local server. With this, you can test the complete subscription lifecycle using your local database and development environment, without affecting your production data. More on that can be found in the official docs (opens in a new tab).