This repository has been archived by the owner on Feb 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Discounts
Caven edited this page Jan 31, 2024
·
2 revisions
Create a discount.
import { type NewDiscount, type Discount, createDiscount } from '@heybrostudio/lemonsqueezy.js'
const { statusCode, error, data } = await createDiscount({
name: 'TestDiscount',
amount: 50,
amountType: 'percent',
storeId: 123456,
variantIds: [345678, 456789],
})
/**
* Create a discount.
*
* @param discount New discount info.
* @returns A discount object.
*/
declare function createDiscount(discount: NewDiscount): Promise<FetchResponse<Discount>>
Returns a discount object.
{
statusCode: number | null
error: Error | null
data: Discount | null
}
Delete a discount with the given ID.
import { deleteDiscount } from '@heybrostudio/lemonsqueezy.js'
const discountId = 677889
const { statusCode, error, data } = await deleteDiscount(discountId)
/**
* Delete a discount.
*
* @param discountId The given discount id.
* @returns A `204 No Content` response on success.
*/
declare function deleteDiscount(discountId: string | number): Promise<FetchResponse<null>>
Returns a status code 204
and No Content
response on success.
{
statusCode: number | null
error: Error | null
data: null
}
Retrieves the discount with the given ID.
import { type Discount, getDiscount } from '@heybrostudio/lemonsqueezy.js'
const discountId = 677889
const { statusCode, error, data } = await getDiscount(discountId)
With related resources:
import { type Discount, type GetDiscountParams, getDiscount } from '@heybrostudio/lemonsqueezy.js'
const discountId = 677889
const { statusCode, error, data } = await getDiscount(discountId, { include: ['store'] })
/**
* Retrieve a discount.
*
* @param discountId The given discount id.
* @param [params] (Optional) Additional parameters.
* @param [params.include] (Optional) Related resources.
* @returns A discount object.
*/
declare function getDiscount(discountId: number | string, params?: GetDiscountParams): Promise<FetchResponse<Discount>>
Returns a discount object.
{
statusCode: number | null
error: Error | null
data: Discount | null
}
Returns a paginated list of discounts.
import { type ListDiscounts, listDiscounts } from '@heybrostudio/lemonsqueezy.js'
const { statusCode, error, data } = await listDiscounts()
With filter:
import { type ListDiscounts, type ListDiscountsParams, listDiscounts } from '@heybrostudio/lemonsqueezy.js'
const { statusCode, error, data } = await listDiscounts({ filter: { storeId: 123456 } })
With pagination:
import { type ListDiscounts, type ListDiscountsParams, listDiscounts } from '@heybrostudio/lemonsqueezy.js'
const { statusCode, error, data } = await listDiscounts({ page: { number: 1, size: 10 } })
With related resources:
import { type ListDiscounts, type ListDiscountsParams, listDiscounts } from '@heybrostudio/lemonsqueezy.js'
const { statusCode, error, data } = await listDiscounts({ include: ['store'] })
/**
* List all discounts.
*
* @param [params] (Optional) Additional parameters.
* @param [params.filter] (Optional) Filter parameters.
* @param [params.filter.storeId] (Optional) Only return discounts belonging to the store 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 discount objects ordered by `created_at`.
*/
declare function listDiscounts(params?: ListDiscountsParams): Promise<FetchResponse<ListDiscounts>>
Returns a paginated list of discount objects ordered by created_at
.
{
statusCode: number | null
error: Error | null
data: ListDiscounts | null
}