Skip to content

Setup LemonSqueezy

Prerequisites

  1. Create a Lemon Squeezy account and a Store.

Setup

The LemonSqueezy integration has three main components:

  1. Creating a product and variants
  2. Setting up a webhook
  3. Enable API

At the end of the setup you should fill the .env file like this:

KEY_LEMON_SQUEEZY_API=XXXXX
KEY_LEMON_SQUEEZY_STORE_ID=1234
KEY_LEMON_SQUEEZY_PRODUCT_ID=4321

You should be able to add the KEY_LEMON_SQUEEZY_STORE_ID. You can find it at https://app.lemonsqueezy.com/settings/stores next to the store URL (copy the ID without the hash!)

Creating a product

A product in LemonSqueezy can be a single payment option or a subscription with variants (e.g weekly, monthly, etc..).

  1. Go to https://app.lemonsqueezy.com/products

  2. New product

  3. Fill the name and description

  4. Select pricing model (single or subscription)

  5. If you select subscription:

    1. Skip the pricing section for now.
    2. Under “Variants” click “Add Variant”
    3. Define your variant name and price (e.g Weekly)
    4. Save and add other variatns if you want
  6. If you select single payment. Fill the pricing info.

  7. Ignore the rest of options and save the product.

  8. Copy the product ID (dropdown menu) and save it in your .env file.

Setting up a WebHook

  1. Go to https://app.lemonsqueezy.com/settings/webhooks

  2. Click the ’+’ button

  3. Use your deployed Firebase Function URL

    https://LOCATION-PROJECTID.cloudfunctions.net/api/v1/payment/event/ls
  4. You can define a secret and check it matches in the function (ignored by default)

  5. Select the event types based on your product type:

    1. order_created (mandatory)
    2. subscription_created
    3. subscription_updated
    4. subscription_payment_succeeded
  6. Save webhook.

Setting up LemonSqueezy API

Go to https://app.lemonsqueezy.com/settings/api and create an API key. Then save it to the .env file.

After that you can deploy the Firebase functions with the new credentials and automatically fill the Firestore payments collection by calling the items_updated event:

Terminal window
curl -XPOST -H "Content-type: application/json" \
-d '{ "meta": { "event_name": "items_updated"}}' \
'https://LOCATION-PROJECTID.cloudfunctions.net/api/v1/payment/event/ls'