iconDirEasy
Payments

Configuration

Configure billing for your application.

Custom enabled launch types [optional]

You can enable or disable paid launch types in the lib/constants.ts file.

constants.ts
// Enabled paid launch types , free launch is required
export const ENABLED_PAID_LAUNCH_TYPES = [
  LAUNCH_TYPES.PREMIUM,
  LAUNCH_TYPES.PREMIUM_PLUS,
  LAUNCH_TYPES.SEO_ARTICLE,
] as const

Set environment variables

Environment variables must be set to configure your billing system.

.env
# Payment [Required] set the default payment provider for the checkout page. Must be one of `stripe` or `polar`
NEXT_PUBLIC_DEFAULT_PAYMENT_PROVIDER=
# [Required] priceId for stripe, productId for polar. If you don't want to use some of them, leave them empty.
NEXT_PUBLIC_PREMIUM_PAYMENT_PRICE_ID=
NEXT_PUBLIC_PREMIUM_PLUS_PAYMENT_PRICE_ID=
NEXT_PUBLIC_SEO_ARTICLE_PRICE_PAYMENT_PRICE_ID=
## Stripe [only required if you want to use Stripe Checkout]
#STRIPE_SECRET_KEY=sk_test_...
#STRIPE_WEBHOOK_SECRET=whsec_...
## Polar [only required if you want to use Polar Checkout]
#POLAR_ACCESS_TOKEN=
## "sandbox" or "production"
#POLAR_ENV=
#POLAR_WEBHOOK_SECRET=

Next, we will introduce the integration with the payment provider.

Stripe

Get the api key

After you have created your account for Stripe, you will need to get the API key. You can do this by going to the API page in the dashboard. Here you will find the Secret key and the Publishable key. You will need the Secret key for the integration to work.

Create products

Create the corresponding products and prices according to your needs.

Create a webhook

To configure a new webhook, go to the Webhooks page in the Stripe dashboard. Click the Add endpoint button and select at least the following events:

  • checkout.session.completed
  • checkout.session.expired

Enter your webhook endpoint URL. Refer to the Webhook endpoint section for more information.

Local Development

To test webhooks locally, prefer use the Stripe CLI to forward webhooks to your local server.

Terminal
stripe login
stripe listen --forward-to localhost:3000/api/auth/stripe/webhook
If you're testing locally this way, you don't need to create a webhook. But when going to production, you have to create a webhook.

Polar

Get the api key

After you have created your account for Polar, you will need to get the API key. You can do this by going to the API page in the dashboard. Under the Settings, scroll to Developers and click New token. Enter a name for the token, set the expiration duration and select the scopes you want the token to have. To keep it simple, you can select all scopes.

Create products

Create the corresponding products and prices according to your needs.

Create a webhook

To configure a new webhook, go to the Webhooks page in the polar dashboard. Click the Add endpoint button and select at least the following events:

  • checkout.updated

Enter your webhook endpoint URL. Refer to the Webhook endpoint section for more information.

On this page