opensaas-sh/blog/src/content/docs/guides/payment-integrations/lemon-squeezy.mdx
import addProduct from '@assets/lemon-squeezy/add-product.png'; import addVariant from '@assets/lemon-squeezy/add-variant.png'; import storeId from '@assets/lemon-squeezy/store-id.png'; import subscriptionVariantIds from '@assets/lemon-squeezy/subscription-variant-ids.png'; import variantId from '@assets/lemon-squeezy/variant-id.png'; import ngrok from '@assets/ngrok.png'; import { Image } from 'astro:assets';
First, make sure you've defined your payment processor in src/payment/paymentProcessor.ts, as described in the important first steps.
Next, you'll need to create a Lemon Squeezy account in test mode. You can do that here.
:::tip[Star our Repo on GitHub! 🌟] We've packed in a ton of features and love into this SaaS starter, and offer it all to you for free!
If you're finding this template and its guides useful, consider giving us a star on GitHub :::
Once you've created your account, you'll need to get your test API keys. You can do that by navigating to https://app.lemonsqueezy.com/settings/api and creating a new API key:
+ button..env.server file under LEMONSQUEEZY_API_KEY.To get your store ID, go to the Lemon Squeezy Dashboard and copy the Store ID from the top right corner.
Copy and paste this number in your .env.server file under LEMONSQUEEZY_STORE_ID.
To create a product, go to the test products url https://app.lemonsqueezy.com/products:
+ New Product button and fill in the relevant information for your product.Subscription for a recurring monthly payment product or Single Payment for credits-based product.
<Image src={addProduct} alt="add product" loading="lazy" />Software as a service (SaaS) as the Tax category type.Subscription products, click on add variant under the variants tab. Here you can input the name of the variant (e.g. "Hobby", "Pro"), and that variant's price.
<Image src={addVariant} alt="add variant" loading="lazy" />... menu button and select Copy variant ID
<Image src={variantId} alt="variant id" loading="lazy" />Copy ID for each variant.
<Image src={subscriptionVariantIds} alt="subscription variant ids" loading="lazy" />.env.server file:
PAYMENTS_HOBBY_SUBSCRIPTION_PLAN_ID and PAYMENTS_PRO_SUBSCRIPTION_PLAN_ID.PAYMENTS_CREDITS_10_PLAN_ID.:::note[Naming products differently]
Note that if you change names of your products, you'll need to update your app code in src/payment/plans.ts and src/payment/paymentProcessorPlans.ts to match these names as well.
:::
Lemon Squeezy notifies your Wasp app about customer and payment events through a webhook. However, to make it available to Lemon Squeezy during development, you need to expose your locally running Wasp server (started with wasp start) to the internet.
You can do that by running ngrok on port 3001 (Wasp server runs on port 3001 by default). ngrok will then generate a public URL that we can provide to Lemon Squeezy:
ngrok.ngrok is installed and your Wasp app is running, run:
ngrok http 3001
ngrok will display a forwarding address. Copy this address and append /payments-webhook to it. It should look something like this:
https://89e5-2003-c7-153c-72a5-f837.ngrok-free.app/payments-webhook
Next, go to your Lemon Squeezy Webhooks Dashboard:
+ button.Callback URL section..env.server file under LEMONSQUEEZY_WEBHOOK_SECRET.order_createdsubscription_createdsubscription_updatedsubscription_cancelledsave.You're now ready to start consuming Lemon Squeezy webhook events in local development.