Skip to content
Branko Conjic edited this page Sep 5, 2024 · 7 revisions

getOrder

Retrieves the order with the given ID.

Usage

import { type Order, getOrder } from '@lemonsqueezy/lemonsqueezy.js';

const orderId = 234567;
const { statusCode, error, data } = await getOrder(orderId);

With related resources:

import { type GetOrderParams, type Order, getOrder } from '@lemonsqueezy/lemonsqueezy.js';

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

Type Declarations

/**
 * Retrieve an order.
 *
 * @param orderId The given order id.
 * @param [params] (Optional) Additional parameters.
 * @param [params.include] (Optional) Related resources.
 * @returns An order object.
 */
declare function getOrder(orderId: number | string, params?: GetOrderParams): Promise<FetchResponse<Order>>;

Returns

Returns an Order object.

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

Source

Source ~ Type ~ Test

listOrders

Returns a paginated list of orders.

Usage

import { type ListOrders, listOrders } from '@lemonsqueezy/lemonsqueezy.js';

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

With filter:

import { type ListOrders, type ListOrdersParams, listOrders } from '@lemonsqueezy/lemonsqueezy.js';

const { statusCode, error, data } = await listOrders({ filter: { storeId: 234567 } });

With pagination:

import { type ListOrders, type ListOrdersParams, listOrders } from '@lemonsqueezy/lemonsqueezy.js';

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

With related resources:

import { type ListOrders, type ListOrdersParams, listOrders } from '@lemonsqueezy/lemonsqueezy.js';

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

Type Declarations

/**
 * List all orders.
 *
 * @param [params] (Optional) Additional parameters.
 * @param [params.filter] (Optional) Filter parameters.
 * @param [params.filter.storeId] (Optional) Only return orders belonging to the store with this ID.
 * @param [params.filter.userEmail] (Optional) Only return orders where the `user_email` field is equal to this email address.
 * @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 order objects ordered by `created_at` (descending).
 */
declare function listOrders(params?: ListOrdersParams): Promise<FetchResponse<ListOrders>>;

Returns

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

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

Source

Source ~ Type ~ Test

generateOrderInvoice

Generates a new invoice for the given order with given parameters.

Usage

import { type OrderInvoice, type GenerateOrderInvoiceParams, generateOrderInvoice } from '@lemonsqueezy/lemonsqueezy.js';

const orderId = 12345;
const { statusCode, error, data } = await generateOrderInvoice(orderId);

With optional parameters:

import { type OrderInvoice, type GenerateOrderInvoiceParams, generateOrderInvoice } from '@lemonsqueezy/lemonsqueezy.js';

const orderId = 12345;
const { statusCode, error, data } = await generateOrderInvoice(orderId, {
	name: 'John Doe',
	address: '123 Main St',
	city: 'Anytown',
	state: 'CA',
	country: 'US',
	zipCode: 12345,
	notes: 'Thank you for your business!',
});

Type Declarations

/**
 * Generate order invoice.
 *
 * @param orderId The given order id.
 * @param [params] (Optional) Then given parameters.
 * @param [params.name] (Optional) The full name of the customer.
 * @param [params.address] (Optional) The street address of the customer.
 * @param [params.city] (Optional) The city of the customer.
 * @param [params.state] (Optional) The state of the customer.
 * @param [params.zipCode] (Optional) The ZIP code of the customer.
 * @param [params.country] (Optional) The country of the customer.
 * @param [params.notes] (Optional) Any additional notes to include on the invoice.
 * @returns A link to download the generated invoice.
 */
declare function generateOrderInvoice(orderId: number | string, params?: GenerateOrderInvoiceParams): Promise<FetchResponse<OrderInvoice>>;

Returns

Returns a link to download the generated invoice.

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

Source

Source ~ Type ~ Test

issueOrderRefund

Issues a partial refund for the order with given id and given amount in cents.

Usage

import { issueOrderRefund } from '@lemonsqueezy/lemonsqueezy.js';

const orderId = 12345;
const amount = 100;
const { statusCode, error, data } = await issueOrderRefund(orderId, amount);

Type Declarations

/**
 * Issues a partial refund of the order.
 *
 * @param orderId The order id.
 * @param amount The amount in cents to refund. Must be less than the total amount of the order.
 */
declare function issueOrderRefund(orderId: number | string, amount: number): Promise<FetchResponse<Order>>;

Returns

Returns an Order object.

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

Source

Source ~ Type ~ Test

Clone this wiki locally