Dodo Payments
Learn how to set up Dodo Payments with supastarter.
Get the API key
After you have created your account for Dodo Payments, you will need to get the API key. You can do this by going to the API keys page in the dashboard.
Add environment variables
To use the Dodo Payments integration, you need to define the following environment variables to your .env.local as well as your production environment:
DODO_PAYMENTS_API_KEY="" # Your Dodo Payments API key
DODO_PAYMENTS_WEBHOOK_SECRET="" # The secret key of the webhook you created (see below)Create products
For your users to choose from the available subscription plans, you need to create those Products first on the Products page. 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 product per plan you want to offer. You can add multiple prices within this product 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 the Dodo Payments dashboard and insert the URL for your project.
To configure a new webhook, go to the Webhooks page in the Dodo Payments settings and click the Add endpoint button.
Select the following events:
checkout.session.completedsubscription.createdsubscription.updatedsubscription.cancelled
Local development
If you want to test the webhook locally, you can use ngrok to create a tunnel to your local machine.
To do so, install ngrok and run it with the following command (while your supastarter development server is running):
ngrok http 3000This will give you a URL (see the Forwarding output) that you can use to create a webhook. Just use that url and add /api/webhooks/payments 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.
Make sure you have a deployed version that has the DODO_PAYMENTS_WEBHOOK_SECRET environment variable set.
Then you can use the URL of your deployed app and add /api/webhooks/payments to it.
Example URL: https://your-app.com/api/webhooks/payments
Set up products in app
The created products have to be defined in the packages/payments/config.ts file. See the plans documentation for more details on plan configuration.
Set currency for locales in your app
You can configure the currency for each locale in packages/i18n/config.ts.
Test Mode vs Live Mode
Dodo Payments provides two environments for testing and production:
- Test Mode: Use
https://test.dodopayments.comfor development and testing - Live Mode: Use
https://live.dodopayments.comfor production
Make sure to use the appropriate environment URLs and API keys for each stage of your development process.
Per default, supastarter uses Live mode when the NODE_ENV is set to production. You can change this behavior in the packages/payments/providers/dodopayments/index.ts file.