Payments

Payments

Payments are implemented through Creem. The template includes subscription billing, one-time credit purchases, webhook handling, and plan lookup.

Main files

PathPurpose
src/features/payment/creem.tsCreem client and API integration
src/features/payment/actions.tsCheckout and payment Server Actions
src/features/payment/types.tsPayment-related types
src/config/payment.tsProduct/payment configuration
src/config/subscription-plan.tsPlan definitions
src/app/api/webhooks/creem/route.tsCreem webhook endpoint
src/features/subscriptionUser plan lookup and subscription UI
src/test/paymentPayment and subscription tests

Required environment variables

VariablePurpose
CREEM_API_KEYCalls Creem APIs
CREEM_WEBHOOK_SECRETVerifies webhook signatures

Production callback and webhook URLs should use your deployed domain.

Subscription flow

  1. Plans are defined in src/config/subscription-plan.ts.
  2. The pricing UI renders available plans.
  3. A checkout action creates a Creem checkout session.
  4. Creem sends webhook events.
  5. The webhook updates subscription state.
  6. The dashboard reads the current user plan.

Credit purchase flow

One-time credit purchases share the payment layer but grant credit packages after successful payment. See Credits for ledger behavior.

Webhook checklist

Before going live:

  1. Configure the Creem webhook URL:
https://your-domain.com/api/webhooks/creem
  1. Set CREEM_WEBHOOK_SECRET.
  2. Test a checkout in sandbox mode if available.
  3. Confirm subscription state updates.
  4. Confirm duplicate webhook events do not double-grant credits.
  5. Run payment tests.
pnpm test:run src/test/payment

On this page