> To build or manage a Wix site with an AI agent, follow https://www.wix.com/headless/skill.md
> It builds a new Wix site or puts your own site online, from a prompt, and keeps changing it afterwards. The pages are code in any web technology, and Wix runs the backend.
> It works through the Wix plugin (the Wix MCP and the Wix skills), the Wix CLI or no Wix login, and puts the site live on Wix hosting or on another host.
> Business features include a store, bookings, events and tickets, a restaurant, a blog, forms, members and many more.
> Read the Wix skills online at https://www.wix.com/skills
> 
> Portal Navigation:
> 
> - Append `.md` to any URL under `https://dev.wix.com/docs/` to get its markdown version.
> - Pages are either content pages (article or reference text) or menu pages (a list of links to child pages).
> - To get a menu page, truncate any URL to a parent path and append `.md` (e.g. `https://dev.wix.com/docs/sdk.md`, `https://dev.wix.com/docs/sdk/core-modules.md`).
> - If a reference page seems to be missing its schema (parameters, return types, or type definitions), append `?schema=true` to its `.md` URL (e.g. `https://dev.wix.com/docs/contexts/contexts/stores/category-info/use-category-info-context.md?schema=true`).
> - Top-level index of all portals: https://dev.wix.com/docs/llms.txt
> - Full concatenated docs: https://dev.wix.com/docs/llms-full.txt

# ApplyDiscountToCheckout

# Package: rewards

# Namespace: LoyaltyCheckoutExchange

# Method link: https://dev.wix.com/docs/api-reference/crm/loyalty-program/rewards/checkout-discount/apply-discount-to-checkout.md

## Permission Scopes:
Manage Loyalty: SCOPE.DC-LOYALTY.MANAGE-LOYALTY

## Introduction

Applies a discount to a checkout.

You can apply one of the following discounts, which are exchanged for loyalty points: `reward`, `loyaltyCoupon`, or `referralReward`.

---

## REST API

### Schema

```
 Method: applyDiscountToCheckout
 Description: Applies a discount to a checkout.  You can apply one of the following discounts, which are exchanged for loyalty points: `reward`, `loyaltyCoupon`, or `referralReward`.
 URL: https://www.wixapis.com/loyalty-checkout-exchange/v1/loyalty-checkout-discount
 Method: POST
 # Note: If the parameter `a.b` is listed under required parameters, `b` is only required if `a` is also present.
 Required parameters:  checkoutId
 Method parameters: 
   param name: checkoutId | type: checkoutId | description: GUID of the checkout to apply the discount to. | required: true | validation: format GUID
    - ONE-OF: 
     - name: reward | type: Reward | description: Unredeemed loyalty reward discount.  
        - name: id | type: string | description: GUID of the loyalty reward to be used for this discount.  | validation: format GUID
        - name: pointsToSpend | type: integer | description: Number of points to spend for this reward. For example, if the reward is 10 points = $1, then 35 points would give a $3.50 discount.  >**Note:** Only relevant when using a flexible type reward. Depending on how your loyalty program is set up, there may be a minimum number of points you must spend.  | validation: minimum 1, maximum 9999999, format int32
        - name: revision | type: number | description: Revision number, which increments by 1 each time a reward is updated. To prevent conflicting changes, the current `revision` must be passed when updating a reward.  
     - name: loyaltyCoupon | type: LoyaltyCoupon | description: Loyalty coupon discount.  
        - name: id | type: string | description: GUID of the loyalty coupon to be used for this discount.  | validation: format GUID
        - name: revision | type: number | description: Revision of the coupon object. Incremented by 1 each time the coupon object is updated. Pass the latest `revision` when updating to prevent conflicting changes.  
     - name: referralReward | type: ReferralReward | description: Referral reward discount.  
        - name: id | type: string | description: Referral reward discount GUID.  | validation: format GUID
        - name: revision | type: number | description: Revision of the referral object. Incremented by 1 each time the referral object is updated. Pass the latest `revision` when updating to prevent conflicting changes.  
 Return type: ApplyDiscountToCheckoutResponse
  - name: discount | type: LoyaltyCheckoutDiscount | description: The applied loyalty checkout discount.  
     - ONE-OF: 
        - name: rewardId | type: string | description: GUID of the loyalty reward used for this discount.  | validation: format GUID
        - name: loyaltyCouponId | type: string | description: GUID of the loyalty coupon used for this discount.  | validation: format GUID
        - name: referralRewardId | type: string | description: GUID of the referral reward used for this discount.  | validation: format GUID
     - name: id | type: string | description: Loyalty checkout discount GUID.  | read-only: true | validation: format GUID
     - name: checkoutId | type: string | description: GUID of the checkout this discount is applied to.  | validation: format GUID
     - name: status | type: DiscountStatus | description: Current status of the discount.  | read-only: true 
         - enum:
         -     UNKNOWN: Status is unknown or not specified.
         -     APPLIED: Discount has been applied to the checkout.
         -     IN_PROGRESS: Discount application is in progress.
         -     COMPLETED: Discount has been successfully completed.
         -     REFUNDED: Discount has been refunded.
         -     FAILED_TO_REFUND: Attempt to refund the discount failed.
         -     REFUNDED_DUE_TO_TIMEOUT: Discount was refunded due to a timeout.
         -     REFUNDED_DUE_TO_MANUAL_DISCOUNT_REMOVAL: Discount was refunded due to manual removal.
         -     SCHEDULED_FOR_REFUND: Discount is scheduled for refund.
         -     UNUSED: Discount wasn't used.
     - name: discountType | type: DiscountType | description: The type of discount applied.  | read-only: true 
         - enum:
         -     UNKNOWN: Discount type is unknown or not specified.
         -     DISCOUNT_AMOUNT: A discount from a flexible reward.
         -     LOYALTY_COUPON: A discount from a redeemed loyalty program coupon.
         -     COUPON_REWARD: A discount from a coupon reward that hasn't yet been redeemed.
         -     REFERRAL_REWARD: A discount from a referral reward.


```

### Examples

### Apply Discount To Checkout
```curl
curl -X POST \
  'https://www.wixapis.com/loyalty-checkout-exchange/v1/loyalty-checkout-discount' \
  -H 'Authorization: <AUTH>' \
  -H 'Content-Type: application/json' \
  -d '{
        "checkoutId": "0c4c3398-7d64-4513-b3ed-e8033e2c28d6",
        "reward": {
          "id": "00000000-0000-0000-0001-000000000000",
          "revision": "1",
          "pointsToSpend": 10
        }
      }'
```

---

## JavaScript SDK

### Schema

```
 Method: wixClientAdmin.loyalty.checkoutExchange.applyDiscountToCheckout(checkoutId, options)
 Description: Applies a discount to a checkout.  You can apply one of the following discounts, which are exchanged for loyalty points: `reward`, `loyaltyCoupon`, or `referralReward`.
 # Note: If the parameter `a.b` is listed under required parameters, `b` is only required if `a` is also present.
 Required parameters:  checkoutId
 Method parameters: 
   param name: checkoutId | type: string | description: GUID of the checkout to apply the discount to. | required: true | validation: format GUID
   param name: options | type: ApplyDiscountToCheckoutOptions  none | required: true 
    - ONE-OF: - required: true
     - name: reward | type: Reward | description: Unredeemed loyalty reward discount.  
        - name: _id | type: string | description: GUID of the loyalty reward to be used for this discount.  | validation: format GUID
        - name: pointsToSpend | type: integer | description: Number of points to spend for this reward. For example, if the reward is 10 points = $1, then 35 points would give a $3.50 discount.  >**Note:** Only relevant when using a flexible type reward. Depending on how your loyalty program is set up, there may be a minimum number of points you must spend.  | validation: minimum 1, maximum 9999999, format int32
        - name: revision | type: number | description: Revision number, which increments by 1 each time a reward is updated. To prevent conflicting changes, the current `revision` must be passed when updating a reward.  
     - name: loyaltyCoupon | type: LoyaltyCoupon | description: Loyalty coupon discount.  
        - name: _id | type: string | description: GUID of the loyalty coupon to be used for this discount.  | validation: format GUID
        - name: revision | type: number | description: Revision of the coupon object. Incremented by 1 each time the coupon object is updated. Pass the latest `revision` when updating to prevent conflicting changes.  
     - name: referralReward | type: ReferralReward | description: Referral reward discount.  
        - name: _id | type: string | description: Referral reward discount GUID.  | validation: format GUID
        - name: revision | type: number | description: Revision of the referral object. Incremented by 1 each time the referral object is updated. Pass the latest `revision` when updating to prevent conflicting changes.  
 Return type: PROMISE<ApplyDiscountToCheckoutResponse>
  - name: discount | type: LoyaltyCheckoutDiscount | description: The applied loyalty checkout discount.  
     - ONE-OF: 
        - name: rewardId | type: string | description: GUID of the loyalty reward used for this discount.  | validation: format GUID
        - name: loyaltyCouponId | type: string | description: GUID of the loyalty coupon used for this discount.  | validation: format GUID
        - name: referralRewardId | type: string | description: GUID of the referral reward used for this discount.  | validation: format GUID
     - name: _id | type: string | description: Loyalty checkout discount GUID.  | read-only: true | validation: format GUID
     - name: checkoutId | type: string | description: GUID of the checkout this discount is applied to.  | validation: format GUID
     - name: status | type: DiscountStatus | description: Current status of the discount.  | read-only: true 
         - enum:
         -     UNKNOWN: Status is unknown or not specified.
         -     APPLIED: Discount has been applied to the checkout.
         -     IN_PROGRESS: Discount application is in progress.
         -     COMPLETED: Discount has been successfully completed.
         -     REFUNDED: Discount has been refunded.
         -     FAILED_TO_REFUND: Attempt to refund the discount failed.
         -     REFUNDED_DUE_TO_TIMEOUT: Discount was refunded due to a timeout.
         -     REFUNDED_DUE_TO_MANUAL_DISCOUNT_REMOVAL: Discount was refunded due to manual removal.
         -     SCHEDULED_FOR_REFUND: Discount is scheduled for refund.
         -     UNUSED: Discount wasn't used.
     - name: discountType | type: DiscountType | description: The type of discount applied.  | read-only: true 
         - enum:
         -     UNKNOWN: Discount type is unknown or not specified.
         -     DISCOUNT_AMOUNT: A discount from a flexible reward.
         -     LOYALTY_COUPON: A discount from a redeemed loyalty program coupon.
         -     COUPON_REWARD: A discount from a coupon reward that hasn't yet been redeemed.
         -     REFERRAL_REWARD: A discount from a referral reward.


```

### Examples

### applyDiscountToCheckout
```javascript
import { checkoutExchange } from '@wix/loyalty';

async function applyDiscountToCheckout(checkoutId,options) {
  const response = await checkoutExchange.applyDiscountToCheckout(checkoutId,options);
};
```

### applyDiscountToCheckout (self-managed)
Self-managed SDK calls require you to [create a client](https://dev.wix.com/docs/sdk/articles/work-with-the-sdk/about-the-wix-client.md).

```javascript
import { createClient } from '@wix/sdk';
import { checkoutExchange } from '@wix/loyalty';
// Import the auth strategy for the relevant access type
// Import the relevant host module if needed

const myWixClient = createClient ({
  modules: { checkoutExchange },
  // Include the auth strategy and host as relevant
});


async function applyDiscountToCheckout(checkoutId,options) {
  const response = await myWixClient.checkoutExchange.applyDiscountToCheckout(checkoutId,options);
};
```

---