๐Ÿ’ฐSubscriptions - Lemon Squeezy

Monetize Your Application with Lemon Squeezy

Lemon Squeezy Setup

In this section, you'll configure the payment provider used by your app to allow users to subscribe to a plan and manage their billing settings directly in-app.

First, create an account on Lemon Squeezy.

Get Your API Key

You'll need a Lemon Squeezy API key in order to provide customized, pre-filled checkouts and in-app subscription management to your users.

Navigate to Settings > API in the menu bar and click the "+" button to create a new API Key.

Fill in your Lemon Squeezy API environment variable in the .env file.


Redirect Setup

After your customers subscribe to a plan, you should redirect them back to your app which will show that they are now successfully subscribed to a plan.

To handle the redirect, navigate to Store > Products, and click into the product you've created for your app's subscription. If you haven't created a product yet, you can do so easily by pressing the "+" button.

Lemon Squeezy has recently changed and does not allow you to directly input a redirect URL. This can still be done by specifying a button in the confirmation modal with a link. I would recommend doing something similar to this:

For the demo, our redirect link is https://demo.pysaas.io/dashboard which will take users back to the dashboard where they're still signed in and can see their updated subscription plan status. For now, for testing purposes, you can put http://localhost:3000/dashboard.

Product URL

Retrieve your product URL from Product Details > Share > Checkout Link and include it in .env:


Enable Webhooks

To allow users to manage subscription and billing settings directly in your app, Lemon Squeezy has to be able to send webhooks to the backend API route that processes them, which is included in the PySaaS codebase.

To enable this, navigate to Settings > Webhooks and click the "+" button to create a new webhook. Your URL will eventually correspond to your app's domain similar to the redirect setup, but for now, we'll be sending it to http://localhost:8000/webhooks/lmsqueezy. To do this, quickly set up ngrok in the middle to put localhost on the internet. For events, we'll be listening for "subscription_created" and "subscription_updated".

If you are having trouble setting up ngrok, please visit the ngrok setup page in the troubleshooting section of the documentation here: NGROK Setup

Lastly, when you create your webhook's signing secret fill in the corresponding environment variable value in your .env file.


Last updated