2mrw uses Stripe for all billing related transactions. Follow these steps to set up the products and prices, set up the Stripe CLI, etc.
1
Creating a Product in Stripe
2
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.
3
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.
4
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.
5
Setting up the Stripe CLI
Install the Stripe CLI using brew:
Copy
brew install stripe/stripe-cli/stripe
Log in to Stripe via the CLI:
Copy
stripe login
Start the Stripe webhook listener:
Copy
npm run stripe:listen
You will now receive a webhook signing secret from the Stripe CLI. Update the .env.local file with it:
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:
Copy
npm run stripe:listen
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.
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.