Introduction

OverviewPhilosophyStructureUpdatesFAQ

Usage

Other

Switch to Lemon Squeezy

How to change the default payment processor to Lemon Squeezy.

Lemon Squeezy is an all-in-one platform for running your SaaS business. It handles payments, subscriptions, global tax compliance, fraud prevention, multi-currency, and more. Here's how to switch the default payment processor from Stripe to Lemon Squeezy.

Lemon Squeezy was acquired by Stripe in July 2024. New signups are being transitioned to Stripe Managed Payments. If you're starting a new project, consider using Stripe directly. Existing Lemon Squeezy integrations continue to work.

1. Swap out the required dependencies

First, uninstall the existing dependencies from the Payments package...

npm uninstall stripe --filter @repo/payments

... and install the new dependencies...

npm install @lemonsqueezy/lemonsqueezy.js --filter @repo/payments

2. Update the environment variables

Next, update the environment variables across the project, for example:

apps/app/.env
LEMON_SQUEEZY_API_KEY=""

Additionally, replace all instances of STRIPE_SECRET_KEY with LEMON_SQUEEZY_API_KEY in the packages/env/index.ts file.

The API key should be a server-side environment variable (without the NEXT_PUBLIC_ prefix), as it should not be exposed to the client.

3. Update the payments client

Initialize the payments client in the packages/payments/index.ts file with the new API key. Then, export the lemonSqueezySetup function from the file.

packages/payments/index.ts
import { env } from '@repo/env';
import { lemonSqueezySetup } from '@lemonsqueezy/lemonsqueezy.js';

lemonSqueezySetup({
  apiKey: env.LEMON_SQUEEZY_API_KEY,
  onError: (error) => console.error("Error!", error),
});

export * from '@lemonsqueezy/lemonsqueezy.js';

4. Update the payments webhook handler

Update the webhook handler for Lemon Squeezy:

apps/api/app/webhooks/payments/route.ts
import { NextResponse } from 'next/server';

export const POST = async (request: Request) => {
  return NextResponse.json({ message: 'Hello World' });
};

There's quite a lot you can do with Lemon Squeezy, so check out the following resources for more information:

5. Use Lemon Squeezy in your app

Finally, use the new payments client in your app.

apps/app/app/(authenticated)/page.tsx
import { getStore } from '@repo/payments';

const Page = async () => {
  const store = await getStore(123456);

  return (
    <pre>{JSON.stringify(store, null, 2)}</pre>
  );
};