Skip to content

Lemon Squeezy

JetShip offers built-in support for Lemon Squeezy. Follow this guide to properly set up Lemon Squeezy in your project.

Configuration ⚙️

Step 1: Create a Lemon Squeezy Account

If you don't already have a Lemon Squeezy account, you will need to create one. You can refer to the Lemon Squeezy Getting Started Guide for more details on setting up your account.

Step 2: Collect API Keys 🔑

Once your account is set up, you'll need to gather some credentials:

  1. API Keys:

  2. Store ID:

    • In the top right corner of the dashboard, click on the Store tab to find your Store ID.

    • Add it to your .env file:

      bash
      LEMONSQUEEZY_STORE_ID=your_store_id

Creating a New Product in Lemon Squeezy 🛍️

To create a new product in Lemon Squeezy, follow these steps:

  1. Log in to your Lemon Squeezy account.
  2. In the left-hand menu, click on Store > Products.
  3. Click the + New Product button to create a new product.

Product Variants

If you're creating a subscription plan, you may need multiple variants of the same product. For example, if you have a "Pro" plan that is offered with both monthly and annual billing options, you will need to create two variants:

  • Pro Monthly
  • Pro Yearly

For one-time purchase products, you will only need to create one product, as Lemon Squeezy automatically generates a default variant if none are created manually.

Finalizing Product Setup

After filling out the product details, click Publish Product.

Retrieving the "Variant ID"

Once your product is created, you'll need the Variant ID to integrate the product with JetShip:

  • For multiple variants: Go to the product, find the Variants section, and click on the three dots next to the variant you want. Select Copy ID.
  • For single variant products: Click on the three dots next to the product and select Copy Variant ID.

If you need more details regarding how to create product, please refer to add new product in lemonsqueezy

JSON Representation of a Product 📄

Once your product is set up, you’ll need to create a JSON representation for it in JetShip. Below are examples for both one-time purchase products and subscription products.

One-Time Purchase Product Example

json
[
  {
    "name": "One Time Product",
    "description": "This is a one-time product with multiple price variants.",
    "oneoff": true,
    "plans": [
      {
        "name": "Starter",
        "price": 99,
        "discountedPrice": 99,
        "price_id": "xxxx",
        "description": "Basic license",
        "icon": "tabler-rocket",
        "most_popular": false,
        "features": [
          "feature1",
          "feature2",
          "feature3"
        ]
      },
      {
        "name": "Professional",
        "price": 199,
        "discountedPrice": 199,
        "price_id": "xxxx",
        "icon": "tabler-users",
        "most_popular": true,
        "description": "Pro license",
        "features": [
          "feature1",
          "feature2",
          "feature3"
        ]
      }
    ],
    "coupon_id": "I4ODK0MQ"
  }
]

Subscription Product Example

json
[
  {
    "name": "Starter",
    "description": "This is the Chatflow AI Starter plan.",
    "plans": [
      {
        "interval": "yearly",
        "price": 399,
        "discountedPrice": 399,
        "price_id": "xxxxx"
      },
      {
        "interval": "monthly",
        "price": 49,
        "discountedPrice": 49,
        "price_id": "xxxxxx"
      }
    ],
    "features": [
      "10 GB Storage",
      "1 Custom Domain",
      "AI-Powered Chatbot (Basic Features)",
      "Standard Analytics Dashboard",
      "Email Support",
      "Automated Responses"
    ],
    "icon": "tabler-rocket",
    "most_popular": false
  },
  {
    "name": "Professional",
    "description": "This is the professional plan of Chatflow AI.",
    "plans": [
      {
        "interval": "yearly",
        "price": 499,
        "discountedPrice": 499,
        "price_id": "xxxxx"
      },
      {
        "interval": "monthly",
        "price": 99,
        "discountedPrice": 99,
        "price_id": "xxxxxx"
      }
    ],
    "features": [
      "100 GB Storage",
      "5 Custom Domains",
      "AI-Powered Chatbot (Advanced Features)",
      "Advanced Analytics Dashboard",
      "Multilingual Support",
      "Priority Email & Chat Support"
    ],
    "icon": "tabler-users",
    "most_popular": true
  },
  {
    "name": "Enterprise",
    "description": "This is the Enterprise plan of Chatflow AI.",
    "plans": [
      {
        "interval": "yearly",
        "price": 999,
        "discountedPrice": 999,
        "price_id": "xxx"
      },
      {
        "interval": "monthly",
        "price": 299,
        "discountedPrice": 299,
        "price_id": "xxx"
      }
    ],
    "features": [
      "Unlimited Storage",
      "20 Custom Domains",
      "AI-Powered Chatbot (All Features)",
      "Customizable AI Responses",
      "Dedicated Account Manager",
      "24/7 Premium Support"
    ],
    "icon": "tabler-crown",
    "most_popular": false
  }
]

Webhooks in LemonSqueezy

LemonSqueezy provides several webhooks that allow you to listen to different events, making it easy to track and store important purchase information in your database. In our application, we specifically handle two key events:

  • order_created: Triggered when a new order is created.
  • subscription_created: Triggered when a new subscription is created.

The primary goal of handling these webhooks is to keep track of users' purchases, especially since LemonSqueezy does not currently support an email lock feature during checkout. This can present an issue when users change their email addresses during the purchase process.

If a user updates their email address, it can be difficult to match their purchase history to their account. This leads to problems when trying to retrieve order or subscription information for the logged-in user, such as when displaying the user's billing information on a /billing page. Because of the email mismatch, requests to the LemonSqueezy API may fail to return the expected data.

Setting Up Webhooks in LemonSqueezy

If you're using LemonSqueezy as your payment provider, it's crucial to set up webhooks correctly to avoid these issues and ensure proper tracking of user purchases. Below is a step-by-step guide to configuring the necessary webhooks in the LemonSqueezy dashboard:

  1. Log in to LemonSqueezy:

  2. Navigate to Webhook Settings:

    • Once logged in, navigate to the Settings page.
    • From the Settings menu, select Webhooks.
  3. Add a New Webhook:

    • Click on the + (plus) icon to add a new webhook callback URL.
  4. Specify the Callback URL:

    • Add your webhook callback URL in the format:

      bash
      https://your-domain.com/api/webhooks/lemon-squeezy

      Replace your-domain.com with your actual domain name.

  5. Configure the Signing Secret:

    • In your application, set the LEMON_SQUEEZY_SIGNING_SECRET environment variable. This ensures that the webhook requests are secure and properly authenticated.
  6. Enable Webhook Events:

    • At a minimum, enable the following webhook events for tracking user purchases:
      • order_created
      • subscription_created
  7. All Done! 🎉

    • You’ve successfully set up your LemonSqueezy webhook to listen for events related to orders and subscriptions.

Important Notes

💡 Tip: Webhooks will allow you to maintain up-to-date user purchase information even if their email changes. This is important for keeping an accurate purchase history and allowing users to view their billing information without issues.

⚠️ Warning: Always verify that the webhook payloads are authentic using the signing secret to prevent unauthorized or malicious webhook calls to your application.

By following this guide, you can avoid issues related to email mismatches during checkout and ensure your billing page works seamlessly.