-
Notifications
You must be signed in to change notification settings - Fork 26
Subscriptions
Branko Conjic edited this page Feb 8, 2024
·
2 revisions
Update an existing subscription to specific parameters.
import { type UpdateSubscription, updateSubscription } from '@lemonsqueezy/lemonsqueezy.js';
const subscriptionId = 234567;
const { statusCode, error, data } = await updateSubscription(subscriptionId, { cancelled: true });
/**
* 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 a subscription object.
{
statusCode: number | null;
error: Error | null;
data: Subscription | null;
}
Cancel an active subscription
import { type Subscription, cancelSubscription } from '@lemonsqueezy/lemonsqueezy.js';
const subscriptionId = 234567;
const { statusCode, error, data } = await cancelSubscription(subscriptionId);
/**
* 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 the Subscription object in a cancelled state.
{
statusCode: number | null;
error: Error | null;
data: Subscription | null;
}
Retrieves the subscription with the given ID.
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'] });
/**
* 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 a subscription object.
{
statusCode: number | null;
error: Error | null;
data: Subscription | null;
}
Returns a paginated list of subscriptions.
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'] });
/**
* 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 a paginated list of subscription objects ordered by created_at
(descending).
{
statusCode: number | null;
error: Error | null;
data: ListSubscriptions | null;
}