💰 Stripe environment variables

The first thing you need to do is create a Stripe account (opens in a new tab).

Once you have created your account, you should enable the test mode in the top right corner of your Stripe dashboard.

STRIPE_PUBLISHABLE_KEY and STRIPE_SECRET_KEY

You can find those directly on the home-page of your Stripe dashboard.

Stripe secret key

STRIPE_BASIC_PRICE_ID and STRIPE_PREMIUM_PRICE_ID

Go to Product Catalog and create a new product.

Stripe new product

Set a name and a monthly price (or anything according to your business model). Then click [Save Product].

In the Pricing section, copy the product price ID (starts with price_) and add it to to your .env.{YOUR_STAGE_NAME}.local file.

Stripe price id

💡

Once you are ready to offer your app to the public, switch off the test mode in stripe, create new live products and copy the price IDs to the base .env file.

STRIPE_WEBHOOK_SECRET

Now let's set up the webhook that will notify your backend about new successful checkouts through Stripe. First, go to Developers -> Webhooks -> Add endpoint.

Stripe webhooks

In test mode your your webhook URL should look like this:

https://api-<YOUR_STAGE_NAME>.<YOUR_DOMAIN>/billing/webhooks

So for example: https://api-maxim.blitz-ship.com/billing/webhooks

When you create webhooks in production mode, simply remove the -<YOUR_STAGE_NAME> part from the URL.

Your webhook should be listening to at least the checkout.session.completed event.

This is what a correctly set up webhook looks like:

Stripe correct webhook

Now, click on the Signing secret -> Reveal button and copy the secret to your .env file. It will be used to verify the webhook signature and make sure its really coming from Stripe.

STRIPE_CUSTOMER_PORTAL_LINK

Go to Settings -> Billing -> Customer portal and set up a customer portal link for your customers to manage their subscriptions, invoices and payments.

Stripe customer portal