> ## Documentation Index
> Fetch the complete documentation index at: https://docs.creem.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Test Mode

> Develop and test your integration safely without processing real payments or affecting production data

Test Mode allows you to build and test your Creem integration in a completely isolated environment. All API calls, payments, webhooks, and data are kept separate from your production environment, ensuring you can develop with confidence.

> [!TIP]
>
> Always develop and test your integration in Test Mode before going live. This prevents accidental
> charges and allows you to verify your entire payment flow safely.

## Activating Test Mode

To switch to the test environment, click the **Test Mode** toggle at the bottom of the left sidebar.

![](https://nucn5fajkcc6sgrd.public.blob.vercel-storage.com/test-mode-BMpcC8LrMTvzYQerR0pSe55z3gWLD3)

## Using Test Mode in Code

When building your integration, you'll need to configure your code to use Test Mode. Here's how to do it across different SDKs:

> [tab] Next.js
>
> Use the `testMode` parameter when creating checkouts:
>
> ```typescript theme={null}
> // app/api/checkout/route.ts
> import { Checkout } from "@creem_io/nextjs";
>
> export const GET = Checkout({
>   apiKey: process.env.CREEM_API_KEY!,
>   testMode: true, // Enable test mode
>   defaultSuccessUrl: "/success",
> });
> ```
>
> For production, use an environment variable:
>
> ```typescript theme={null}
> export const GET = Checkout({
>   apiKey: process.env.CREEM_API_KEY!,
>   testMode: process.env.NODE_ENV !== "production",
>   defaultSuccessUrl: "/success",
> });
> ```

> [tab] TypeScript SDK
>
> Enable test mode when initializing the SDK:
>
> ```typescript theme={null}
> import { Creem } from "creem";
>
> const creem = new Creem({
>   apiKey: process.env.CREEM_API_KEY!,
>   server: "test", // Enable test mode
> });
>
> const checkout = await creem.checkouts.create({
>   productId: "prod_abc123",
>   successUrl: "https://yoursite.com/success",
> });
> ```
>
> For production, omit `server`; production is the default:
>
> ```typescript theme={null}
> const creem = new Creem({
>   apiKey: process.env.CREEM_API_KEY!,
> });
> ```

> [tab] Better Auth
>
> Configure test mode in your auth setup:
>
> ```typescript theme={null}
> // auth.ts
> import { betterAuth } from "better-auth";
> import { creem } from "@creem_io/better-auth";
>
> export const auth = betterAuth({
>   database: {
>     // your database config
>   },
>   plugins: [
>     creem({
>       apiKey: process.env.CREEM_API_KEY!,
>       testMode: true, // Enable test mode
>     }),
>   ],
> });
> ```

> [tab] REST API
>
> When using the REST API directly, use the test API endpoint:
>
> ```bash theme={null}
> # Test Mode
> curl -X POST https://test-api.creem.io/v1/checkouts \
>   -H "x-api-key: YOUR_TEST_API_KEY" \
>   -H "Content-Type: application/json" \
>   -d '{
>     "product_id": "prod_YOUR_PRODUCT_ID",
>     "success_url": "https://yoursite.com/success"
>   }'
> ```
>
> ```bash theme={null}
> # Production Mode
> curl -X POST https://api.creem.io/v1/checkouts \
>   -H "x-api-key: YOUR_PRODUCTION_API_KEY" \
>   -H "Content-Type: application/json" \
>   -d '{
>     "product_id": "prod_YOUR_PRODUCT_ID",
>     "success_url": "https://yoursite.com/success"
>   }'
> ```

## API Endpoints

Creem uses separate API endpoints for test and production environments:

| Environment | Base URL |
| - | - |
| Production | `https://api.creem.io` |
| Test Mode | `https://test-api.creem.io` |

> [!WARNING]
>
> Make sure to use the correct API endpoint for your environment. Using the production endpoint with
> test mode enabled (or vice versa) will result in errors.

## API Keys

Test and production environments use different API keys. You can find both keys in the [Developers section](https://creem.io/dashboard/developers). Make sure to toggle Test Mode in the bottom of the left sidebar.

> [!TIP]
>
> Store your API keys as environment variables and never commit them to version control.

```bash theme={null}
# .env.local
CREEM_API_KEY=your_test_api_key_here
```

## Testing Payments

Use these test card numbers to simulate different payment scenarios:

> [!NOTE]
>
> All test card numbers work with any future expiration date, any CVV, and any billing information.

| Card Number | Behavior |
| - | - |
| `4111 1111 1111 1111` | Successful payment |
| `4507 9900 0000 0028` | Card declined |
| `4507 9900 0000 0010` | Insufficient funds |
| `4507 9900 0000 0044` | Incorrect CVC |

## Webhook Testing

When in Test Mode, webhook events are sent to your test webhook URL. This allows you to:

1. Test your webhook endpoint locally using tools like [ngrok](https://ngrok.com)
2. Verify webhook signature validation
3. Ensure your event handlers work correctly

If you want a more in-depth explanation about webhooks, check the guide below:

> [card] [Learn More About Webhooks](https://docs.creem.io/code/webhooks.md)
>
> Set up webhooks to receive real-time payment notifications.

## Switching to Production

When you're ready to go live:

**1. Complete Testing**

Verify all payment flows work correctly in Test Mode

**2. Update API Keys**

Replace test API keys with production API keys in your environment variables

**3. Update API Endpoint**

Ensure direct API calls use `https://api.creem.io`. The TypeScript SDK uses production by
default when `server` is omitted.

**4. Configure Production Webhooks**

Register your production webhook URL in the live dashboard

**5. Create Production Products**

Switch to production mode in the dashboard and create your live products

**6. Monitor First Transactions**

Watch your first few production transactions carefully to ensure everything works as expected

> [!WARNING]
>
> Never use test API keys or the test API endpoint in production. This will cause all payments to
> fail.

## Next Steps

> [card] [Checkout](https://docs.creem.io/features/checkout/checkout-link.md)
>
> Learn how to create checkout sessions and payment links

> [card] [One-Time Payments](https://docs.creem.io/features/one-time-payment.md)
>
> Accept single payments for products and services

> [card] [Subscriptions](https://docs.creem.io/features/subscriptions/introduction.md)
>
> Set up recurring billing and subscription management

> [card] [Webhooks](https://docs.creem.io/code/webhooks.md)
>
> Set up webhooks to receive real-time payment notifications


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.