6. Configure Stripe
Follow the below steps to configure Stripe for you application and start accepting payments.
Create a Stripe account
Head on over to Stripe and create an account if you don't already have one.
Test mode
We recommend setting everything up in "Test mode" first by switching on the "Test mode" toggle in the Stripe dashboard. Once you are ready for production, follow the below steps while in production mode.
Create products and prices
Once you have your Stripe account set up, it's time to create your products. You can configure any number of products you want - for example you might want one product for a cheaper plan and one product for a more expensive premium plan. For each product you want to create, repeat the below steps:
Go to Products -> Add product and add your product details. Since Volca was created for SaaS products, pick the recurring billing method.
When you are done, save the product, scroll down to the "Pricing" heading and copy the ID of the price you just configured.
Configure plans
To configure your products in Volca, follow the below steps for each product you created and for each environment:
- Add a
PlanId
for your product in the fileconfig/types.ts
. By default there are three plans configured -BASIC
,PLUS
andPREMIUM
. Feel free to remove them or rename them as you prefer. - Add your plans to the
plans
configuration for each environment inapp.config.ts
. A new plan can be added like this:
plans: [
...
{
id: PlanId.MY_NEW_PLAN,
stripePriceId: 'stripe-price-id', // Your price ID from Stripe
}
...
]
Finally, in clients/web/src/pages/onboarding.tsx
add your plan to the plans
array like this:
const plans = {
...
MY_NEW_PLAN: {
title: 'My New Plan',
description: 'A plan that is mine and new.',
price: 19,
features: ['Feature A', 'Feature B'],
}
...
}
Set the STRIPE_KEY locally
To get subscriptions running locally, open the .env
file in the root folder and add:
STRIPE_KEY=
The Stripe secret key found in the "Developers" tab in the Stripe dashboard
And then add your STRIPE_PRICE_ID
to the app.config.ts
file.
Now you can start your project locally and try subscribing!
Set the STRIPE_KEY parameter in AWS
This step requires you to have deployed your app to AWS at least once by following the deploy infrastructure guide.
- Open the AWS console
- Open Services -> Systems Manager -> Parameter Store
- Find the existing parameter called
/<name>/<environment>/STRIPE_KEY
- Update the parameter with your Stripe key and save
- For the updated parameter to be updated in your app, you need to re-deploy it by triggering the GitHub action
deploy-api-service
either from the GitHub UI or by pushing a commit to themain
branch.
Now you should be able to accept payments in your deployed application!
Webhooks
Whenever a customer makes a purchase through your Stripe checkout flow, the database needs to be updated to add a subscription for the user who made the purchase. This is done using webhooks. You will need to set up a webhook for each environment that your project runs in.
- Sign in to the Stripe dashboard
- Go to the Developers tab
- Go to Webhooks
- Click Add endpoint
- Enter the following values
Endpoint URL:
<your-api-url>/stripe/webhook
Events:customer.subscription.created
andcustomer.subscription.deleted
- Leave the rest as default and click Add endpoint
Next, we need to add the webhook secret to our configuration.
- Click the webhook you created in the Stripe dashboard
- Click Signing secret -> Reveal
- Copy the secret
- Go into AWS -> Systems Manager -> Parameter Store
- Find the STRIPE_WEBHOOK_SECRET parameter and update it with the value from Stripe
- Re-deploy your project
Now you are done! Stripe will alert you if your webhook would fail.
Free trial
The free trial length can be configured by setting the environment variable FREE_TRIAL_DAYS
to the number of days you want to offer a free trial.
Test card
If the environment variable TEST_CARD_ENABLED
is set to 1
, a test card will automatically be created when a checkout session is started. This is useful when you want to test the checkout flow.