Skip to content

lmsqueezy/lemonsqueezy.js

Repository files navigation

The official Lemon Squeezy JavaScript SDK

NPM version Functions usage APIs Count Weekly downloads NPM Downloads FOSSA Status

Introduction

This is the official JavaScript SDK for Lemon Squeezy, making it easy to incorporate billing into your JavaScript application.

Features

Installation

Install the package

# bun
bun install @lemonsqueezy/lemonsqueezy.js
# pnpm
pnpm install @lemonsqueezy/lemonsqueezy.js
# npm
npm install @lemonsqueezy/lemonsqueezy.js

Create an API key

Create a new API key from Settings > API in your Lemon Squeezy dashboard.

Add this API key into your project, for example as LEMONSQUEEZY_API_KEY in your .env file.

Caution

Do not use this package directly in the browser, as this will expose your API key. This would give anyone full API access to your Lemon Squeezy account and store(s). For more information see here.

Using the API in test mode

You can build and test a full API integration with Lemon Squeezy using Test Mode.

Any API keys created in test mode will interact with your test mode store data.

When you are ready to go live with your integration, make sure to create an API key in live mode and use that in your production application.

Usage

import {
  getAuthenticatedUser,
  lemonSqueezySetup,
} from "@lemonsqueezy/lemonsqueezy.js";

const apiKey = import.meta.env.LEMON_SQUEEZY_API_KEY;

lemonSqueezySetup({
  apiKey,
  onError: (error) => console.error("Error!", error),
});

const { data, error } = await getAuthenticatedUser();

if (error) {
  console.log(error.message);
} else {
  console.log(data);
}

For more functions usage, see Wiki.

Bundle size

Click to view
Export min+brotli
createDiscount 1.01 kB
createCheckout 888 B
updateSubscriptionItem 856 B
updateSubscription 838 B
listCheckouts 824 B
listDiscountRedemptions 819 B
listLicenseKeyInstances 818 B
listSubscriptionInvoices 816 B
listLicenseKeys 815 B
listOrderItems 815 B
listSubscriptionItems 815 B
listUsageRecords 814 B
listSubscriptions 812 B
listWebhooks 812 B
listCustomers 811 B
listDiscounts 811 B
listFiles 811 B
listOrders 811 B
listPrices 811 B
listProducts 811 B
listStores 811 B
listVariants 811 B
updateLicenseKey 811 B
createWebhook 806 B
issueSubscriptionInvoiceRefund 796 B
issueOrderRefund 795 B
updateWebhook 792 B
generateSubscriptionInvoice 787 B
generateOrderInvoice 785 B
validateLicense 761 B
activateLicense 760 B
deactivateLicense 759 B
createUsageRecord 724 B
getDiscountRedemption 702 B
getLicenseKeyInstance 702 B
getSubscriptionInvoice 699 B
getSubscriptionItem 698 B
getUsageRecord 698 B
getOrderItem 697 B
getWebhook 697 B
getLicenseKey 695 B
getCheckout 694 B
getStore 694 B
getSubscription 694 B
getCustomer 692 B
getFile 692 B
getOrder 692 B
getPrice 692 B
getDiscount 691 B
getProduct 691 B
archiveCustomer 690 B
getVariant 690 B
createCustomer 686 B
updateCustomer 682 B
deleteWebhook 660 B
cancelSubscription 658 B
deleteDiscount 656 B
getSubscriptionItemCurrentUsage 650 B
getAuthenticatedUser 595 B
lemonSqueezySetup 106 B

Contributing

See the Contributing Guide.

License

FOSSA Status