ESC
NextStarterAI logo
Menu
On this page

Features > Payment Setup > Lemon Squeezy

Setup


1. Create a new account on Lemon Squeezy and activate payments


2. In your [Settings] > [General], add required fields like url, app name, logo support email etc.


3. In your [Settings] > [General], turn Tax-inclusive pricing on if you are going to include tax in your final prices.


4. In your [Settings] > [Domains], add your domain if you are going to custom domain for checkout page.


5. Turn ON Test Mode


6. Create a new product and copy the variant ID (123456) in config.lemonsqueezy.plans[0].variantId in the config.ts file.


7. In your [Settings] > [Stores], copy your store id and add it to LEMONSQUEEZY_STORE_ID in .env.local


8. In your [Settings] > [API], create and copy your API key and add it to LEMONSQUEEZY_API_KEY in .env.local


9. To set up the webhook locally, Lemon Squeezy should be able to call your local endpoint somehow. We are going to use ngrok for that purpose. Sign up to ngrok and get your Authtoken from this page.
Run following commands to make your service publicly available:

1brew install ngrok/ngrok/ngrok 2ngrok config add-authtoken [USE YOUR AUTH TOKEN] 3ngrok http 3000
Copy Public URL from the output. We are going to use it in the next step.


10. To set up the webhook locally, follow the steps in [Settings] > [Webhooks]. Create a webhook and set a signing secret. Copy the signing secret and add it to LEMONSQUEEZY_WEBHOOK_SECRET in .env.local
Set Callback URL as following:
https://[USE YOUR PUBLIC URL].ngrok-free.app/api/webhook/lemonsqueezy
Turn following updates on:
order_created, subscription_updated, subscription_cancelled, subscription_payment_success


Ready for production?

1. Turn OFF Test Mode in your Lemon Squeezy Dashboard
2. In your [Settings] > [API], copy your API Key and add it to LEMONSQUEEZY_API_KEY in your production environment variables.
3. In your [Settings] > [Webhooks]. Set your domain + /api/webhook/lemonsqueezy. Selectorder_created, subscription_updated, subscription_cancelled, subscription_payment_success events (or more if needed). Copy the signing secret and add it toLEMONSQUEEZY_WEBHOOK_SECRET in your production environment variables.

Create a Checkout


From the front-end, use the ButtonCheckout to automatically create a checkout session (one-time payment or subscription)


Webhooks & subscription handling


Our API listens to Lemon Squeezy selected webhooks events & update the user accordingly. It adds credits to credits column of user record on users table. You can add your own business logic to the/api/webhook/lemonsqueezy API endpoint (add credits to a user, send email with a paid e-book etc.)