Skip to content

Checkouts

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

createCheckout

Create a custom checkout.

Usage

import { type NewCheckout, type Checkout, createCheckout } from '@lemonsqueezy/lemonsqueezy.js';

const storeId = 123456;
const variantId = 234567;
const newCheckout: NewCheckout = {
	productOptions: {
		name: 'New Checkout Test',
		description: 'a new checkout test',
	},
	checkoutOptions: {
		embed: true,
		media: true,
		logo: true,
	},
	checkoutData: {
		email: '[email protected]',
		name: 'Lemon Squeezy Test',
	},
	expiresAt: null,
	preview: true,
	testMode: true,
};
const { statusCode, error, data } = await createCheckout(storeId, variantId, newCheckout);

Type Declarations

/**
 * Create a checkout.
 *
 * @param storeId (Required) The given store id.
 * @param variantId (Required) The given variant id.
 * @param [checkout] (Optional) A new checkout info.
 * @returns A checkout object.
 */
declare function createCheckout(storeId: number | string, variantId: number | string, checkout?: NewCheckout): Promise<FetchResponse<Checkout>>;

Returns

Returns a checkout object.

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

Source

Source ~ Type ~ Test

getCheckout

Retrieves the checkout with the given ID.

Usage

import { type Checkout, getCheckout } from '@lemonsqueezy/lemonsqueezy.js';

const checkoutId = 456789;
const { statusCode, error, data } = await getCheckout(checkoutId);

With related resources:

import { type Checkout, type GetCheckoutParams, getCheckout } from '@lemonsqueezy/lemonsqueezy.js';

const checkoutId = 456789;
const { statusCode, error, data } = await getCheckout(checkoutId, { include: ['store'] });

Type Declarations

/**
 * Retrieve a checkout.
 *
 * @param checkoutId (Required) The checkout id.
 * @param [params] (Optional) Additional parameters.
 * @param [params.include] (Optional) Related resources.
 * @returns A checkout object.
 */
declare function getCheckout(checkoutId: number | string, params?: GetCheckoutParams): Promise<FetchResponse<Checkout>>;

Returns

Returns a checkout object.

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

Source

Source ~ Type ~ Test

listCheckouts

Returns a paginated list of checkouts.

Usage

import { type ListCheckouts, listCheckouts } from '@lemonsqueezy/lemonsqueezy.js';

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

With filter:

import { type ListCheckouts, type ListCheckoutsParams, listCheckouts } from '@lemonsqueezy/lemonsqueezy.js';

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

With pagination:

import { type ListCheckouts, type ListCheckoutsParams, listCheckouts } from '@lemonsqueezy/lemonsqueezy.js';

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

With related resources:

import { type ListCheckouts, type ListCheckoutsParams, listCheckouts } from '@lemonsqueezy/lemonsqueezy.js';

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

Type Declarations

/**
 * List all checkouts.
 *
 * @param [params] (Optional) Additional parameters.
 * @param [params.filter] (Optional) Filter parameters.
 * @param [params.filter.storeId] (Optional) Only return products belonging to the store with this ID.
 * @param [params.filter.variantId] (Optional) Only return products belonging to the variant with this ID.
 * @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 checkout objects ordered by `created_at` (descending).
 */
declare function listCheckouts(params?: ListCheckoutsParams): Promise<FetchResponse<ListCheckouts>>;

Returns

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

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

Source

Source ~ Type ~ Test

Clone this wiki locally