Chargebee
Get the api key
After you have created your account for Chargebee, you will need to get the API key. Refer to this page to learn how to get the API key.
Add environment variables
To use the Chargebee integration, you need to define the following environment variables to your .env.local
as well as your production environment:
Create products
For your users to choose from the available subscription plans, you need to create those Plans. You can create as many products as you want, but you will need to create at least one product for the integration to work.
Create one plan you want to offer. You can add multiple prices within this plan to offer multiple currencies or different billing intervals.
Create a webhook
To sync the current subscription status and other information to your database, you need to set up a webhook.
The webhook code comes ready to use with supastarter, you just have to create the webhook in Chargebee and add the URL for your project.
To configure a new webhook, go to the Webhooks settings as described here and click the Add Webhook button.
Select the following events:
- Subscription Created
- Subscription Changed
- Subscription Cancelled
To get the URL for the webhook, you can either use a local development URL or the URL of your deployed app:
Local development
If you want to test the webhook locally, you can use ngrok to create a tunnel to your local machine. Ngrok will then give you a URL that you can use to test the webhook locally.
To do so, install ngrok and run it with the following command (while your supastarter development server is running):
This will give you a URL (see the Forwarding output) that you can use to create a webhook in Chargebee. Just use that url and add /api/webhooks/chargebee
to it.
Production / preview deployment
When you have already deployed a version of your project, you can use the actual URL to create the webhook with. This will be necessary for a production version your app later anyway.
Then you can use the URL of your deployed app and add /api/webhooks/chargebee
to it.
Example URL: https://your-app.com/api/webhooks/chargebee