# Discounts calculated on your server

Server-calculated discounts give you full control over your store's discounts. However, you need to code all logic for such discounts on a self-hosted endpoint called `discountUrl`.

<figure><img src="https://2472323273-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FpZxwtrnfjGn9RK75zT5A%2Fuploads%2FKPRtqKItmrx4lZK8zuAm%2FdiscountUrl_request.png?alt=media&#x26;token=45cf6d36-3cb9-4ae9-aa78-6271403668f8" alt=""><figcaption></figcaption></figure>

Every time cart details are changed, Ecwid sends cart data as a **POST request with JSON body** to `discountUrl` and waits for the response with the discount details. Your app must deliver the response in the **5-second** window. Otherwise, Ecwid allows customers to proceed without the discount.

When calculating discounts, you can refer to Ecwid's flow for calculating the order total which depends on the gross/net prices in the order:

{% tabs %}
{% tab title="Gross prices" %}
Check the store settings with the [Get store profile > taxSettings](https://app.gitbook.com/s/G9n5VxMY9T0Ob3D56PSD/rest-api/store-profile/get-store-profile#taxsettings) > `pricesIncludeTax` field. If it's `false`, modifications to the order total are calculated in the following order:

1. Order subtotal
2. Coupon discount
3. Handling fee
4. Discounts
5. Shipping
6. Taxes
   {% endtab %}

{% tab title="Net prices" %}
Check the store settings with the [Get store profile > taxSettings](https://app.gitbook.com/s/G9n5VxMY9T0Ob3D56PSD/rest-api/store-profile/get-store-profile#taxsettings) > `pricesIncludeTax` field. If it's `true`, modifications to the order total are calculated in the following order:

1. Order subtotal
2. Coupon discount
3. Handling fee
4. Taxes
5. Discounts
6. Shipping
   {% endtab %}
   {% endtabs %}

### Connect server-calculated discounts with your store

As a developer, you must develop a self-hosted endpoint that receives POST requests from your Ecwid store and responds with discounts.

{% hint style="info" %}
If you don't yet have an app for Ecwid API access, start with the following [instructions](https://app.gitbook.com/s/uOzT5egoVTAjMJwRuMQT/get-started/set-up-your-dev-environment-in-ecwid#step-2.-get-your-first-application).
{% endhint %}

Make sure your app has the `customize_cart_calculation` access scope and `discountUrl` endpoint. [Request application update](https://app.gitbook.com/s/uOzT5egoVTAjMJwRuMQT/contact-ecwid-api-support-team)

### Process discount request from the store

Upon receiving a discount request, parse the JSON body to get all the required details about the cart. Use the example and fields breakdown below:&#x20;

<details>

<summary>Example of request coming from the store</summary>

```http
POST https://mycoolapp.com/discounts HTTP/1.1

{
  "storeId": 1003,
  "merchantAppSettings": {},
  "cart": {
    "id": null,
    "orderNumber": null,
    "vendorOrderNumber": null,
    "subtotal": 2130,
    "ipAddress": null,
    "couponDiscount": 213,
    "paymentStatus": "INCOMPLETE",
    "fulfillmentStatus": "NEW",
    "refererUrl": null,
    "orderComments": null,
    "volumeDiscount": 0,
    "membershipBasedDiscount": 0,
    "totalAndMembershipBasedDiscount": 0,
    "discount": 0,
    "customerGroupId": null,
    "customerGroup": null,
    "customerId": null,
    "customerEmail": null,
    "discountCoupon": {
      "id": 135823561,
      "ownerId": 1003,
      "name": "Coupon",
      "code": "YOURCODE",
      "discountType": "PERCENT",
      "status": "ACTIVE",
      "discount": 10,
      "launchDate": "2019-09-30 23:00:00 +0000",
      "expirationDate": null,
      "totalLimit": null,
      "usesLimit": "UNLIMITED",
      "applicationLimit": "UNLIMITED",
      "creationDate": "2021-09-21 13:40:21 +0000",
      "orderCount": 0,
      "legacyCatalogLimit": null,
      "catalogLimit": null,
      "repeatCustomerOnly": false,
      "newCustomerOnly": false,
      "parentId": 41576009,
      "customerId": 0,
      "cartId": 1950723716,
      "updateDate": "2021-02-23 02:01:30 +0000"
    },
    "discountInfo": null,
    "handlingFee": {
      "name": "Handling Fee",
      "value": 0,
      "description": ""
    },
    "hidden": false,
    "items": [
      {
        "weight": 120,
        "price": 2130,
        "amount": 1,
        "productId": 352841275,
        "combinationId": 12345,
        "name": "Test Product",
        "categoryId": null,
        "sku": "00002312",
        "selectedOptions": [
          {
            "name": "Size",
            "nameTranslated": null,
            "type": "CHOICE",
            "value": "S",
            "valueTranslated": {
              "en": "S"
            },
            "valuesArray": [
              "S"
            ],
            "valuesArrayTranslated": null,
            "files": null,
            "selections": [
              {
                "selectionTitle": "S",
                "selectionModifier": 0,
                "selectionModifierType": "ABSOLUTE"
              }
            ]
          }
        ],
        "dimensions": {
          "length": 0,
          "width": 0,
          "height": 0
        },
        "productPrice": 2130,
        "categoryIds": [],
        "categories": [],
        "quantity": null,
        "unlimited": true,
        "inStock": true,
        "priceInProductList": 2130,
        "isShippingRequired": true,
        "productClassId": 0,
        "enabled": true,
        "warningLimit": 0,
        "fixedShippingRateOnly": false,
        "fixedShippingRate": 0,
        "options": [
          {
            "type": "SELECT",
            "name": "Size",
            "defaultChoice": 0,
            "required": false,
            "choices": [
              {
                "text": "S",
                "priceModifier": 0,
                "priceModifierType": "ABSOLUTE"
              },
              {
                "text": "M",
                "priceModifier": 0,
                "priceModifierType": "ABSOLUTE"
              }
            ]
          }
        ],
        "wholesalePrices": [],
        "compareToPrice": null,
        "url": "https://store.ecwid.com/#!/Test-Product/p/352841275",
        "created": "2021-05-03 18:23:13 +0000",
        "updated": "2021-09-21 13:42:21 +0000",
        "createTimestamp": 1620066193,
        "updateTimestamp": 1632231741,
        "defaultCombinationId": 222806564,
        "imageUrl": null,
        "thumbnailUrl": null,
        "smallThumbnailUrl": null,
        "hdThumbnailUrl": null,
        "originalImageUrl": null,
        "originalImage": null,
        "borderInfo": null,
        "galleryImages": [],
        "defaultCategoryId": 0,
        "seoTitle": "",
        "seoDescription": "",
        "favorites": {
          "count": 0,
          "displayedCount": "0"
        },
        "attributes": [
          {
            "id": 27942320,
            "name": "UPC",
            "type": "UPC",
            "value": "TEST",
            "show": "DESCR"
          },
          {
            "id": 27942321,
            "name": "Brand",
            "type": "BRAND",
            "value": "GENERIC",
            "show": "DESCR"
          }
        ],
        "relatedProducts": {
          "productIds": [],
          "relatedCategory": {
            "enabled": false,
            "categoryId": 0,
            "productCount": 5
          }
        },
        "combinations": [
          {
            "id": 222806563,
            "sku": "00002444",
            "combinationNumber": 2,
            "options": [
              {
                "name": "Size",
                "nameTranslated": {
                  "en": "Size"
                },
                "value": "M",
                "valueTranslated": {
                  "en": "M"
                }
              }
            ],
            "smallThumbnailUrl": null,
            "hdThumbnailUrl": null,
            "thumbnailUrl": null,
            "imageUrl": null,
            "originalImageUrl": null,
            "price": null,
            "defaultDisplayedPrice": 2130,
            "defaultDisplayedPriceFormatted": "$2 130.00",
            "compareToPrice": null,
            "wholesalePrices": null,
            "quantity": null,
            "unlimited": true,
            "inStock": true,
            "warningLimit": 0,
            "weight": 190,
            "borderInfo": null,
            "attributes": [],
            "isShippingRequired": null
          },
          {
            "id": 222806564,
            "sku": "00002312",
            "combinationNumber": 1,
            "options": [
              {
                "name": "Size",
                "nameTranslated": {
                  "en": "Size"
                },
                "value": "S",
                "valueTranslated": {
                  "en": "S"
                }
              }
            ],
            "smallThumbnailUrl": null,
            "hdThumbnailUrl": null,
            "thumbnailUrl": null,
            "imageUrl": null,
            "originalImageUrl": null,
            "price": null,
            "defaultDisplayedPrice": 2130,
            "defaultDisplayedPriceFormatted": "$2 130.00",
            "compareToPrice": null,
            "wholesalePrices": null,
            "quantity": null,
            "unlimited": true,
            "inStock": true,
            "warningLimit": 0,
            "weight": 120,
            "borderInfo": null,
            "attributes": [],
            "isShippingRequired": null
          }
        ],
        "showOnFrontpage": 2
      }
    ],
    "shippingAddress": {
      "street": "test",
      "city": "test",
      "countryCode": "US",
      "postalCode": "10001",
      "stateOrProvinceCode": "NY",
      "stateOrProvinceName": "New York"
    },
    "originAddress": {
      "street": "1 Teema, Harris Road, South End\n",
      "city": "Port Elizabeth",
      "countryCode": "DE",
      "postalCode": "54570",
      "stateOrProvinceCode": ""
    },
    "weight": 120,
    "weightUnit": "kg",
    "dimensionUnit": "CM",
    "currency": "USD",
    "predictedPackages": null,
    "paymentMethod": "PayPal",
    "extraFields": null
  },
 "lang": "en"

```

</details>

Request contains a JSON object with the following fields:

| Name                | Type                 | Description                                                 |
| ------------------- | -------------------- | ----------------------------------------------------------- |
| storeId             | number               | Ecwid store ID.                                             |
| merchantAppSettings | json                 | Merchant settings for your integration set up by your code. |
| cart                | object [cart](#cart) | All available cart details.                                 |
| lang                | string               | Customer's storefront language (e.g. `en`).                 |

#### cart

<table><thead><tr><th width="197">Field</th><th width="170">Type</th><th>Description</th></tr></thead><tbody><tr><td>Id</td><td>string</td><td>Unique order ID.</td></tr><tr><td>subtotal</td><td>number</td><td>Cost of all products in the order (item's <code>price</code> x <code>quantity</code>) before any cost modifiers such as discounts, taxes, fees, etc. are applied.</td></tr><tr><td>email</td><td>string</td><td>Customer's email address.</td></tr><tr><td>paymentMethod</td><td>string</td><td>Name of the payment method customer chosen at the checkout.</td></tr><tr><td>ipAddress</td><td>string</td><td>Customer's IP address detected at the checkout.</td></tr><tr><td>paymentStatus</td><td>string</td><td>Order payment status. Supported values: <code>AWAITING_PAYMENT</code>, <code>PAID</code>, <code>CANCELLED</code>, <code>REFUNDED</code>, <code>PARTIALLY_REFUNDED</code>, <code>INCOMPLETE</code>, <code>CUSTOM_PAYMENT_STATUS_1</code>, <code>CUSTOM_PAYMENT_STATUS_2</code>, <code>CUSTOM_PAYMENT_STATUS_3</code>.<br><br>Read more about order statuses in <a href="https://support.ecwid.com/hc/en-us/articles/207806235-Order-details-and-statuses-overview#-understanding-order-statuses"><strong>Help Center</strong></a>.</td></tr><tr><td>fulfillmentStatus</td><td>string</td><td>Order fulfillment status. Supported values: <code>AWAITING_PROCESSING</code>, <code>PROCESSING</code>, <code>SHIPPED</code>, <code>DELIVERED</code>, <code>WILL_NOT_DELIVER</code>, <code>RETURNED</code>, <code>READY_FOR_PICKUP</code>, <code>OUT_FOR_DELIVERY</code>, <code>CUSTOM_FULFILLMENT_STATUS_1</code>, <code>CUSTOM_FULFILLMENT_STATUS_2</code>, <code>CUSTOM_FULFILLMENT_STATUS_3</code>.<br><br>Read more about order statuses in <a href="https://support.ecwid.com/hc/en-us/articles/207806235-Order-details-and-statuses-overview#-understanding-order-statuses"><strong>Help Center</strong></a>.</td></tr><tr><td>refererUrl</td><td>string</td><td>URL of the page when order was placed without page slugs (hash <code>#</code> part).</td></tr><tr><td>orderComments</td><td>string</td><td>Order comments, left by a customer at the checkout.</td></tr><tr><td>volumeDiscount</td><td>number</td><td>Sum of applied <strong>advanced discounts (promotions)</strong> based on subtotal. Included in the <code>discount</code> field.</td></tr><tr><td>membershipBasedDiscount</td><td>number</td><td>Sum of applied <strong>advanced discounts (promotions)</strong> based on customer group. Included in the <code>discount</code> field.</td></tr><tr><td>totalAndMembershipBasedDiscount</td><td>number</td><td>Sum of applied <strong>advanced discounts (promotions)</strong> based on both subtotal and customer group. Included in the <code>discount</code> field.</td></tr><tr><td>discount</td><td>number</td><td><p>Sum of all applied <strong>advanced discounts</strong>. Does not include discount coupons.</p><p>Total order discount is the sum of the<code>couponDiscount</code> and <code>discount</code> fields.</p></td></tr><tr><td>couponDiscount</td><td>number</td><td><p>Discount value from applied <strong>discount coupon</strong>, e.g. <code>10</code>.</p><p>Total order discount is the sum of the<code>couponDiscount</code> and <code>discount</code> fields.</p></td></tr><tr><td>discountInfo</td><td>array <a href="#discountinfo">discounts</a></td><td>Detailed information about applied <strong>advanced discounts (promotions)</strong>.</td></tr><tr><td>discountCoupon</td><td>object <a href="#discountcoupon">discountCoupon</a></td><td>Detailed information about applied <strong>discount coupons (promotions)</strong>.</td></tr><tr><td>customerId</td><td>number</td><td>Unique internal ID assigned to the customer.</td></tr><tr><td>customerGroup</td><td>string</td><td>Name of the group the customer belongs to (if any).<br><br>Read mroe about <a href="https://support.ecwid.com/hc/en-us/articles/207807105-Customer-groups">customer groups</a>.</td></tr><tr><td>customerGroupId</td><td>number</td><td>ID of the group the customer belongs to.</td></tr><tr><td>items</td><td>array <a href="#items">items</a></td><td>Detailed information about products in the order.</td></tr><tr><td>shippingAddress</td><td>object <a href="#shippingaddress">shippingAddress</a></td><td>Details about the shipping address entered at the checkout by the customer.</td></tr><tr><td>originAddress</td><td>object <a href="#originaddress">originAddress</a></td><td>Store address from where the shipping starts.</td></tr><tr><td>predictedPackages</td><td>object <a href="#predictedpackages">predictedPackages</a></td><td>Ecwid-calculated details about one package fit to ship all items.</td></tr><tr><td>handlingFee</td><td>object <a href="#handlingfee">handlingFee</a></td><td>Details about fees applied to order.</td></tr><tr><td>extraFields</td><td>object <a href="#extrafields">extraFields</a></td><td>Names and values of custom checkout fields applied to the order.</td></tr></tbody></table>

#### items

<table><thead><tr><th width="198">Field</th><th width="156">Type</th><th>Description</th></tr></thead><tbody><tr><td>productId</td><td>number</td><td>Internal product ID. Can be used to find full product details with the <mark style="color:green;"><code>GET</code></mark> <code>/products</code> request.</td></tr><tr><td>combinationId</td><td>number</td><td>ID of a product variation whos options mathes with values chosen by the customer at the checkout.<br><br>Read more on product variations in <a href="https://support.ecwid.com/hc/en-us/articles/207100299-Product-variations">Help Center.</a></td></tr><tr><td>categoryId</td><td>number</td><td>ID of the category this product belongs to or was added from. <br><br>Returns <code>-1</code> if the product was added to the cart via the Buy Now button.</td></tr><tr><td>price</td><td>number</td><td>Price of product in the order with all price modifier applied.</td></tr><tr><td>productPrice</td><td>number</td><td>Basic product price without any modifiers: options markups, discounts, taxes, fees.</td></tr><tr><td>priceInProductList</td><td>number</td><td>Product price displayed in a storefront. May differ from the <em>price</em> value when the product has options and variations and the default variation's price is different from the base product price. <strong>Does not include taxes</strong></td></tr><tr><td>weight</td><td>number</td><td>Weight of the product.</td></tr><tr><td>name</td><td>string</td><td>Name of the product.</td></tr><tr><td>sku</td><td>string</td><td>Product SKU. <br><br>If the chosen options match a variation, this will be a variation SKU.</td></tr><tr><td>amount</td><td>number</td><td>Quantity of the product in the cart.</td></tr><tr><td>nameTranslated</td><td>object <a href="#translations">translations</a></td><td>Available translations for the product name.</td></tr><tr><td>isShippingRequired</td><td>boolean</td><td>Defines if the product requires shipping.</td></tr><tr><td>fixedShippingRateOnly</td><td>boolean</td><td>Defines if the product has a unique fixed shipping rate. <br><br>If <code>true</code>, shipping costs won't calculate for the product and <code>fixedShippingRate</code> value will be used instead.</td></tr><tr><td>fixedShippingRate</td><td>number</td><td>Fixed shipping costs for the product. <br><br>Affects shipping costs only if <code>fixedShippingRateOnly</code> is <code>true</code>.</td></tr><tr><td>selectedOptions</td><td>array <a href="#selectedoptions">selectedOptions</a></td><td>Product options values selected by the customer at the checkout.</td></tr><tr><td>imageUrl</td><td>string</td><td>Link to the main product image.</td></tr><tr><td>files</td><td>array of objects <a href="#files">files</a></td><td>Details about downloadable files attached to the product.</td></tr><tr><td>dimensions</td><td>object <a href="#dimensions">dimensions</a></td><td>Details about product dimensions used for shipping costs calculations.</td></tr><tr><td>discounts</td><td>array <a href="#discounts">discounts</a></td><td><strong>Advanced discounts (promotions)</strong> applied to the specific product in the order.</td></tr><tr><td>isCustomerSetPrice</td><td>boolean</td><td>If <code>true</code>, customer set a custom product price using the "<a href="https://support.ecwid.com/hc/en-us/articles/360018423259-Pay-What-You-Want-pricing">Pay What You Want</a>" feature. <br><br>In this case, both the product <code>price</code> and <code>selectedPrice</code> -> <code>value</code> fields contain the price set by a customer.<br>If <code>false</code>, customer didn't choose the custom price. Therefore, the <code>selectedPrice</code> -> <code>value</code> field will be absent and the <code>price</code> field contains default product price set by the store owner.</td></tr><tr><td>selectedPrice</td><td>object selectedPrice > value</td><td><p>If <code>isCustomerSetPrice</code> is <code>true</code>, this field contains the "<a href="https://support.ecwid.com/hc/en-us/articles/360018423259-Pay-What-You-Want-pricing">Pay What You Want</a>" price set by a customer at the checkout.</p><p>Example with the PWYW price set to 100:<br><code>"selectedPrice": { "value": 100 }</code></p></td></tr><tr><td>attributes</td><td>array of objects <a href="#attributes">attributes</a></td><td>Details about product attributes.<br><br>Read more on product attributes in <a href="https://support.ecwid.com/hc/en-us/articles/207807495-Product-types-and-attributes">Help Center</a>.</td></tr></tbody></table>

#### attributes

| Field | Type   | Description                    |
| ----- | ------ | ------------------------------ |
| name  | string | Name of the product attribute. |
| value | string | Attribute value.               |

#### files

| Field | Type   | Description                                                       |
| ----- | ------ | ----------------------------------------------------------------- |
| id    | number | Internal unique file ID.                                          |
| name  | string | File name visible to the customer.                                |
| size  | number | File size in bytes (64-bit integer).                              |
| url   | string | File download link sent to the customer after the order was paid. |

#### selectedOptions

<table><thead><tr><th width="224">Field</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td>name</td><td>string</td><td>Name of the product option.</td></tr><tr><td>nameTranslated</td><td>object <a href="#translations">translations</a></td><td>Available translations for product option name.</td></tr><tr><td>type</td><td>string</td><td>Type of the product option that defines its functionality. <br><br>One of:<br><code>CHOICE -</code> Dropdown, radio button, or size. Allows selecting only one value from the list.<br><code>CHOICES -</code> Checkbox. Allows selecting multiple values.<br><code>TEXT -</code> Text input or area.<br><code>DATE -</code> Datetime selector.<br><code>FILES -</code> Upload file option.</td></tr><tr><td>value</td><td>string</td><td>Selected/entered value for the option as <code>string</code>. <br><br>For <code>CHOICES</code> type, provides a string with all selected values separated by a comma.</td></tr><tr><td>valueTranslated</td><td>object <a href="#translations">translations</a></td><td>Available translations for the product option value.</td></tr><tr><td>valuesArray</td><td>array</td><td><p>Selected/entered value for the option as <code>array</code>. </p><p></p><p>For the <code>CHOICES</code> type, provides an array with all selected values.</p></td></tr><tr><td>valuesArrayTranslated</td><td>object <a href="#translations">translations</a></td><td>Available translations for the product options values array.</td></tr><tr><td>files</td><td>array of objects <a href="#files">files</a></td><td>Detailed information about files attached to the selected option.<br><br>Available only if the option type is <code>FILES.</code></td></tr><tr><td>selections</td><td>array of objects <a href="#selections">selections</a></td><td>Details of selected product options. <br><br>If sent in "Update order" request, other fields will be recalculated based on information from <code>selections</code>.</td></tr></tbody></table>

#### selections

<table><thead><tr><th width="221">Field</th><th width="153">Type</th><th>Description</th></tr></thead><tbody><tr><td>selectionTitle</td><td>string</td><td>Name of the selected option value.</td></tr><tr><td>selectionModifier</td><td>number</td><td>Price modifier of the selected option value. <br><br>Value can be negative, for example, <code>-10</code> if it decreases the product price.</td></tr><tr><td>selectionModifierType</td><td>string</td><td>Price modifier type.<br><br>One of: <br><code>PERCENT</code> - Price modifier applies as a percent from the product price.<br><code>ABSOLUTE</code> - Price modifier applies as a flat value.</td></tr></tbody></table>

#### dimensions

| Field  | Type   | Description         |
| ------ | ------ | ------------------- |
| length | number | Length of a product |
| width  | number | Width of a product  |
| height | number | Height of a product |

#### discounts

| Field        | Type                                           | Description                                                               |
| ------------ | ---------------------------------------------- | ------------------------------------------------------------------------- |
| discountInfo | array of objects [discountInfo](#discountinfo) | Details about **advanced discounts (promotions)** applied to the product. |
| total        | number                                         | Sum of **advanced discounts (promotions)** applied to the order.          |

#### discountInfo

<table><thead><tr><th width="189">Field</th><th width="168">Type</th><th>Description</th></tr></thead><tbody><tr><td>value</td><td>number</td><td>Discount value.</td></tr><tr><td>type</td><td>string</td><td>Discount type.<br><br>One of: <br><code>PERCENT</code> - Price modifier applies as a percent from the product price.<br><code>ABS</code> - Price modifier applies as a flat value.</td></tr><tr><td>base</td><td>string</td><td><p>Discount base. <br><br>One of: <br><code>SUBTOTAL</code>  - Discount is based on order subtotal.</p><p><code>ITEM</code>   - Discount is only applied to certain products in the order.</p><p><code>SHIPPING</code>   - Discount is only applied to order shipping costs.</p><p><code>ON_MEMBERSHIP</code>   - Discount is only applied if the customer belongs to a certain customer group.</p><p><code>ON_TOTAL_AND_MEMBERSHIP</code> - Discount is applied when customer group and order subtotal conditions are met (order must meet both <code>SUBTOTAL</code> and <code>ON_MEMBERSHIP</code>).</p><p><code>CUSTOM</code>  - Discount is added by an app with custom logic.</p></td></tr><tr><td>orderTotal</td><td>number</td><td>Minimum order subtotal value for the advanced discount to apply.</td></tr><tr><td>description</td><td>string</td><td>Description the store owner added for the advanced discount.</td></tr><tr><td>appliesToItems</td><td>array of numbers</td><td>List of product IDs advanced discount apply to. For example, <code>[123456, 234567]</code>.<br><br>If specified, the discount can't apply to all other products.</td></tr></tbody></table>

#### discountCoupon

<table><thead><tr><th width="211">Field</th><th width="190">Type</th><th>Description</th></tr></thead><tbody><tr><td>id</td><td>number</td><td>Internal discount coupon ID.</td></tr><tr><td>name</td><td>string</td><td>Name of the discount coupon visible in Ecwid admin.</td></tr><tr><td>code</td><td>string</td><td>Discount coupon code.</td></tr><tr><td>discountType</td><td>string</td><td>Discount type.<br><br>One of: <br><code>ABS</code><br><code>PERCENT</code><br><code>SHIPPING</code><br><code>ABS_AND_SHIPPING</code><br><code>PERCENT_AND_SHIPPING</code></td></tr><tr><td>status</td><td>string</td><td>Discount coupon state.<br><br>One of:<br><code>ACTIVE</code><br><code>PAUSED</code><br><code>EXPIRED</code><br><code>USEDUP</code></td></tr><tr><td>discount</td><td>number</td><td>Discount value applied to the order total.</td></tr><tr><td>launchDate</td><td>string</td><td>The date of coupon launch, for example, <code>2014-06-06 08:00:00 +0000</code>.</td></tr><tr><td>expirationDate</td><td>string</td><td>Coupon expiration date, for example, <code>2014-06-06 08:00:00 +0000</code>.</td></tr><tr><td>totalLimit</td><td>number</td><td>The minimum order subtotal the coupon applies to.</td></tr><tr><td>usesLimit</td><td>string</td><td>Number of uses limitation: <code>UNLIMITED</code>, <code>ONCEPERCUSTOMER</code>, <code>SINGLE</code></td></tr><tr><td>applicationLimit</td><td>string</td><td>Application limit for discount coupons.<br><br>One of:<br><code>UNLIMITED</code><br><code>NEW_CUSTOMER_ONLY</code><br><code>REPEAT_CUSTOMER_ONLY</code></td></tr><tr><td>creationDate</td><td>string</td><td>Discount coupon creation date.</td></tr><tr><td>updateDate</td><td>string</td><td>Date of the last discount coupon update.</td></tr><tr><td>orderCount</td><td>number</td><td>Amount of orders where the discount coupon was used previously.</td></tr><tr><td>catalogLimit</td><td>object <a href="#cataloglimit">catalogLimit</a></td><td>Products and categories the coupon can be applied to</td></tr></tbody></table>

#### catalogLimit

| Field      | Type             | Description                                        |
| ---------- | ---------------- | -------------------------------------------------- |
| products   | array of numbers | List of product IDs the coupon can be applied to.  |
| categories | array of numbers | List of category IDs the coupon can be applied to. |

#### handlingFee

| Field       | Type   | Description                                                    |
| ----------- | ------ | -------------------------------------------------------------- |
| name        | string | Handling fee name set by store admin, for example, `Wrapping`. |
| value       | number | Handling fee flat value.                                       |
| description | string | Handling fee's description for customers.                      |

#### extraFields

| Field                                         | Type   | Description                                                                                             |
| --------------------------------------------- | ------ | ------------------------------------------------------------------------------------------------------- |
| ecwid\_order\_delivery\_time\_interval\_start | string | Start of the delivery date/datetime interval.                                                           |
| ecwid\_order\_delivery\_time\_interval\_end   | string | End of the delivery date/datetime interval.                                                             |
| ecwid\_order\_delivery\_time\_display\_format | string | <p>Format of the delivery date chosen.<br><br>One of:<br><code>DATE</code><br><code>DATETIME</code></p> |

#### orderExtraFields

| Field                      | Type   | Description                                                                                                                                                                                                                                                                                |
| -------------------------- | ------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| id                         | string | Internal ID defined for the checkout extra field.                                                                                                                                                                                                                                          |
| value                      | string | Extra field value. Length cannot exceed 255 characters.                                                                                                                                                                                                                                    |
| customerInputType          | string | One of: `""`,`"TEXT"`, `"SELECT"`, `"DATETIME"`                                                                                                                                                                                                                                            |
| title                      | string | Extra field title visible at the checkout.                                                                                                                                                                                                                                                 |
| orderDetailsDisplaySection | string | <p>Defines a place where the field is visible to the store admin on the order details page. <br><br>One of:<br><code>shipping\_info</code> </p><p><code>billing\_info</code></p><p><code>customer\_info</code></p><p><code>order\_comments</code><br><br>Empty if the field is hidden.</p> |
| orderBy                    | string | Extra field position. Use it to sort fields within the same `orderDetailsDisplaySection`                                                                                                                                                                                                   |

#### predictedPackages

| Name          | Type   | Description                                                          |
| ------------- | ------ | -------------------------------------------------------------------- |
| height        | number | Height of a predicted package                                        |
| width         | number | Width of a predicted package                                         |
| length        | number | Length of a predicted package                                        |
| weight        | number | Total weight of a predicted package                                  |
| declaredValue | number | Declared value of a predicted package (subtotal of items in package) |

#### shippingAddress

| Name                | Type   | Description                                |
| ------------------- | ------ | ------------------------------------------ |
| street              | string | Customer's street                          |
| city                | string | Customer's city                            |
| countryCode         | string | Customer's country code in Ecwid           |
| countryName         | string | Customer's country name in Ecwid           |
| postalCode          | string | Customer's postal code                     |
| stateOrProvinceCode | string | Customer's state or province code in Ecwid |
| stateOrProvinceName | string | Customer's state or province name in Ecwid |

#### originAddress

| Name                | Type   | Description                                |
| ------------------- | ------ | ------------------------------------------ |
| street              | string | Customer's street                          |
| city                | string | Customer's city                            |
| countryCode         | string | Customer's country code in Ecwid           |
| postalCode          | string | Customer's postal code                     |
| stateOrProvinceCode | string | Customer's state or province code in Ecwid |

#### translations

Object with text field translations in the `"lang": "text"` format, where the `"lang"` is an ISO 639-1 language code. For example:

```
{
    "en": "Sample text",
    "nl": "Voorbeeldtekst"
}
```

Translations are available for all active store languages. Only the default language translations are returned if no other translations are provided for the field. Find active store languages with <mark style="color:green;">`GET`</mark> `/profile` request > `languages` > `enabledLanguages`.

### Respond with discounts

With the cart details, you can calculate discounts using your own logic and conditions. Ecwid doesn't have access to this part of discount processing.

However, your response must meet API requirements. Discount details must be sent as a response to the initial request in a JSON format in 5 seconds or less.

{% hint style="info" %}
Respond with several different discounts limited to different products to create complex logic.
{% endhint %}

<details>

<summary>Response JSON example</summary>

```json
{
    "discounts": [
        {
          "value": 20,
          "type": "ABSOLUTE",
          "description": "T-shirt for free for orders over $100",
          "appliesToProducts": [45723490,35498525]
        },
        {
          "value": 10,
          "type": "PERCENT",
          "description": "10% off. Thanks for liking us on Facebook!"
        }
    ]
}
```

</details>

Response must contain a JSON object with the following fields:

<table><thead><tr><th width="190">Name</th><th width="181">Type</th><th>Description</th></tr></thead><tbody><tr><td>value</td><td>number</td><td>Discount amount.<br><br><strong>Required</strong></td></tr><tr><td>type</td><td>number</td><td><p>Discount type.<br><br>One of: </p><p><code>ABSOLUTE</code></p><p><code>PERCENT</code> </p><p></p><p>If not specified, discount is applied as <code>ABSOLUTE</code>.</p></td></tr><tr><td>description</td><td>string</td><td>Discount description displayed to the customer at the checkout and later in order receipts.</td></tr><tr><td>appliesToProducts</td><td>array of numbers</td><td><p>Limit discount application to specific products by their IDs.</p><p></p><p>If it's empty or not specified, the discount will be evenly spread between all products in the cart.</p></td></tr></tbody></table>
