Get the api key
After you have created your account for Lemonsqueezy, 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 theSecret key
and the Publishable key
. You will need the Secret key
for the integration to work.
Add environment variables
To use the Lemonsqueezy integration, you need to define the following environment variables to your.env.local
as well as your production environment:
.env.local
In-App Purchases
You can use Lemonsqueezy anywhere in your application by importing alemonsqueezy
object:
page.tsx
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
/api/lemonsqueezy/checkout
endpoint.
apps/web/[locale]/components/payment/price-form.tsx
- Server
apps/web/api/lemonsqueezy/checkout/route.ts
.
Lemonsqueezy allows using the product’s Purchase Link without creating a checkout session through the API.
Webhooks
Create a webhook
To configure a new webhook, go to the Webhooks page in the lemonsqueezy dashboard. Click the Add endpoint button and select at least the following events: For subscriptions:subscription_created
subscription_updated
subscription_cancelled
order_created
Terminal
Webhook Handler
Stripe webhooks are handled in thePOST /webhooks/lemonsqueezy
route in the apps/api
app. This route constructs the event and then switches on the event type to determine how to process the event.
We have implemented the basic structure of the
Webhook
handler for you. You can modify it as needed.