Billing

LemonSqueezy Integration

LemonSqueezy is a simple payment gateway that enables you to accept payments and manage subscriptions with ease. In this guide, you will learn how to integrate LemonSqueezy with staarter.dev and start monetizing your application.

Prerequisites

Before you begin, make sure you have the following:

  • A LemonSqueezy account: You can sign up for a free account on the LemonSqueezy website.
  • At least one product and variant created in your LemonSqueezy account: You can create products and variants in the LemonSqueezy Dashboard.

Creating a Product and Variant in LemonSqueezy

LemonSqueezy Products
LemonSqueezy Products

On the products page in the LemonSqueezy Dashboard, click the "New Product" button to create a new product. Enter the product details, such as name, description, and image. You can also create multiple variants for the product, each with different pricing and billing intervals.

Configure the LemonSqueezy Provider

Locale Pricing

LemonSqueezy only supports one currency at the moment. You can set your store's currency on the settings page.

In packages/config/billing.ts, set all the locales to your store's currency:

export const localeCurrencies: Record<Locale, Currency> = {
  en: "USD",
  de: "USD",
};

Make sure to set currencies to only include your store's currency:

export const currencies = ["USD"] as const;

Webhook Configuration

Creating a Webhook in LemonSqueezy
Creating a Webhook in LemonSqueezy

In the LemonSqueezy Dashboard, go to the webhooks page and click the "Add Webhook" button to create a new webhook. Enter the URL of your application's webhook endpoint (e.g., https://your-app-url/api/webhook/lemonsqueezy) and select the following events:

  • subscription_created
  • subscription_updated
  • subscription_cancelled
  • subscription_resumed
  • subscription_expired
  • subscription_paused
  • subscription_unpaused

Generate a signing secret using the following command:

openssl rand -base64 24

Copy the signing secret, fill it into the LemonSqueezy Dashboard, and add it to your environment variables as LEMONSQUEEZY_WEBHOOK_SECRET.

API Key

In your LemonSqueezy Dashboard, go to the API keys page to obtain your secret API key. Add this key to your environment variables as LEMONSQUEEZY_API_KEY.

Enable LemonSqueezy as the Payment Gateway

In packages/billing/src/providers/index.ts, change the export instruction to include the LemonSqueezy provider:

export { provider, providerId, webhook } from './lemonsqueezy'
Previous
Paddle