basalt / subscriptions/src / LemonSqueezyBillingGateway
Class: LemonSqueezyBillingGateway
Defined in: subscriptions/src/drivers/lemonsqueezy.ts:92
Lemon Squeezy billing gateway targeting the REST API directly (JSON:API) — no SDK. Lemon Squeezy is a merchant-of-record and checkout-first, so createCheckoutSession creates a checkout; the durable subscription id arrives on a subscription_* webhook via gatewayRef. createSubscription throws CheckoutRequiredError (use Subscriptions.checkout()). Webhook signatures use the X-Signature scheme (HMAC-SHA256 hex over the raw body).
Implements
Constructors
Constructor
> new LemonSqueezyBillingGateway(options): LemonSqueezyBillingGateway
Defined in: subscriptions/src/drivers/lemonsqueezy.ts:100
Parameters
options
Returns
LemonSqueezyBillingGateway
Properties
name
> readonly name: "lemonsqueezy" = 'lemonsqueezy'
Defined in: subscriptions/src/drivers/lemonsqueezy.ts:93
Implementation of
signatureHeader
> readonly signatureHeader: "x-signature" = 'x-signature'
Defined in: subscriptions/src/drivers/lemonsqueezy.ts:94
Request header(s) carrying this gateway's webhook signature, lower-case (e.g. 'stripe-signature', 'paddle-signature', 'x-signature'). billingWebhookRoute reads the first one present. Omitted: the route falls back to stripe-signature / x-billing-signature.
Implementation of
BillingGateway.signatureHeader
Methods
cancelSubscription()
> cancelSubscription(gatewayRef, _options): Promise<void>
Defined in: subscriptions/src/drivers/lemonsqueezy.ts:140
Parameters
gatewayRef
string
_options
atPeriodEnd
boolean
Returns
Promise<void>
Implementation of
BillingGateway.cancelSubscription
createCheckoutSession()
> createCheckoutSession(input): Promise<{ id: string; url: string; }>
Defined in: subscriptions/src/drivers/lemonsqueezy.ts:118
Hosted Checkout session — returns a URL to redirect the customer to.
Parameters
input
Returns
Promise<{ id: string; url: string; }>
Implementation of
BillingGateway.createCheckoutSession
createPortalSession()
> createPortalSession(input): Promise<{ url: string; }>
Defined in: subscriptions/src/drivers/lemonsqueezy.ts:146
Customer Portal session — returns a URL for self-service billing.
Parameters
input
Returns
Promise<{ url: string; }>
Implementation of
BillingGateway.createPortalSession
createSubscription()
> createSubscription(_input): Promise<{ gatewayRef: string; }>
Defined in: subscriptions/src/drivers/lemonsqueezy.ts:114
Always throws CheckoutRequiredError: a checkout id is not a subscription (returning it as the ref activated the plan unpaid and left a ref cancel/swap could not address).
Parameters
_input
Returns
Promise<{ gatewayRef: string; }>
Implementation of
BillingGateway.createSubscription
resumeSubscription()
> resumeSubscription(gatewayRef): Promise<void>
Defined in: subscriptions/src/drivers/lemonsqueezy.ts:157
Withdraws a cancellation scheduled with cancelSubscription(ref, { atPeriodEnd: true }), so the gateway keeps renewing. Required by Subscriptions.resume() for a gateway-backed subscription.
Parameters
gatewayRef
string
Returns
Promise<void>
Implementation of
BillingGateway.resumeSubscription
swapSubscription()
> swapSubscription(gatewayRef, input): Promise<void>
Defined in: subscriptions/src/drivers/lemonsqueezy.ts:164
Changes the plan on an existing subscription, applying proration.
Parameters
gatewayRef
string
input
Returns
Promise<void>
Implementation of
BillingGateway.swapSubscription
verifyWebhook()
> verifyWebhook(rawBody, signature): WebhookEvent | null
Defined in: subscriptions/src/drivers/lemonsqueezy.ts:179
Verifies the signature and translates the payload. Throws WebhookInvalidError on a bad signature. Returns null for a verified event the gateway doesn't map to a domain event (gateways emit many event types we don't act on).
Parameters
rawBody
string
signature
string | undefined
Returns
WebhookEvent | null