LemonSqueezy Configuration
This guide explains how to configure LemonSqueezy as a payment provider in your Ever Works application.
Overviewβ
LemonSqueezy is a merchant of record platform that simplifies:
- π° Global payments with automatic tax compliance
- π Support for 135+ countries
- π Built-in fraud prevention
- π Subscription management
- π³ Multiple payment methods
- π§ Automated email receipts
LemonSqueezy acts as a merchant of record, handling all tax compliance, VAT, and sales tax automatically. This means you don't need to register for tax in different countries.
Required Environment Variablesβ
Add these variables to your .env.local file:
# LemonSqueezy Configuration
LEMONSQUEEZY_API_KEY=your_api_key_here
LEMONSQUEEZY_WEBHOOK_SECRET=your_webhook_secret_here
LEMONSQUEEZY_STORE_ID=your_store_id_here
# Product/Variant IDs (optional)
NEXT_PUBLIC_LEMONSQUEEZY_PRO_VARIANT_ID=variant_id_here
NEXT_PUBLIC_LEMONSQUEEZY_SPONSOR_VARIANT_ID=variant_id_here
LemonSqueezy Dashboard Setupβ
Step 1: Create Your Storeβ
- Sign up at LemonSqueezy
- Create a new store
- Complete your store settings (name, currency, etc.)
- Copy your Store ID from the URL or settings
Step 2: Create Productsβ
- Go to Products β New Product
- Create your pricing tiers:
| Product | Price | Type | Description |
|---|---|---|---|
| Pro Plan | $10/month | Subscription | Advanced features |
| Sponsor Plan | $20 | One-time | Premium support |
- For each product, create Variants with specific pricing
- Copy the Variant ID for each pricing option
Step 3: Get API Keyβ
- Go to Settings β API
- Create a new API key
- Copy the API key (starts with
ls_) - Add it to your
.env.localasLEMONSQUEEZY_API_KEY
Step 4: Configure Webhooksβ
-
Go to Settings β Webhooks
-
Click Create Webhook
-
Configure the webhook:
- URL:
https://yourdomain.com/api/lemonsqueezy/webhook - Events: Select all subscription and order events
- Secret: Generate a secret key
- URL:
-
Copy the Webhook Secret and add it to your
.env.local
Recommended Eventsβ
Select these events in your webhook configuration:
- β
subscription_created- New subscription - β
subscription_updated- Subscription changes - β
subscription_cancelled- Cancellation - β
subscription_payment_success- Successful payment - β
subscription_payment_failed- Failed payment - β
subscription_trial_will_end- Trial ending - β
order_created- One-time purchase - β
order_refunded- Refund processed
Webhook Endpointβ
The webhook is available at: /api/lemonsqueezy/webhook
Supported Events Mappingβ
| LemonSqueezy Event | Internal Event | Description |
|---|---|---|
subscription_created | SUBSCRIPTION_CREATED | New subscription created |
subscription_updated | SUBSCRIPTION_UPDATED | Subscription updated |
subscription_cancelled | SUBSCRIPTION_CANCELLED | Subscription cancelled |
subscription_payment_success | SUBSCRIPTION_PAYMENT_SUCCEEDED | Payment succeeded |
subscription_payment_failed | SUBSCRIPTION_PAYMENT_FAILED | Payment failed |
subscription_trial_will_end | SUBSCRIPTION_TRIAL_ENDING | Trial ending soon |
order_created | PAYMENT_SUCCEEDED | One-time payment |
order_refunded | REFUND_SUCCEEDED | Refund processed |
Implementationβ
Payment System Architectureβ
Featuresβ
Securityβ
- β HMAC signature verification (SHA-256)
- β Webhook secret validation
- β Comprehensive error handling
- β Request logging
Functionalityβ
- β Subscription lifecycle management
- β Automatic payment processing
- β Email notifications
- β Database synchronization
- β Error monitoring
Integration Servicesβ
The webhook integrates with:
WebhookSubscriptionService- Subscription managementPaymentEmailService- Email notifications- Database queries - Data persistence
- Configuration management - Secure settings
Usage Exampleβ
Create a Checkoutβ
import { LemonSqueezyProvider } from '@/lib/payment/providers/lemonsqueezy-provider';
const lsProvider = new LemonSqueezyProvider({
apiKey: process.env.LEMONSQUEEZY_API_KEY!,
storeId: process.env.LEMONSQUEEZY_STORE_ID!,
});
// Create checkout session
const checkout = await lsProvider.createCheckout({
variantId: 'variant_id_here',
customerId: 'customer_id',
redirectUrl: 'https://yoursite.com/success',
});
// Redirect user to checkout.url
Handle Webhook Eventsβ
The webhook automatically handles events. You can customize behavior in:
app/api/lemonsqueezy/webhook/route.ts
Testingβ
Test Modeβ
- LemonSqueezy provides a test mode for development
- Use test API keys (available in dashboard)
- Test webhooks with LemonSqueezy's webhook testing tool
Local Testingβ
# Use a tool like ngrok to expose your local server
ngrok http 3000
# Update webhook URL in LemonSqueezy dashboard
https://your-ngrok-url.ngrok.io/api/lemonsqueezy/webhook
Monitoringβ
All webhook events are logged:
- β
Success:
β LemonSqueezy [event] handled successfully - β Errors:
β Failed to handle [event]: [error details]
Check your application logs for webhook activity.
Troubleshootingβ
Common Issuesβ
Issue: "No signature provided" error
- Solution: Ensure LemonSqueezy is sending the
x-signatureheader - Check webhook configuration in LemonSqueezy dashboard
Issue: "Invalid signature" error
- Solution: Verify
LEMONSQUEEZY_WEBHOOK_SECRETmatches the secret in LemonSqueezy - Ensure webhook URL is correctly configured
Issue: "Missing required LemonSqueezy configuration" error
- Solution: Check all required environment variables are set
- Verify variable names match exactly
Issue: Webhook not receiving events
- Solution: Verify webhook URL is publicly accessible
- Use ngrok for local testing
- Check LemonSqueezy webhook logs
Debug Modeβ
Set NODE_ENV=development to enable test mode for LemonSqueezy operations.
Security Best Practicesβ
- HTTPS Only: Always use HTTPS for webhook endpoints in production
- Secret Rotation: Rotate webhook secrets regularly
- Monitoring: Monitor webhook logs for suspicious activity
- Environment Variables: Never commit secrets to version control
- Rate Limiting: Implement rate limiting for production webhooks
Email Notificationsβ
The webhook automatically sends email notifications for:
- β Payment success confirmations
- β Subscription updates
- β Trial ending reminders
- β Payment failures (logged for monitoring)
Comparison: LemonSqueezy vs Stripeβ
| Feature | LemonSqueezy | Stripe |
|---|---|---|
| Tax Compliance | Automatic (merchant of record) | Manual setup required |
| Setup Complexity | Simple | More complex |
| Transaction Fees | Higher (~5-7%) | Lower (~2.9% + 30Β’) |
| Global Support | 135+ countries | 195+ countries |
| Customization | Limited | Extensive |
| Best For | Quick setup, global sales | High volume, custom flows |
Dependenciesβ
Required packages (already included in Ever Works):
{
"@lemonsqueezy/lemonsqueezy.js": "^3.0.0"
}
Next Stepsβ
- Stripe Configuration - Alternative payment provider
- Payment Overview - Compare payment providers
- Environment Variables - Complete environment setup
- Deployment - Deploy your payment integration
Resourcesβ
Supportβ
Need help with LemonSqueezy integration? Check our support page or join our community.