Stripe
2mrw uses Stripe for all billing related transactions. Follow these steps to set up the products and prices, set up the Stripe CLI, etc.
Creating a Product in Stripe
Updating The stripe_price_id Inside The Codebase
In this example, we’re updating the stripe_price_id for the ESSENTIALS plan for the MONTHLY subscription.
The exact same logic applies to all other plans when updating their stripe_price_id. For instance, when adding the annual plan for the INDIE HACKER plan we just have to get its price id from Stripe and insert it into the appropiate object inside our pricing.config.ts file.
Updating the Stripe Secret Key
TL / DR: You should have a stripe secret key in the .env.local file that can be found in the Stripe Dashboard under the API Keys tab.
Enabling Stripe Billing Portal
Search for Customer Portal in the Stripe Dashboard and enable it by clicking Activate Link. This will enable the Stripe Billing Portal.
Setting up the Stripe CLI
- Install the Stripe CLI using brew:
- Log in to Stripe via the CLI:
- Start the Stripe webhook listener:
- You will now receive a webhook signing secret from the Stripe CLI. Update the
.env.local
file with it:
How To Use Stripe on Localhost
In order to use Stripe on localhost, we need to start the Stripe CLI and enable test mode in the Stripe Dashboard like seen in the demo below. You can run the following command to start the Stripe CLI:
The stripe webhook api/webhook/stripe/route.ts will now listen to incoming Stripe events such as checkout.session.completed, subscription.updated, subscription.deleted, etc.
How To Use Stripe In Production
TL / DR: You should have a stripe webhook endpoint that listens for the checkout.session.completed, customer.subscription.updated and customer.subscription.trial_will_end events.
You now have an active stripe webhook that will listen to the events mentioned above and trigger the appropriate actions in the codebase.
Further Configuration (Optional)
If desired, it’s also possible to configure the PAYOUT schedule in the Stripe Dashboard and activate emails for successful PAYMENTS and REFUNDS.