LemonSqueezy Integration
Learn how to set up LemonSqueezy payments in your Indie Kit application
LemonSqueezy Integration π
Let's set up LemonSqueezy payments for your Indie Kit application! π
Initial Setup β‘
-
Create a LemonSqueezy account
-
Set up your store details
-
Add these environment variables to your
.env
file:# LemonSqueezy Configuration LEMON_SQUEEZY_API_KEY=your-api-key LEMON_SQUEEZY_STORE_ID=your-store-id LEMON_SQUEEZY_WEBHOOK_SECRET=your-webhook-secret
π Security Note: Never commit these keys to your repository. In production, add them securely to your hosting platform's environment variables.
Product Configuration ποΈ
In your LemonSqueezy Dashboard:
-
Create Products with variants:
- Monthly subscriptions
- Yearly subscriptions
- One-time payments
-
For each product:
- Set up pricing
- Configure billing cycles
- Add product descriptions
- Set up trial periods (if needed)
Webhook Setup π
-
Add your webhook endpoint in LemonSqueezy Dashboard:
https://your-domain.com/api/webhooks/lemonsqueezy
-
Enable these webhook events:
subscription_created
subscription_updated
subscription_cancelled
subscription_resumed
order_created
Plan Mapping πΊοΈ
- Go to your super admin dashboard:
/super-admin/plans
- For each plan, add the corresponding LemonSqueezy Product IDs:
monthlyLemonSqueezyProductId
yearlyLemonSqueezyProductId
onetimeLemonSqueezyProductId
π‘ Tip: Find Product IDs in LemonSqueezy Dashboard under Products β Select Product β Variants
Adding Subscribe Buttons π
Use the getSubscribeUrl
helper to create subscription links:
import getSubscribeUrl, { PlanType, PlanProvider } from '@/lib/plans/getSubscribeUrl'
function PricingCard({ plan }) {
// Monthly subscription with 7-day trial
const monthlyUrl = getSubscribeUrl({
codename: plan.codename,
type: PlanType.MONTHLY,
provider: PlanProvider.LEMON_SQUEEZY,
trialPeriodDays: 7
})
// Yearly subscription with 14-day trial
const yearlyUrl = getSubscribeUrl({
codename: plan.codename,
type: PlanType.YEARLY,
provider: PlanProvider.LEMON_SQUEEZY,
trialPeriodDays: 14
})
// One-time payment
const onetimeUrl = getSubscribeUrl({
codename: plan.codename,
type: PlanType.ONETIME,
provider: PlanProvider.LEMON_SQUEEZY
})
return (
<div className="pricing-card">
<h2>{plan.name}</h2>
<div className="buttons">
{plan.hasMonthlyPricing && (
<Link href={monthlyUrl}>
<Button>Subscribe Monthly</Button>
</Link>
)}
{plan.hasYearlyPricing && (
<Link href={yearlyUrl}>
<Button>Subscribe Yearly</Button>
</Link>
)}
{plan.hasOnetimePricing && (
<Link href={onetimeUrl}>
<Button>Buy Lifetime</Button>
</Link>
)}
</div>
</div>
)
}
Features Available π―
- π Automatic plan upgrades/downgrades
- π³ LemonSqueezy-managed billing
- πͺ Customer portal access
- β‘ Webhook handling
- π Payment tracking
- π Usage monitoring
Best Practices π‘
-
Testing
- Use test mode in LemonSqueezy
- Test all subscription flows
- Verify webhook events
- Test upgrade/downgrade paths
-
Production
- Configure proper webhook security
- Monitor webhook events
- Set up email notifications
- Keep product IDs in sync
-
Customer Experience
- Clear pricing information
- Smooth checkout flow
- Easy access to billing portal
- Clear trial period information
Advantages of LemonSqueezy π
- Simple setup process
- Built-in EU VAT handling
- Modern checkout experience
- Lower transaction fees
- Excellent developer experience
- Quick payouts
Now your Indie Kit application is ready to accept payments and manage subscriptions through LemonSqueezy! π