Skip to content

Subscriptions

Branko Conjic edited this page Feb 8, 2024 · 2 revisions

updateSubscription

Update an existing subscription to specific parameters.

Usage

import { type UpdateSubscription, updateSubscription } from '@lemonsqueezy/lemonsqueezy.js';

const subscriptionId = 234567;
const { statusCode, error, data } = await updateSubscription(subscriptionId, { cancelled: true });

Type Declarations

/**
 * Update a subscription.
 *
 * @param subscriptionId The given subscription id.
 * @param subscription Subscription information that needs to be updated.
 * @returns A subscription object.
 */
declare function updateSubscription(subscriptionId: string | number, updateSubscription: UpdateSubscription): Promise<FetchResponse<Subscription>>;

Returns

Returns a subscription object.

{
	statusCode: number | null;
	error: Error | null;
	data: Subscription | null;
}

Source

Source ~ Type ~ Test

cancelSubscription

Cancel an active subscription

Usage

import { type Subscription, cancelSubscription } from '@lemonsqueezy/lemonsqueezy.js';

const subscriptionId = 234567;
const { statusCode, error, data } = await cancelSubscription(subscriptionId);

Type Declarations

/**
 * Cancel a subscription.
 *
 * @param subscriptionId The given subscription id
 * @returns The Subscription object in a cancelled state.
 */
declare function cancelSubscription(subscriptionId: string | number): Promise<FetchResponse<Subscription>>;

Returns

Returns the Subscription object in a cancelled state.

{
	statusCode: number | null;
	error: Error | null;
	data: Subscription | null;
}

Source

Source ~ Type ~ Test

getSubscription

Retrieves the subscription with the given ID.

Usage

import { type Subscription, getSubscription } from '@lemonsqueezy/lemonsqueezy.js';

const subscriptionId = 234567;
const { statusCode, error, data } = await getSubscription(subscriptionId);

With related resources:

import { type Subscription, type GetSubscriptionParams, getSubscription } from '@lemonsqueezy/lemonsqueezy.js';

const subscriptionId = 234567;
const { statusCode, error, data } = await getSubscription(subscriptionId, { include: ['order'] });

Type Declarations

/**
 * Retrieve a subscription.
 *
 * @param subscriptionId The given subscription id.
 * @param [params] (Optional) Additional parameters.
 * @param [params.include] (Optional) Related resources.
 * @returns A subscription object.
 */
declare function getSubscription(subscriptionId: number | string, params?: GetSubscriptionParams): Promise<FetchResponse<Subscription>>;

Returns

Returns a subscription object.

{
	statusCode: number | null;
	error: Error | null;
	data: Subscription | null;
}

Source

Source ~ Type ~ Test

listSubscriptions

Returns a paginated list of subscriptions.

Usage

import { type ListSubscriptions, listSubscriptions } from '@lemonsqueezy/lemonsqueezy.js';

const { statusCode, error, data } = await listSubscriptions();

With filter:

import { type ListSubscriptions, type ListSubscriptionsParams, listSubscriptions } from '@lemonsqueezy/lemonsqueezy.js';

const { statusCode, error, data } = await listSubscriptions({ filter: { storeId: 123456 } });

With pagination:

import { type ListSubscriptions, type ListSubscriptionsParams, listSubscriptions } from '@lemonsqueezy/lemonsqueezy.js';

const { statusCode, error, data } = await listSubscriptions({ page: { number: 1, size: 10 } });

With related resources:

import { type ListSubscriptions, type ListSubscriptionsParams, listSubscriptions } from '@lemonsqueezy/lemonsqueezy.js';

const { statusCode, error, data } = await listSubscriptions({ include: ['order'] });

Type Declarations

/**
 * List all subscriptions.
 *
 * @param [params] (Optional) Additional parameters.
 * @param [params.filter.storeId] (Optional) Only return subscriptions belonging to the store with this ID.
 * @param [params.filter.orderId] (Optional) Only return subscriptions belonging to the order with this ID.
 * @param [params.filter.orderItemId] (Optional) Only return subscriptions belonging to the order item with this ID.
 * @param [params.filter.productId] (Optional) Only return subscriptions belonging to the product with this ID.
 * @param [params.filter.variantId] (Optional) Only return subscriptions belonging to the variant with this ID.
 * @param [params.filter.userEmail] (Optional) Only return subscriptions where the `user_email` field is equal to this email address.
 * @param [params.filter.status] (Optional) Only return subscriptions with this status.
 * @param [params.page] (Optional) Custom paginated queries.
 * @param [params.page.number] (Optional) The parameter determine which page to retrieve.
 * @param [params.page.size] (Optional) The parameter to determine how many results to return per page.
 * @param [params.include] (Optional) Related resources.
 * @returns A paginated list of subscription objects ordered by `created_at` (descending).
 */
declare function listSubscriptions(params?: ListSubscriptionsParams): Promise<FetchResponse<ListSubscriptions>>;

Returns

Returns a paginated list of subscription objects ordered by created_at (descending).

{
	statusCode: number | null;
	error: Error | null;
	data: ListSubscriptions | null;
}

Source

Source ~ Type ~ Test

Clone this wiki locally