Skip to content

Lemonsqueezy

Introduction

Follow this guide to get set up with LemonSqueezy.

Create LemonSqueezy Account

  1. 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

  1. Create a new API key in the API keys page.
  2. In the .env file of your project, add the key to the LEMON_SQUEEZY_API_KEY variable.

Getting the Store ID

  1. 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:

LEMON_SQUEEZY_STORE_ID=11111

Creating Products and Variants

  1. 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.

  2. 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 and LEMON_SQUEEZY_VARIANT_ID_2 variables in the .env file of your project.

Changing the Project Files

  1. 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):
    // import * as payments from "@/lib/payments/stripe";
    import * as payments from "@/lib/payments/lemonsqueezy";
    Basically, comment out the payments/stripe line and uncomment the payments/lemonsqueezy line.

Creating a Webhook

  1. 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”.
  2. 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.
      Terminal window
      openssl rand -base64 28
    • For What updates should we send?, choose the following events:
      • order_created
      • subscription_cancelled
  3. 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.