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

  1. Install the Stripe CLI using brew:
brew install stripe/stripe-cli/stripe
  1. Log in to Stripe via the CLI:
stripe login
  1. Start the Stripe webhook listener:
npm run stripe:listen
  1. You will now receive a webhook signing secret from the Stripe CLI. Update the .env.local file with it:
STRIPE_WEBHOOK_SECRET=

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:

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.

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.