Kensa
Admin

Payment Setup (Creem)

Complete guide to integrating Creem payment system, including product creation, webhook configuration, and testing.

Payment Setup (Creem)

This guide covers how to integrate the Creem payment system with Kensa, including creating products, configuring webhooks, and testing the payment flow.

Prerequisites

1. Register a Creem Account

Visit the Creem Dashboard to register and complete verification.

2. Get API Keys

  1. Log in to Creem Dashboard
  2. Go to Settings > API Keys
  3. Create a Publishable Key and Secret Key
  4. Add them to .env.local:
CREEM_API_KEY='creem_live_xxx'  # or creem_test_xxx for testing
CREEM_WEBHOOK_SECRET='your-webhook-secret'

3. Confirm Environment Variables

Ensure these are set in .env.local:

# App URL (important: used for webhook callback)
NEXT_PUBLIC_APP_URL='http://localhost:3000'  # development
# NEXT_PUBLIC_APP_URL='https://your-domain.com'  # production

# Payment provider
NEXT_PUBLIC_BILLING_PROVIDER='creem'

Create Creem Products

You need to create 9 products in the Creem dashboard (3 monthly subscriptions, 3 yearly subscriptions, 3 one-time credit packs).

Product List

Monthly Subscriptions

Product NamePriceCycleCredits
Basic Plan$9.90Monthly280
Pro Plan$29.90Monthly960
Ultimate Plan$79.90Monthly2,850

Yearly Subscriptions

Product NamePriceCycleCredits
Basic Plan (Yearly)$99.00Yearly3,360
Pro Plan (Yearly)$299.00Yearly11,520
Ultimate Plan (Yearly)$799.00Yearly34,200

One-Time Credit Packages

Product NamePriceCreditsAccess
Starter Pack$14.90280All users
Standard Pack$39.90960Subscribers only
Pro Pack$99.902,850Subscribers only

Creating a Subscription Product (Example: Basic Monthly)

  1. Log in to the Creem Dashboard
  2. Go to Products and click Create Product
  3. Fill in the product details:
Product Type: Subscription
Product Name: Basic Plan
Description: 280 credits/month - Perfect for individuals

Pricing:
  Currency: USD
  Price: 9.90
  Billing Cycle: Monthly
  Trial Period: 0

Metadata (optional):
  credits: "280"
  features: "hd_videos,fast_generation"
  1. Click Create Product
  2. Copy the generated Product ID (format: prod_xxx)
  3. Save it to the corresponding entry in pricing-user.ts

Creating Yearly Subscriptions

Repeat the steps above with these changes:

Product Name: Basic Plan (Yearly)
Price: 99.00
Billing Cycle: Yearly
Metadata:
  credits: "3360"

Creating One-Time Credit Packs

  1. Set Product Type to One-time
  2. Do not set a billing cycle
  3. Example configuration:
Product Type: One-time
Product Name: Starter Pack
Description: 280 credits - One-time purchase

Pricing:
  Currency: USD
  Price: 14.90

Metadata:
  credits: "280"
  allow_free_user: "true"

Configure Webhooks

Webhooks receive payment status notifications from Creem and automatically add credits to user accounts.

Step 1: Determine Your Webhook URL

# Development
https://localhost:3000/api/auth/creem/webhook

# Production
https://your-domain.com/api/auth/creem/webhook

Step 2: Set Up Webhook in Creem

  1. Go to Creem Dashboard > Webhooks
  2. Click Add Webhook
  3. Configure:
Endpoint URL: https://your-domain.com/api/auth/creem/webhook
Events:
  - checkout.completed    (payment completed)
  - subscription.created  (subscription created)
  - subscription.updated  (subscription updated)
  - subscription.cancelled (subscription cancelled)
  - subscription.expired  (subscription expired)
Secret: (auto-generated, copy to .env.local)
  1. Click Save
  2. Copy the generated Webhook Secret to .env.local:
CREEM_WEBHOOK_SECRET='whsec_xxx'

Step 3: Verify Webhook (Optional)

Creem sends a test webhook to verify your server can receive it:

# Check local development server logs
pnpm dev

# Or use ngrok to expose local port for testing
ngrok http 3000

Update Code Configuration

Step 1: Update Product IDs

Open src/config/pricing-user.ts and replace all prod_xxx placeholders with the actual Product IDs from Creem:

export const SUBSCRIPTION_PRODUCTS = [
  {
    id: "prod_YOUR_BASIC_MONTHLY_ID", // Replace with actual ID
    name: "Basic Plan",
    priceUsd: 9.9,
    credits: 280,
    period: "month" as const,
    popular: false,
    enabled: true,
  },
  {
    id: "prod_YOUR_PRO_MONTHLY_ID", // Replace with actual ID
    name: "Pro Plan",
    priceUsd: 29.9,
    credits: 960,
    period: "month" as const,
    popular: true,
    enabled: true,
  },
  // ... other products
];

Step 2: Verify Configuration

# Start development server
pnpm dev

# Visit pricing page
open http://localhost:3000/pricing

Verify:

  • All 9 products are displayed on the page
  • Prices display correctly ($9.90, $29.90, etc.)
  • Credit amounts display correctly
  • "Popular" tags appear on the correct products

Testing the Payment Flow

1. Test Environment Configuration

Creem provides test keys for simulating payments:

# .env.local
CREEM_API_KEY='creem_test_xxx'
CREEM_WEBHOOK_SECRET='whsec_test_xxx'

2. Test One-Time Purchase

  1. Visit the pricing page at http://localhost:3000/pricing
  2. Click the One-time credit packs tab
  3. Click the purchase button on Starter Pack
  4. Use the Creem test card to complete payment
  5. After success, redirect to /my-creations?payment=success
  6. Check that user credits increased

Test card details (Creem test environment):

Card Number: 4242 4242 4242 4242
Expiry: Any future date (e.g., 12/34)
CVC: Any 3 digits (e.g., 123)

3. Test Subscription Purchase

  1. Switch to the Monthly subscription tab
  2. Click the subscribe button on Pro Plan
  3. Complete payment
  4. Verify user subscription status, credits, and subscription management button

4. Test Webhook

Use Creem Dashboard's webhook testing feature:

  1. Go to Webhooks and select your webhook
  2. Click Send test webhook
  3. Select event type: checkout.completed
  4. Check your server logs to confirm receipt

5. Verify Credit System

pnpm script:check-credits [email protected]

Troubleshooting

Product ID Not Found

Cause: Product not created or ID copied incorrectly.

Fix:

  1. Log in to Creem Dashboard
  2. Go to Products and find the product
  3. Copy the Product ID (format: prod_xxx)
  4. Paste into pricing-user.ts without extra spaces

Webhook Not Working

Checklist:

  • NEXT_PUBLIC_APP_URL is correct (no trailing slash)
  • Webhook URL is https://yourdomain.com/api/auth/creem/webhook
  • Webhook Secret is correctly copied to .env.local
  • Server is accessible from the internet (use ngrok for development)

Payment Succeeded But Credits Not Added

Cause: Webhook not processed correctly.

Debug steps:

  1. Check server logs for Creem-related entries
  2. Query the credit_transactions table in your database
  3. Query the creem_subscriptions table

How to Disable a Product

Set enabled to false in pricing-user.ts:

{
  id: "prod_xxx",
  name: "Basic Plan",
  enabled: false, // Disabled
  // ...
}

How to Change Prices

Important: Do not modify existing products directly. The correct process is:

  1. Create a new product (v2) in Creem dashboard
  2. Update the Product ID in pricing-user.ts
  3. New users will use the new product
  4. Existing subscribers continue on the old product until their subscription ends

Production Checklist

Before deploying to production, complete the following:

Environment Variables

  • NEXT_PUBLIC_APP_URL set to production domain
  • CREEM_API_KEY using production key (creem_live_xxx)
  • CREEM_WEBHOOK_SECRET using production secret

Product Configuration

  • All 9 product IDs filled in
  • Product prices match pricing-user.ts
  • Credit amounts configured correctly

Webhook

  • Webhook URL uses production domain
  • Webhook secret updated
  • Test webhook sent successfully

Functional Testing

  • One-time credit pack purchase works
  • Monthly subscription purchase works
  • Yearly subscription purchase works
  • Credits appear after successful payment
  • Subscription management page accessible

Security

  • .env.local is in .gitignore
  • No API keys hardcoded in source code
  • Webhook secret verification configured
Payment Setup (Creem) | Kensa