We use Stripe and Dodo Payments to handle credit top-ups. Dodo Payments also acts as a Merchant of Record (MoR) to handle global tax compliance for you if needed.
Configuration
Stripe:
- Create an account at Stripe.
- Get your Pub Secret key, and Webhook signing secret from the developer dashboard.
- Add variables to
.env:
STRIPE_SECRET_KEY=your_secret_key
STRIPE_WEBHOOK_SECRET=your_webhook_secret
Dodo Payments:
- Create an account at Dodo Payments.
- Get your API Key and Webhook Key from the developer settings.
- Set the environment to
test_modefor development. - Add variables to
.env:
DODO_PAYMENTS_API_KEY=your_api_key
DODO_PAYMENTS_WEBHOOK_KEY=your_webhook_key
DODO_PAYMENTS_RETURN_URL=http://localhost:3000
DODO_PAYMENTS_ENVIRONMENT=test_mode
NEXT_PUBLIC_DODO_PAYMENTS_URL=https://test.dodopayments.com
Creating Products (only for Dodo)
- Create a product in your dashboard for one-time credit top-ups (e.g., "100 Credits").
- Copy the Product ID.
- Add it to your
.env(e.g.,DODO_CREDITS_PRODUCT_ID).
Webhooks
The boilerplate includes webhook handlers to process payment events automatically.
Stripe Webhook:
- Located at
/api/payments/stripe/webhook - Listens for
checkout.session.completedevents.
Dodo Webhook:
- Located at
/api/payments/dodo/webhook - Listens for payment success events.
Testing Webhooks Locally
Use tools like the Stripe CLI for Stripe, or ngrok for Dodo or you can do cloudflare tunnel for both
# Stripe CLI
stripe listen --forward-to localhost:3000/api/payments/stripe/webhook
# ngrok for Dodo
ngrok http 3000
Then use the provided forwarding URLs in your dashboard webhook settings.
Credits System
The boilerplate includes a built-in credits system:
- Each user has
creditsTotalandcreditsUsedfields - Credits are added automatically when a payment succeeds
- Track credit usage in your app features
- Configure
CREDITS_PER_UNITin the billing procedures
