DiscountsAPI
The API for interacting with discounts.
Anchor to standardapiStandardApi
The base API object provided to purchase
extension targets.
- Anchor to discountAllocationsdiscountAllocationsStatefulRemoteSubscribable<[]>required
Discounts that have been applied to the entire cart.
- Anchor to discountCodesdiscountCodesStatefulRemoteSubscribable<[]>required
A list of discount codes currently applied to the checkout.
Docs_Standard_DiscountsApi
- discountAllocations
Discounts that have been applied to the entire cart.
StatefulRemoteSubscribable<CartDiscountAllocation[]>
- discountCodes
A list of discount codes currently applied to the checkout.
StatefulRemoteSubscribable<CartDiscountCode[]>
export interface Docs_Standard_DiscountsApi
extends Pick<StandardApi, 'discountAllocations' | 'discountCodes'> {}
CartDiscountAllocation
CartCodeDiscountAllocation | CartAutomaticDiscountAllocation | CartCustomDiscountAllocation
CartCodeDiscountAllocation
- code
The code for the discount
string
- discountedAmount
The money amount that has been discounted from the order
Money
- type
The type of the code discount
"code"
export interface CartCodeDiscountAllocation extends CartDiscountAllocationBase {
/**
* The code for the discount
*/
code: string;
/**
* The type of the code discount
*/
type: 'code';
}
Money
- amount
The price amount.
number
- currencyCode
The ISO 4217 format for the currency.
CurrencyCode
export interface Money {
/**
* The price amount.
*/
amount: number;
/**
* The ISO 4217 format for the currency.
* @example 'CAD' for Canadian dollar
*/
currencyCode: CurrencyCode;
}
CurrencyCode
'AED' | 'AFN' | 'ALL' | 'AMD' | 'ANG' | 'AOA' | 'ARS' | 'AUD' | 'AWG' | 'AZN' | 'BAM' | 'BBD' | 'BDT' | 'BGN' | 'BHD' | 'BIF' | 'BMD' | 'BND' | 'BOB' | 'BOV' | 'BRL' | 'BSD' | 'BTN' | 'BWP' | 'BYN' | 'BZD' | 'CAD' | 'CDF' | 'CHE' | 'CHF' | 'CHW' | 'CLF' | 'CLP' | 'CNY' | 'COP' | 'COU' | 'CRC' | 'CUC' | 'CUP' | 'CVE' | 'CZK' | 'DJF' | 'DKK' | 'DOP' | 'DZD' | 'EGP' | 'ERN' | 'ETB' | 'EUR' | 'FJD' | 'FKP' | 'GBP' | 'GEL' | 'GHS' | 'GIP' | 'GMD' | 'GNF' | 'GTQ' | 'GYD' | 'HKD' | 'HNL' | 'HRK' | 'HTG' | 'HUF' | 'IDR' | 'ILS' | 'INR' | 'IQD' | 'IRR' | 'ISK' | 'JMD' | 'JOD' | 'JPY' | 'KES' | 'KGS' | 'KHR' | 'KMF' | 'KPW' | 'KRW' | 'KWD' | 'KYD' | 'KZT' | 'LAK' | 'LBP' | 'LKR' | 'LRD' | 'LSL' | 'LYD' | 'MAD' | 'MDL' | 'MGA' | 'MKD' | 'MMK' | 'MNT' | 'MOP' | 'MRU' | 'MUR' | 'MVR' | 'MWK' | 'MXN' | 'MXV' | 'MYR' | 'MZN' | 'NAD' | 'NGN' | 'NIO' | 'NOK' | 'NPR' | 'NZD' | 'OMR' | 'PAB' | 'PEN' | 'PGK' | 'PHP' | 'PKR' | 'PLN' | 'PYG' | 'QAR' | 'RON' | 'RSD' | 'RUB' | 'RWF' | 'SAR' | 'SBD' | 'SCR' | 'SDG' | 'SEK' | 'SGD' | 'SHP' | 'SLL' | 'SOS' | 'SRD' | 'SSP' | 'STN' | 'SVC' | 'SYP' | 'SZL' | 'THB' | 'TJS' | 'TMT' | 'TND' | 'TOP' | 'TRY' | 'TTD' | 'TWD' | 'TZS' | 'UAH' | 'UGX' | 'USD' | 'USN' | 'UYI' | 'UYU' | 'UYW' | 'UZS' | 'VES' | 'VND' | 'VUV' | 'WST' | 'XAF' | 'XAG' | 'XAU' | 'XBA' | 'XBB' | 'XBC' | 'XBD' | 'XCD' | 'XDR' | 'XOF' | 'XPD' | 'XPF' | 'XPT' | 'XSU' | 'XTS' | 'XUA' | 'XXX' | 'YER' | 'ZAR' | 'ZMW' | 'ZWL'
CartAutomaticDiscountAllocation
- discountedAmount
The money amount that has been discounted from the order
Money
- title
The title of the automatic discount
string
- type
The type of the automatic discount
"automatic"
export interface CartAutomaticDiscountAllocation
extends CartDiscountAllocationBase {
/**
* The title of the automatic discount
*/
title: string;
/**
* The type of the automatic discount
*/
type: 'automatic';
}
CartCustomDiscountAllocation
- discountedAmount
The money amount that has been discounted from the order
Money
- title
The title of the custom discount
string
- type
The type of the custom discount
"custom"
export interface CartCustomDiscountAllocation
extends CartDiscountAllocationBase {
/**
* The title of the custom discount
*/
title: string;
/**
* The type of the custom discount
*/
type: 'custom';
}
CartDiscountCode
- code
The code for the discount
string
export interface CartDiscountCode {
/**
* The code for the discount
*/
code: string;
}
Anchor to checkoutapiCheckoutApi
The API object provided to purchase.checkout
extension targets.
- Anchor to applyDiscountCodeChangeapplyDiscountCodeChange(change: ) => Promise<>required
Performs an update on the discount codes. It resolves when the new discount codes have been negotiated and results in an update to the value retrieved through the
property.
Caution> See security considerations if your extension retrieves discount codes through a network call.
NoteThis method will return an error if the cart instruction
is false, or the buyer is using an accelerated checkout method, such as Apple Pay, Google Pay, or Meta Pay.
Docs_Checkout_DiscountsApi
- applyDiscountCodeChange
Performs an update on the discount codes. It resolves when the new discount codes have been negotiated and results in an update to the value retrieved through the [`discountCodes`](/docs/api/checkout-ui-extensions/apis/discounts#standardapi-propertydetail-discountcodes) property. > Caution: > See [security considerations](/docs/api/checkout-ui-extensions/configuration#network-access) if your extension retrieves discount codes through a network call. > Note: This method will return an error if the [cart instruction](/docs/api/checkout-ui-extensions/apis/cart-instructions#standardapi-propertydetail-instructions) `discounts.canUpdateDiscountCodes` is false, or the buyer is using an accelerated checkout method, such as Apple Pay, Google Pay, or Meta Pay.
(change: DiscountCodeChange) => Promise<DiscountCodeChangeResult>
export interface Docs_Checkout_DiscountsApi
extends Pick<CheckoutApi, 'applyDiscountCodeChange'> {}
DiscountCodeChange
DiscountCodeAddChange | DiscountCodeRemoveChange
DiscountCodeAddChange
- code
The code for the discount (case-sensitive)
string
- type
The type of the `DiscountCodeChange` API.
"addDiscountCode"
export interface DiscountCodeAddChange {
/**
* The type of the `DiscountCodeChange` API.
*/
type: 'addDiscountCode';
/**
* The code for the discount (case-sensitive)
*/
code: string;
}
DiscountCodeRemoveChange
- code
The code for the discount (case-sensitive)
string
- type
The type of the `DiscountCodeChange` API.
"removeDiscountCode"
export interface DiscountCodeRemoveChange {
/**
* The type of the `DiscountCodeChange` API.
*/
type: 'removeDiscountCode';
/**
* The code for the discount (case-sensitive)
*/
code: string;
}
DiscountCodeChangeResult
DiscountCodeChangeResultSuccess | DiscountCodeChangeResultError
DiscountCodeChangeResultSuccess
- type
Indicates that the discount code change was applied successfully.
"success"
export interface DiscountCodeChangeResultSuccess {
/**
* Indicates that the discount code change was applied successfully.
*/
type: 'success';
}
DiscountCodeChangeResultError
- message
A message that explains the error. This message is useful for debugging. It is **not** localized, and therefore should not be presented directly to the buyer.
string
- type
Indicates that the discount code change failed.
"error"
export interface DiscountCodeChangeResultError {
/**
* Indicates that the discount code change failed.
*/
type: 'error';
/**
* A message that explains the error. This message is useful for debugging.
* It is **not** localized, and therefore should not be presented directly
* to the buyer.
*/
message: string;
}
Anchor to useApplyDiscountCodeChangeuse Apply Discount Code Change()
Returns a function to add or remove discount codes.
UseApplyDiscountCodeChangeGeneratedType
Returns a function to add or remove discount codes. > Caution: > See [security considerations](/docs/api/checkout-ui-extensions/configuration#network-access) if your extension retrieves discount codes through a network call.
(change: DiscountCodeChange) => Promise<DiscountCodeChangeResult>
export function useApplyDiscountCodeChange<
Target extends RenderExtensionTarget = RenderExtensionTarget,
>(): (change: DiscountCodeChange) => Promise<DiscountCodeChangeResult> {
const api = useApi<Target>();
if ('applyDiscountCodeChange' in api) {
return api.applyDiscountCodeChange;
}
throw new ExtensionHasNoMethodError(
'applyDiscountCodeChange',
api.extension.target,
);
}
DiscountCodeChange
DiscountCodeAddChange | DiscountCodeRemoveChange
DiscountCodeAddChange
- code
The code for the discount (case-sensitive)
string
- type
The type of the `DiscountCodeChange` API.
"addDiscountCode"
export interface DiscountCodeAddChange {
/**
* The type of the `DiscountCodeChange` API.
*/
type: 'addDiscountCode';
/**
* The code for the discount (case-sensitive)
*/
code: string;
}
DiscountCodeRemoveChange
- code
The code for the discount (case-sensitive)
string
- type
The type of the `DiscountCodeChange` API.
"removeDiscountCode"
export interface DiscountCodeRemoveChange {
/**
* The type of the `DiscountCodeChange` API.
*/
type: 'removeDiscountCode';
/**
* The code for the discount (case-sensitive)
*/
code: string;
}
DiscountCodeChangeResult
DiscountCodeChangeResultSuccess | DiscountCodeChangeResultError
DiscountCodeChangeResultSuccess
- type
Indicates that the discount code change was applied successfully.
"success"
export interface DiscountCodeChangeResultSuccess {
/**
* Indicates that the discount code change was applied successfully.
*/
type: 'success';
}
DiscountCodeChangeResultError
- message
A message that explains the error. This message is useful for debugging. It is **not** localized, and therefore should not be presented directly to the buyer.
string
- type
Indicates that the discount code change failed.
"error"
export interface DiscountCodeChangeResultError {
/**
* Indicates that the discount code change failed.
*/
type: 'error';
/**
* A message that explains the error. This message is useful for debugging.
* It is **not** localized, and therefore should not be presented directly
* to the buyer.
*/
message: string;
}
Anchor to useDiscountAllocationsuse Discount Allocations()
Returns the current discount allocations applied to the cart.
UseDiscountAllocationsGeneratedType
Returns the current discount allocations applied to the cart, and automatically re-renders your component if discount allocations changed.
CartDiscountAllocation[]
export function useDiscountAllocations<
Target extends RenderExtensionTarget = RenderExtensionTarget,
>(): CartDiscountAllocation[] {
const {discountAllocations} = useApi<Target>();
return useSubscription(discountAllocations);
}
CartDiscountAllocation
CartCodeDiscountAllocation | CartAutomaticDiscountAllocation | CartCustomDiscountAllocation
CartCodeDiscountAllocation
- code
The code for the discount
string
- discountedAmount
The money amount that has been discounted from the order
Money
- type
The type of the code discount
"code"
export interface CartCodeDiscountAllocation extends CartDiscountAllocationBase {
/**
* The code for the discount
*/
code: string;
/**
* The type of the code discount
*/
type: 'code';
}
Money
- amount
The price amount.
number
- currencyCode
The ISO 4217 format for the currency.
CurrencyCode
export interface Money {
/**
* The price amount.
*/
amount: number;
/**
* The ISO 4217 format for the currency.
* @example 'CAD' for Canadian dollar
*/
currencyCode: CurrencyCode;
}
CurrencyCode
'AED' | 'AFN' | 'ALL' | 'AMD' | 'ANG' | 'AOA' | 'ARS' | 'AUD' | 'AWG' | 'AZN' | 'BAM' | 'BBD' | 'BDT' | 'BGN' | 'BHD' | 'BIF' | 'BMD' | 'BND' | 'BOB' | 'BOV' | 'BRL' | 'BSD' | 'BTN' | 'BWP' | 'BYN' | 'BZD' | 'CAD' | 'CDF' | 'CHE' | 'CHF' | 'CHW' | 'CLF' | 'CLP' | 'CNY' | 'COP' | 'COU' | 'CRC' | 'CUC' | 'CUP' | 'CVE' | 'CZK' | 'DJF' | 'DKK' | 'DOP' | 'DZD' | 'EGP' | 'ERN' | 'ETB' | 'EUR' | 'FJD' | 'FKP' | 'GBP' | 'GEL' | 'GHS' | 'GIP' | 'GMD' | 'GNF' | 'GTQ' | 'GYD' | 'HKD' | 'HNL' | 'HRK' | 'HTG' | 'HUF' | 'IDR' | 'ILS' | 'INR' | 'IQD' | 'IRR' | 'ISK' | 'JMD' | 'JOD' | 'JPY' | 'KES' | 'KGS' | 'KHR' | 'KMF' | 'KPW' | 'KRW' | 'KWD' | 'KYD' | 'KZT' | 'LAK' | 'LBP' | 'LKR' | 'LRD' | 'LSL' | 'LYD' | 'MAD' | 'MDL' | 'MGA' | 'MKD' | 'MMK' | 'MNT' | 'MOP' | 'MRU' | 'MUR' | 'MVR' | 'MWK' | 'MXN' | 'MXV' | 'MYR' | 'MZN' | 'NAD' | 'NGN' | 'NIO' | 'NOK' | 'NPR' | 'NZD' | 'OMR' | 'PAB' | 'PEN' | 'PGK' | 'PHP' | 'PKR' | 'PLN' | 'PYG' | 'QAR' | 'RON' | 'RSD' | 'RUB' | 'RWF' | 'SAR' | 'SBD' | 'SCR' | 'SDG' | 'SEK' | 'SGD' | 'SHP' | 'SLL' | 'SOS' | 'SRD' | 'SSP' | 'STN' | 'SVC' | 'SYP' | 'SZL' | 'THB' | 'TJS' | 'TMT' | 'TND' | 'TOP' | 'TRY' | 'TTD' | 'TWD' | 'TZS' | 'UAH' | 'UGX' | 'USD' | 'USN' | 'UYI' | 'UYU' | 'UYW' | 'UZS' | 'VES' | 'VND' | 'VUV' | 'WST' | 'XAF' | 'XAG' | 'XAU' | 'XBA' | 'XBB' | 'XBC' | 'XBD' | 'XCD' | 'XDR' | 'XOF' | 'XPD' | 'XPF' | 'XPT' | 'XSU' | 'XTS' | 'XUA' | 'XXX' | 'YER' | 'ZAR' | 'ZMW' | 'ZWL'
CartAutomaticDiscountAllocation
- discountedAmount
The money amount that has been discounted from the order
Money
- title
The title of the automatic discount
string
- type
The type of the automatic discount
"automatic"
export interface CartAutomaticDiscountAllocation
extends CartDiscountAllocationBase {
/**
* The title of the automatic discount
*/
title: string;
/**
* The type of the automatic discount
*/
type: 'automatic';
}
CartCustomDiscountAllocation
- discountedAmount
The money amount that has been discounted from the order
Money
- title
The title of the custom discount
string
- type
The type of the custom discount
"custom"
export interface CartCustomDiscountAllocation
extends CartDiscountAllocationBase {
/**
* The title of the custom discount
*/
title: string;
/**
* The type of the custom discount
*/
type: 'custom';
}
Anchor to useDiscountCodesuse Discount Codes()
Returns the current discount codes applied to the cart.
UseDiscountCodesGeneratedType
Returns the current discount codes applied to the cart, and automatically re-renders your component if discount codes are added or removed.
CartDiscountCode[]
export function useDiscountCodes<
Target extends RenderExtensionTarget = RenderExtensionTarget,
>(): CartDiscountCode[] {
const {discountCodes} = useApi<Target>();
return useSubscription(discountCodes);
}
CartDiscountCode
- code
The code for the discount
string
export interface CartDiscountCode {
/**
* The code for the discount
*/
code: string;
}