Get the api key

After you have created your account for Creem, 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.

Add environment variables

To use the Creem integration, you need to define the following environment variables to your .env.local as well as your production environment:

.env.local
CREEM_API_KEY=
CREEM_WEBHOOK_SECRET=

In-App Purchases

You can use Creem anywhere in your application by importing a creem object:

page.tsx
import { creem } from '@repo/payments';

Creating a Checkout Session

We need to create a checkout session to charge your users , and you only need modify some code. It consists of two parts:

  • Client

It sends a request to create a session to the /api/creem/checkout endpoint.

apps/web/[locale]/components/payment/price-form.tsx
      const response = await fetch('/api/creem/checkout', { // change to `/api/creem/checkout`
        method: 'POST',
        body: JSON.stringify({
          priceId: item.priceId,
          interval: item.interval,
        }),
      });
  • Server

Implementing business logic in apps/web/api/creem/checkout/route.ts.