use Apply Discount Code Changehook
Returns a function to add or remove discount codes.
See security considerations if your extension retrieves discount codes through a network call.
Anchor to useApplyDiscountCodeChangeuse Apply Discount Code Change()
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
- type
The type of the `DiscountCodeChange` API.
"addDiscountCode"
- code
The code for the discount
string
export interface DiscountCodeAddChange {
/**
* The type of the `DiscountCodeChange` API.
*/
type: 'addDiscountCode';
/**
* The code for the discount
*/
code: string;
}
DiscountCodeRemoveChange
- type
The type of the `DiscountCodeChange` API.
"removeDiscountCode"
- code
The code for the discount
string
export interface DiscountCodeRemoveChange {
/**
* The type of the `DiscountCodeChange` API.
*/
type: 'removeDiscountCode';
/**
* The code for the discount
*/
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
- type
Indicates that the discount code change failed.
"error"
- 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
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;
}