Initial Setup
Payments
LemonSqueezy
Subscriptions

Subscriptions

Set up the API

Go to the lemonsqueezy (opens in a new tab) to create a new key, then save it somewhere in the app, for example in an .env file.

LEMONSQUEEZY_API_KEY=your_api_key

Create a product

Go to the products (opens in a new tab) to create a new product, then save the product variant id somewhere in the app, for example in an .env file.

LEMONS_SQUEEZY_PRODUCT_VARIANT_ID=your_product_id

Now grab the store id from store (opens in a new tab) and save it somewhere in the app, for example in an .env file.

LEMON_SQUEEZY_STORE_ID=your_store_id

Create a webhook

Go to the webhooks (opens in a new tab) to create a new webhook, then save the webhook id somewhere in the app, for example in an .env file.

LEMONSQUEEZY_WEBHOOK_SECRET=your_webhook_id

Create a subscription

Now you can use the below code to create a subscription.

    const handleLemonCheckout = async () => {
        if (!user) return router.push("/sign-in");
        try {
            const response = (await axios.post("/api/lemon")) as {
                data: { url: string };
            };

            window.location.href = response.data.url;
        } catch (err) {
            console.log(err);
        }
    };