Lemonsqueezy
Introduction
Follow this guide to get set up with LemonSqueezy.
Create LemonSqueezy Account
- First, create a LemonSqueezy account if you don’t have one already. Follow the onboarding instructions to set up your LemonSqueezy account.
Getting the API Key
- Create a new API key in the API keys page.
- In the
.env
file of your project, add the key to theLEMON_SQUEEZY_API_KEY
variable.
Getting the Store ID
- Get the Store ID in the Stores Settings page. Copy the number without the # sign, and paste it into
LEMON_SQUEEZY_STORE_ID
in.env
.
For example, if your store ID is #11111, it should look like:
Creating Products and Variants
-
For your user to choose between different subscription plans, you will need to create a Product first on the Products page. Click ”+ New Product” and go down to the Variants section. Here, you will add a variant for each subscription plan you want to offer. For example, if you have a $9/month plan and a $29/month plan, you will be adding 2 variants, one for each plan.
-
After you filled out the details and saved the product, click on the Product, go to the Variants section, copy the IDs for each variant, and paste them into the
LEMON_SQUEEZY_VARIANT_ID_1
andLEMON_SQUEEZY_VARIANT_ID_2
variables in the.env
file of your project.
Changing the Project Files
- In your RyzeKit project, go to
/src/lib/payments/handler.ts
and make the following change at the top of the file (in the imports section): Basically, comment out the payments/stripe line and uncomment the payments/lemonsqueezy line.
Creating a Webhook
- To update the current subscription status of a user and other information in your database, you will need to set up a LemonSqueezy webhook. First, go to the Webhooks page and click ”+ Add endpoint”.
- Next, fill in the details to create the webhook endpoint.
- For Callback URL, be sure to add
/api/webhook
to the end of your website name.- for example: www.myapp.com/api/webhook
- If you are using localhost, you can use a tunneling tool like Tunnelmole or ngrok to expose your local server to the internet. Just be sure to add
/api/webhook
at the end of your tunneled URL.
- For Signing secret, input a random string. Then, copy and paste this string into
LEMON_SQUEEZY_WEBHOOK_SIGNATURE
in the.env
file of your project.- You can generate a random string by running the following command in your terminal.
- For What updates should we send?, choose the following events:
order_created
subscription_cancelled
- For Callback URL, be sure to add
- If you are in test mode, you can try purchasing the product or subscription plan with a test payment method. In the webhook page, you will then be able to see whether the webhook was configured successfully.
Making a Paid Feature
You can make features, content, or pages accessible only to paid subscribers & members by using the isSubscribed()
function found in /src/lib/payments/handler.ts
. An example can be found in /src/pages/protected/paid-content.astro
, which is the file for the /protected/paid-content
route.
Next Steps
🚀 Congratulations, you’ve successfully set up payments! Proceed to the next page to continue with setup.