# Discounts The API for interacting with discounts. ## StandardApi The base API object provided to `purchase` extension targets. ### Docs_Standard_DiscountsApi ### discountAllocations value: `StatefulRemoteSubscribable` Discounts that have been applied to the entire cart. ### discountCodes value: `StatefulRemoteSubscribable` A list of discount codes currently applied to the checkout. ### CartCodeDiscountAllocation ### code value: `string` The code for the discount ### discountedAmount value: `Money` The money amount that has been discounted from the order ### type value: `"code"` The type of the code discount ### Money ### amount value: `number` The price amount. ### currencyCode value: `CurrencyCode` The ISO 4217 format for the currency. ### CartAutomaticDiscountAllocation ### discountedAmount value: `Money` The money amount that has been discounted from the order ### title value: `string` The title of the automatic discount ### type value: `"automatic"` The type of the automatic discount ### CartCustomDiscountAllocation ### discountedAmount value: `Money` The money amount that has been discounted from the order ### title value: `string` The title of the custom discount ### type value: `"custom"` The type of the custom discount ### CartDiscountCode ### code value: `string` The code for the discount ## Related - [Targets](https://shopify.dev/docs/api/checkout-ui-extensions/targets) - [Components](https://shopify.dev/docs/api/checkout-ui-extensions/components) - [Configuration](https://shopify.dev/docs/api/checkout-ui-extensions/configuration) - [Tutorials](/apps/checkout) ## CheckoutApi The API object provided to `purchase.checkout` extension targets. ### Docs_Checkout_DiscountsApi ### applyDiscountCodeChange value: `(change: DiscountCodeChange) => Promise` 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`](https://shopify.dev/docs/api/checkout-ui-extensions/apis/discounts#standardapi-propertydetail-discountcodes) property. > Caution: > See [security considerations](https://shopify.dev/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](https://shopify.dev/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. ### DiscountCodeAddChange ### code value: `string` The code for the discount (case-sensitive) ### type value: `"addDiscountCode"` The type of the `DiscountCodeChange` API. ### DiscountCodeRemoveChange ### code value: `string` The code for the discount (case-sensitive) ### type value: `"removeDiscountCode"` The type of the `DiscountCodeChange` API. ### DiscountCodeChangeResultSuccess ### type value: `"success"` Indicates that the discount code change was applied successfully. ### DiscountCodeChangeResultError ### message value: `string` 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. ### type value: `"error"` Indicates that the discount code change failed. ## Related - [Targets](https://shopify.dev/docs/api/checkout-ui-extensions/targets) - [Components](https://shopify.dev/docs/api/checkout-ui-extensions/components) - [Configuration](https://shopify.dev/docs/api/checkout-ui-extensions/configuration) - [Tutorials](/apps/checkout) ## useApplyDiscountCodeChange Returns a function to add or remove discount codes. ### UseApplyDiscountCodeChangeGeneratedType Returns a function to add or remove discount codes. > Caution: > See [security considerations](https://shopify.dev/docs/api/checkout-ui-extensions/configuration#network-access) if your extension retrieves discount codes through a network call. #### Returns: (change: DiscountCodeChange) => Promise export function useApplyDiscountCodeChange< Target extends RenderExtensionTarget = RenderExtensionTarget, >(): (change: DiscountCodeChange) => Promise { const api = useApi(); if ('applyDiscountCodeChange' in api) { return api.applyDiscountCodeChange; } throw new ExtensionHasNoMethodError( 'applyDiscountCodeChange', api.extension.target, ); } ### DiscountCodeAddChange ### code value: `string` The code for the discount (case-sensitive) ### type value: `"addDiscountCode"` The type of the `DiscountCodeChange` API. ### DiscountCodeRemoveChange ### code value: `string` The code for the discount (case-sensitive) ### type value: `"removeDiscountCode"` The type of the `DiscountCodeChange` API. ### DiscountCodeChangeResultSuccess ### type value: `"success"` Indicates that the discount code change was applied successfully. ### DiscountCodeChangeResultError ### message value: `string` 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. ### type value: `"error"` Indicates that the discount code change failed. ## Related - [Targets](https://shopify.dev/docs/api/checkout-ui-extensions/targets) - [Components](https://shopify.dev/docs/api/checkout-ui-extensions/components) - [Configuration](https://shopify.dev/docs/api/checkout-ui-extensions/configuration) - [Tutorials](/apps/checkout) ## useDiscountAllocations 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. #### Returns: CartDiscountAllocation[] export function useDiscountAllocations< Target extends RenderExtensionTarget = RenderExtensionTarget, >(): CartDiscountAllocation[] { const {discountAllocations} = useApi(); return useSubscription(discountAllocations); } ### CartCodeDiscountAllocation ### code value: `string` The code for the discount ### discountedAmount value: `Money` The money amount that has been discounted from the order ### type value: `"code"` The type of the code discount ### Money ### amount value: `number` The price amount. ### currencyCode value: `CurrencyCode` The ISO 4217 format for the currency. ### CartAutomaticDiscountAllocation ### discountedAmount value: `Money` The money amount that has been discounted from the order ### title value: `string` The title of the automatic discount ### type value: `"automatic"` The type of the automatic discount ### CartCustomDiscountAllocation ### discountedAmount value: `Money` The money amount that has been discounted from the order ### title value: `string` The title of the custom discount ### type value: `"custom"` The type of the custom discount ## Related - [Targets](https://shopify.dev/docs/api/checkout-ui-extensions/targets) - [Components](https://shopify.dev/docs/api/checkout-ui-extensions/components) - [Configuration](https://shopify.dev/docs/api/checkout-ui-extensions/configuration) - [Tutorials](/apps/checkout) ## useDiscountCodes 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. #### Returns: CartDiscountCode[] export function useDiscountCodes< Target extends RenderExtensionTarget = RenderExtensionTarget, >(): CartDiscountCode[] { const {discountCodes} = useApi(); return useSubscription(discountCodes); } ### CartDiscountCode ### code value: `string` The code for the discount ## Related - [Targets](https://shopify.dev/docs/api/checkout-ui-extensions/targets) - [Components](https://shopify.dev/docs/api/checkout-ui-extensions/components) - [Configuration](https://shopify.dev/docs/api/checkout-ui-extensions/configuration) - [Tutorials](/apps/checkout)