Payment provider of choice
Cascade uses Lemon Squeezy as the merchant of record. Lemon Squeezy is a payment gateway that allows you to accept payments from your customers. It is a secure and reliable payment gateway that supports multiple payment methods. It also handles all tax related things for you.Setup on Lemon Squeezy side
Make sure you are doing all of the below in test mode. You can switch between
test and live in the Lemon Squeezy dashboard.


New Product
button.
Choose Subscription and select $9.99 as the price for collection every month.

Yearly
& Monthly
and set the price to 9 & 100 respectively.



Name your API key corresponding to your store so you could rotate it later if needed.
Setup on Cascade side
Now that you have your store ID and API key, you can set up Cascade to use Lemon Squeezy as the payment provider. Inside of.env
file add the following:
We are using local tunnel for webhook URL, you should replace cascade with
your app name and generate correct connection in the next step.
http://localhost:3000/ls-setup
Make sure you are signed in and your user has
SUPER_ADMIN
role.
npx localtunnel --port 3000 --subdomain cascade
with replacing cascade with your domain. This will make sure we are able to receive webhooks from Lemon Squeezy locally.
You can now click two buttons to create a webhook and create plans in our database that correspond to Lemon Squeezy subsriptions.
Create webhook
button will create a webhook on Lemon Squeezy side, so we can receive events. This is just a nice utility to setup webhooks without going to Lemon Squeezy dashboard.Sync plans
button will create plans in our database that correspond to Lemon Squeezy subscriptions. This is needed so we can match Lemon Squeezy events to our plans.
Working with payment utilities
To make sure we incentivise our users to subscribe to paid plans we sometimes need to block them from using our app. We can do this by using payment utilities.useGuardedSpendCredits
hook will check if the user has enough credits to spend on the given feature. You need to ensure that you Prisma schema has a field for each feature you want to block.
buttonClicks
field to your Plan
schema & reflect it in your FeatureUsage
schema.
When you create plans automatically with
syncPlansFromLemonsqueezyVariants
using this guide you need to
manually input the limits for the features in your Database.FeatureUsage
model in database. This model will be used to track the usage of each feature for each user. Extent it when needed.