> For the complete documentation index, see [llms.txt](https://apidocs.akinon.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://apidocs.akinon.com/flows/basket-offer-flows.md). Agents can also search and read this documentation through its [MCP server](https://apidocs.akinon.com/~gitbook/mcp).

# Basket Offer Flows

This document provides a detailed explanation of the basket offer flows, including the purpose of the flow, the services involved, and the description of each field in the requests and responses.

{% hint style="warning" %}
The request and response structures described in this document are for API version v2. In version v1, the structures were different. To use the v2 structure (either by migrating from v1 or for new integrations), you must set `"api_version": "v2"` in your PromotionGateway configuration.
{% endhint %}

**Example configuration:**

```json
{
  "auth": {
    "password": "xx",
    "username": "xxx"
  },
  "urls": {
    "base_url": "xxx",
    "query_offers": "xxx"
  },
  "klass": "omnishop.promotions.backend.extension.service.ExtensionService",
  "api_version": "v2"
}
```

**Optional configuration:**

| Key                          | Type    | Default | Description                                                                                                                                                                     |
| ---------------------------- | ------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `voucher_code_from_response` | Boolean | `false` | v2 only. When `true`, the voucher code is attached only to the offers whose `voucherCode` matches the code sent in `basket.voucherCode`. See the Voucher Code Handling section. |

## <mark style="color:red;">Purpose of the Flow</mark>

The Basket Offer Flow is designed to integrate with third-party systems to retrieve and apply discount offers to a customer's shopping basket. This flow ensures that the basket's current state, including its items and any existing discounts, is sent to the third-party system. The third-party system evaluates the basket and returns applicable offers, which are then applied to the basket before proceeding to the payment stage. This flow is particularly useful for:

* **Dynamic Discount Calculation:** Allowing third-party systems to calculate discounts based on the basket's contents.
* **Custom Promotions:** Supporting external promotion engines to provide tailored offers.
* **Scalability:** Standardizing the integration with multiple third-party systems using a consistent API pattern.

This part of the document contains the list of services that can be integrated in flows above. 2 configuration parameters will be shared during integration:

| Field    | Description                       |
| -------- | --------------------------------- |
| username | Username for basic authentication |
| password | Password for basic authentication |

## <mark style="color:red;">basket-offers (POST)</mark>

This service is used to retrieve discount offers for a customer's basket from a third-party system. It sends the current state of the basket and user information to the third-party system and receives applicable offers in response.

**URL:**

```
^^/offers
```

**Request Headers**

| Header                  | Description                                                 | Requirement |
| ----------------------- | ----------------------------------------------------------- | ----------- |
| x-akinon-request-id     | Unique ID for problem solving & tracing.                    | Mandatory   |
| x-akinon-api-version    | Akinon Customer API version.                                | Mandatory   |
| x-app-device            | Client/session type (e.g. `default`, `android`, `instore`). | Mandatory   |
| x-store-id              | Store identifier (when available).                          | Optional    |
| x-store-remote-id       | Remote store identifier (when available).                   | Optional    |
| x-store-staff-id        | Staff user identifier (when available).                     | Optional    |
| x-store-staff-remote-id | Remote staff user identifier (when available).              | Optional    |
| x-store-staff-email     | Staff user email address (when available).                  | Optional    |
| Authorization           | Basic \[BASE64\_encoded(username:password)]                 | Mandatory   |

**Request Body Structure**

| Field                                                                                       | Type        | Description                                                                                                      |
| ------------------------------------------------------------------------------------------- | ----------- | ---------------------------------------------------------------------------------------------------------------- |
| basket                                                                                      | Object      | Container for basket information                                                                                 |
| basket.id                                                                                   | Number      | Unique identifier for the basket                                                                                 |
| basket.version                                                                              | Number      | Version of the basket to ensure consistency                                                                      |
| basket.voucherCode                                                                          | String/Null | Voucher or coupon code (optional)                                                                                |
| basket.basketItems                                                                          | Array       | List of items in the basket                                                                                      |
| basket.basketItems\[].id                                                                    | Number      | Unique identifier for the basket item                                                                            |
| basket.basketItems\[].unitPrice                                                             | String      | Price per unit of the item                                                                                       |
| basket.basketItems\[].retailPrice                                                           | String/Null | Retail (list) price of the product before any discount; null if not available                                    |
| basket.basketItems\[].quantity                                                              | Number      | Quantity of the item in the basket                                                                               |
| basket.basketItems\[].unitType                                                              | String      | Type of unit (e.g., QUANTITY, KILOGRAM)                                                                          |
| basket.basketItems\[].taxRate                                                               | String      | Tax rate applied to the item                                                                                     |
| basket.basketItems\[].totalAmount                                                           | String      | Total price of the item (unitPrice \* quantity)                                                                  |
| basket.basketItems\[].discountAmount                                                        | String      | Total discount applied to the item                                                                               |
| basket.basketItems\[].globallyConsumedQuantity                                              | String      | Quantity consumed globally for discounts (decimal value as string)                                               |
| basket.basketItems\[].currencyType                                                          | String      | Currency code (ISO 4217)                                                                                         |
| basket.basketItems\[].appliedDiscounts                                                      | Array       | List of discounts applied to this item                                                                           |
| basket.basketItems\[].appliedDiscounts\[].discount                                          | Object      | Discount details                                                                                                 |
| basket.basketItems\[].appliedDiscounts\[].discount.type                                     | String      | Type of discount (LOYALTY\_POINT, SAMPLE\_PRODUCT, DEFERRED, POINT, SHIPPING, BASKET)                            |
| basket.basketItems\[].appliedDiscounts\[].discount.description                              | String      | Description of the discount                                                                                      |
| basket.basketItems\[].appliedDiscounts\[].discount.discountedBasketItems                    | Array       | Items to which the discount will be applied and distributed based on quantity                                    |
| basket.basketItems\[].appliedDiscounts\[].discount.discountedBasketItems\[].pk              | Number      | Primary key of the basket item                                                                                   |
| basket.basketItems\[].appliedDiscounts\[].discount.discountedBasketItems\[].quantity        | String      | Quantity of the item affected by the discount (decimal value as string)                                          |
| basket.basketItems\[].appliedDiscounts\[].discount.conditionConsumedBasketItems             | Array       | Items consumed to meet discount conditions; no additional items are consumed once offer conditions are satisfied |
| basket.basketItems\[].appliedDiscounts\[].discount.conditionConsumedBasketItems\[].pk       | Number      | Primary key of the basket item                                                                                   |
| basket.basketItems\[].appliedDiscounts\[].discount.conditionConsumedBasketItems\[].quantity | String      | Quantity consumed for the discount (decimal value as string)                                                     |
| basket.basketItems\[].appliedDiscounts\[].discount.extraArgs                                | Object      | Additional arguments for the discount                                                                            |
| basket.basketItems\[].product                                                               | Object      | Product information                                                                                              |
| basket.basketItems\[].product.id                                                            | Number      | Unique identifier for the product                                                                                |
| basket.basketItems\[].product.sku                                                           | String      | Stock Keeping Unit of the product                                                                                |
| basket.basketItems\[].product.name                                                          | String      | Name of the product                                                                                              |
| basket.basketItems\[].product.attributes                                                    | Object      | Additional attributes of the product                                                                             |
| user                                                                                        | Object      | User information                                                                                                 |
| user.emailAllowed                                                                           | Boolean     | Whether the user allows email communication                                                                      |
| user.smsAllowed                                                                             | Boolean     | Whether the user allows SMS communication                                                                        |
| user.callAllowed                                                                            | Boolean     | Whether the user allows phone calls                                                                              |
| user.phone                                                                                  | String/Null | User's phone number                                                                                              |
| user.email                                                                                  | Array       | List of user's email addresses                                                                                   |
| shippingOption                                                                              | Object/Null | Selected shipping option. Null until a shipping option is selected during checkout.                              |
| shippingOption.id                                                                           | Number      | Unique identifier for the shipping option                                                                        |
| shippingOption.name                                                                         | String      | Name of the shipping option                                                                                      |
| shippingOption.slug                                                                         | String      | Slug of the shipping option                                                                                      |
| shippingOption.amount                                                                       | String/Null | Shipping fee for the selected shipping option (decimal value as string)                                          |
| address                                                                                     | Object/Null | Selected shipping address. Null until an address is selected during checkout.                                    |
| address.id                                                                                  | Number      | Unique identifier for the address                                                                                |
| address.city                                                                                | Object/Null | City of the address (`id`, `name`)                                                                               |
| address.township                                                                            | Object/Null | Township of the address (`id`, `name`)                                                                           |
| address.district                                                                            | Object/Null | District of the address (`id`, `name`)                                                                           |
| address.country                                                                             | Object/Null | Country of the address (`id`, `name`)                                                                            |
| address.line                                                                                | String      | Street line of the address                                                                                       |
| address.postcode                                                                            | String/Null | Postal code of the address                                                                                       |
| paymentOption                                                                               | Object/Null | Selected payment option. Null until a payment option is selected during checkout.                                |
| paymentOption.id                                                                            | Number      | Unique identifier for the payment option                                                                         |
| paymentOption.name                                                                          | String      | Name of the payment option                                                                                       |
| paymentOption.slug                                                                          | String      | Slug of the payment option                                                                                       |

**Request Body Example**

```json
{
    "basket": {
      "id": 32,
      "version": 1758310922044282,
      "voucherCode": null,
        "basketItems": [
            {
                "id": 59,
                "unitPrice": "500.00",
                "retailPrice": "600.00",
                "quantity": 1,
                "unitType": "QUANTITY",
                "taxRate": "20.00",
                "totalAmount": "500.00",
                "discountAmount": "0.00",
                "globallyConsumedQuantity": "0.0",
                "currencyType": "TRY",
                "appliedDiscounts": [
                    {
                        "discount": {
                            "type": "BASKET",
                            "description": "Internal Offer",
                            "discountedBasketItems": [
                                {
                                    "pk": 59,
                                    "quantity": "1"
                                },
                                {
                                    "pk": 58,
                                    "quantity": "7"
                                }
                            ],
                            "conditionConsumedBasketItems": [
                                {
                                    "pk": 58,
                                    "quantity": "0.2"
                                }
                            ],
                            "extraArgs": {
                                "discount": "0.00"
                            },
                        }
                    }
                ],
                "product": {
                    "id": 100009,
                    "sku": "SKU8",
                    "name": "Test Product 8",
                    "attributes": {}
                }
            },
            {
                "id": 58,
                "unitPrice": "500.00",
                "retailPrice": null,
                "quantity": 7,
                "unitType": "QUANTITY",
                "taxRate": "20.00",
                "totalAmount": "3500.00",
                "discountAmount": "12.32",
                "globallyConsumedQuantity": "0.0",
                "currencyType": "TRY",
                "appliedDiscounts": [
                    {
                        "discount": {
                            "type": "BASKET",
                            "description": "Internal Offer",
                            "discountedBasketItems": [
                                {
                                    "pk": 59,
                                    "quantity": "1"
                                },
                                {
                                    "pk": 58,
                                    "quantity": "7"
                                }
                            ],
                            "conditionConsumedBasketItems": [
                                {
                                    "pk": 58,
                                    "quantity": "0.2"
                                }
                            ],
                            "extraArgs": {
                                "discount": "12.32"
                            },
                        }
                    }
                ],
                "product": {
                    "id": 100010,
                    "sku": "SKU9",
                    "name": "Test Product 9",
                    "attributes": {}
                }
            }
        ]
    },
    "user": {
        "emailAllowed": true,
        "smsAllowed": true,
        "callAllowed": false,
        "phone": null,
        "email": []
    },
    "shippingOption": {
        "id": 3,
        "name": "Standard Shipping",
        "slug": "standard-shipping",
        "amount": "29.90"
    },
    "address": {
        "id": 145,
        "city": {
            "id": 34,
            "name": "Istanbul"
        },
        "township": {
            "id": 512,
            "name": "Kadikoy"
        },
        "district": {
            "id": 2043,
            "name": "Moda"
        },
        "country": {
            "id": 1,
            "name": "Turkey"
        },
        "line": "Example street No: 1",
        "postcode": "34710"
    },
    "paymentOption": {
        "id": 7,
        "name": "Credit Card",
        "slug": "credit-card"
    }
}
```

### <mark style="color:red;">**Discount Types Extra Args**</mark>

The following discount types and their associated extra arguments are supported:

#### **Loyalty Point Extra Args**

<table><thead><tr><th width="250.0703125">Field</th><th width="86.8203125">Type</th><th>Description</th></tr></thead><tbody><tr><td>loyaltyData</td><td>Object</td><td>Loyalty point information</td></tr><tr><td>loyaltyData.amount</td><td>String</td><td>Amount of loyalty points used (decimal value as string)</td></tr><tr><td>loyaltyData.benefitCoefficient</td><td>String</td><td>Coefficient for calculating benefits</td></tr><tr><td>loyaltyData.validFrom</td><td>String</td><td>Start date of the loyalty points</td></tr><tr><td>loyaltyData.validUntil</td><td>String</td><td>Expiration date of the loyalty points</td></tr></tbody></table>

```json
{
  "extraArgs": {
    "loyaltyData": {
      "amount": "50.00",
      "benefitCoefficient": "1.5",
      "validFrom": "2025-01-01",
      "validUntil": "2025-12-31"
    }
  }
}
```

#### **Sample Product Extra Args**

<table><thead><tr><th width="184.05859375">Field</th><th width="97.14453125">Type</th><th>Description</th></tr></thead><tbody><tr><td>sampleProducts</td><td>Array</td><td>List of sample products</td></tr><tr><td>sampleProducts[].id</td><td>Number</td><td>Unique identifier for the sample product</td></tr><tr><td>allowedQuantity</td><td>Number</td><td>Maximum quantity allowed for the sample product</td></tr></tbody></table>

```json
{
  "extraArgs": {
    "sampleProducts": [
      {
        "id": 12345
      },
      {
        "id": 67890
      }
    ],
    "allowedQuantity": 2
  }
}
```

#### **Deferred Extra Args**

<table><thead><tr><th width="157.98046875">Field</th><th width="129.91015625">Type</th><th>Description</th></tr></thead><tbody><tr><td>data</td><td>Object</td><td>Deferred discount data</td></tr><tr><td>data.coupon</td><td>String</td><td>Coupon code for the deferred discount</td></tr></tbody></table>

```json
{
  "extraArgs": {
    "data": {
      "coupon": "SAVE2025"
    }
  }
}
```

#### **Point Extra Args**

No additional arguments required.

```json
{
  "extraArgs": {}
}
```

#### **Shipping Extra Args**

No additional arguments required.

```json
{
  "extraArgs": {}
}
```

#### **Basket Extra Args**

<table><thead><tr><th width="101.16796875">Field</th><th width="93.4609375">Type</th><th>Description</th></tr></thead><tbody><tr><td>discount</td><td>String</td><td>Total discount applied to the basket (decimal value as string)</td></tr></tbody></table>

```json
{
  "extraArgs": {
    "discount": "25.50"
  }
}
```

**Request Body (typescript interface)**

```ts
interface BasketOffersRequest {
  basket: Basket;
  user: User;
  shippingOption: ShippingOption | null;
  address: Address | null;
  paymentOption: PaymentOption | null;
}

interface ShippingOption {
  id: number;
  name: string;
  slug: string;
  amount: string | null;
}

interface PaymentOption {
  id: number;
  name: string;
  slug: string;
}

interface NamedRef {
  id: number;
  name: string;
}

interface Address {
  id: number;
  city: NamedRef | null;
  township: NamedRef | null;
  district: NamedRef | null;
  country: NamedRef | null;
  line: string;
  postcode: string | null;
}

interface Basket {
  id: number;
  version: number;
  voucherCode: string | null;
  basketItems: BasketItem[];
}

interface BasketItem {
  id: number;
  unitPrice: string;
  retailPrice: string | null;
  quantity: number;
  unitType: string;
  taxRate: string;
  totalAmount: string;
  discountAmount: string;
  globallyConsumedQuantity: string;
  currencyType: string;
  appliedDiscounts: AppliedDiscount[];
  product: Product;
}

interface AppliedDiscount {
  discount: Discount;
}

interface BaseDiscount {
  type: 'LOYALTY_POINT' | 'SAMPLE_PRODUCT' | 'DEFERRED' | 'POINT' | 'SHIPPING' | 'BASKET';
  description: string;
  discountedBasketItems: DiscountedBasketItem[];
  conditionConsumedBasketItems: ConditionConsumedBasketItem[];
}

type Discount =
  | (BaseDiscount & { type: 'LOYALTY_POINT'; extraArgs: LoyaltyPointArgs })
  | (BaseDiscount & { type: 'SAMPLE_PRODUCT'; extraArgs: SampleProductArgs })
  | (BaseDiscount & { type: 'DEFERRED'; extraArgs: DeferredArgs })
  | (BaseDiscount & { type: 'POINT'; extraArgs?: undefined })
  | (BaseDiscount & { type: 'SHIPPING'; extraArgs?: undefined })
  | (BaseDiscount & { type: 'BASKET'; extraArgs: BasketArgs });

interface LoyaltyPointArgs {
  loyaltyData: {
    amount: string;
    benefitCoefficient: string;
    validFrom: string; 
    validUntil: string;
  };
}

interface SampleProductArgs {
  sampleProducts: {
    id: number;
  }[];
  allowedQuantity: number;
}

interface DeferredArgs {
  data: {
    coupon: string;
  };
}

interface BasketArgs {
  discount: string;
}

interface DiscountedBasketItem {
  pk: number;
  quantity: string;
}

interface ConditionConsumedBasketItem {
  pk: number;
  quantity: string;
}

interface Product {
  id: number;
  sku: string;
  name: string;
  attributes: Record<string, any>;
}

interface User {
  emailAllowed: boolean;
  smsAllowed: boolean;
  callAllowed: boolean;
  phone: string | null;
  email: string[];
}

```

**Response Body Structure**

| Field                                                 | Type        | Description                                                                                                                                                                                       |
| ----------------------------------------------------- | ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| \[]                                                   | Array       | List of available offers                                                                                                                                                                          |
| \[].notifyAfterOrderCreation                          | Boolean     | Indicates if the offer requires notification after order creation                                                                                                                                 |
| \[].discount                                          | Object      | Discount details                                                                                                                                                                                  |
| \[].discount.id                                       | String      | Unique identifier for the discount                                                                                                                                                                |
| \[].discount.type                                     | String      | Type of discount (LOYALTY\_POINT, SAMPLE\_PRODUCT, DEFERRED, POINT, SHIPPING, BASKET)                                                                                                             |
| \[].discount.description                              | String      | Description of the discount                                                                                                                                                                       |
| \[].discount.discountedBasketItems                    | Array       | Items to which the discount will be applied and distributed based on quantity                                                                                                                     |
| \[].discount.discountedBasketItems\[].pk              | Number      | Primary key of the basket item                                                                                                                                                                    |
| \[].discount.discountedBasketItems\[].quantity        | Number      | Quantity of the item affected by the discount                                                                                                                                                     |
| \[].discount.conditionConsumedBasketItems             | Array       | Items consumed for the discount condition                                                                                                                                                         |
| \[].discount.conditionConsumedBasketItems\[].pk       | Number      | Primary key of the basket item consumed for the discount                                                                                                                                          |
| \[].discount.conditionConsumedBasketItems\[].quantity | Number      | Quantity consumed for the discount                                                                                                                                                                |
| \[].discount.extraArgs                                | Object      | Additional arguments for the discount                                                                                                                                                             |
| \[].priority                                          | Number      | Priority of the discount                                                                                                                                                                          |
| \[].label                                             | String      | Label for the discount                                                                                                                                                                            |
| \[].isMergeable                                       | Boolean     | Indicates if the discount can be combined with other discounts                                                                                                                                    |
| \[].successMessage                                    | String      | Message displayed when the discount is successfully applied                                                                                                                                       |
| \[].upsellMessage                                     | String      | Message encouraging the user to take further actions                                                                                                                                              |
| \[].voucherCode                                       | String/Null | Optional. The voucher code this offer came from. It must be the code sent in `basket.voucherCode`. Used only when `voucher_code_from_response` is enabled; see the Voucher Code Handling section. |

**Response Body Example**

```json
[
    {
        "successMessage": "Congratulations! You saved 25.50 TRY with our Spring Sale promotion.",
        "upsellMessage": "Add 2 more items to your cart and get free shipping!",
        "label": "Spring Sale - 15% Off",
        "priority": 1,
        "discount": {
            "description": "Spring Sale 2025 - 15% Off on Fashion Items",
            "discountedBasketItems": [
                {
                    "pk": 58,
                    "quantity": "1"
                }
            ],
            "extraArgs": {
                "discount": "25.50"
            },
            "conditionConsumedBasketItems": [
                {
                    "pk": 58,
                    "quantity": "1"
                }
            ],
            "type": "BASKET",
            "id": "v2-spring-discount-2025"
        },
        "notifyAfterOrderCreation": false,
        "isMergeable": true,
        "voucherCode": null
    },
    {
        "successMessage": "Thank you for being a loyal customer! You saved 10 TRY with your member discount.",
        "upsellMessage": "Add 2 more items to your cart and get free shipping!",
        "label": "Loyalty Reward - 10 TRY Off",
        "priority": 2,
        "discount": {
            "description": "Loyalty Member Special Discount",
            "discountedBasketItems": [
                {
                    "pk": 59,
                    "quantity": "1"
                }
            ],
            "extraArgs": {
                "discount": "10.00"
            },
            "conditionConsumedBasketItems": [
                {
                    "pk": 59,
                    "quantity": "1"
                }
            ],
            "type": "BASKET",
            "id": "v2-loyalty-reward-2025"
        },
        "notifyAfterOrderCreation": true,
        "isMergeable": true
    }
]
```

**Response Body (typescript interface)**

```ts
type BasketOffersResponse = BasketOffer[];

interface BasketOffer {
  notifyAfterOrderCreation: boolean;
  discount: ResponseDiscount;
  priority: number;
  label: string;
  isMergeable: boolean;
  successMessage: string;
  upsellMessage: string;
  voucherCode?: string | null;
}

interface ResponseDiscount {
  id: string;
  type: 'LOYALTY_POINT' | 'SAMPLE_PRODUCT' | 'DEFERRED' | 'POINT' | 'SHIPPING' | 'BASKET';
  description: string;
  discountedBasketItems: ResponseDiscountedBasketItem[];
  conditionConsumedBasketItems: ResponseConditionConsumedBasketItem[];
  extraArgs?: Record<string, any>;
}

interface ResponseDiscountedBasketItem {
  pk: number;
  quantity: string;
}

interface ResponseConditionConsumedBasketItem {
  pk: number;
  quantity: string;
}


```

## <mark style="color:red;">Voucher Code Handling</mark>

When the customer enters a voucher code, on the basket or at checkout, it is sent in `basket.voucherCode`. Commerce then decides which of the returned offers carry this code:

* A discount that carries the code shows it on the basket, and the code is saved on the order's discount. A discount without the code is saved with the code `extension-promotion`.
* The voucher code is accepted only if at least one applied offer carries it. Otherwise it is rejected as not valid.

Which offers carry the code depends on the `voucher_code_from_response` setting:

| `voucher_code_from_response` | Offers that carry the voucher code                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| ---------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `false` (default)            | All returned offers, unless the code belongs to something else. That is the case when another applied offer uses the code (for example a gift card from another promotion gateway, or a Commerce voucher, coupon or bulk voucher code), or when the code is an active Commerce voucher, coupon or bulk voucher code available to the customer, even one whose conditions are not met. Then none of the offers carry the code. Expired, passive or used Commerce vouchers with the same code do not count. |
| `true` (v2 only)             | Only the offers whose `voucherCode` equals the code sent in `basket.voucherCode`. Offers without `voucherCode`, or with `null`, an empty string or a different code, do not carry it.                                                                                                                                                                                                                                                                                                                     |

{% hint style="warning" %}
Enable `voucher_code_from_response` only after your service returns `voucherCode`. If it is enabled and your offers do not return it, none of them carry the code, so a code that only your service knows is rejected.
{% endhint %}

**Example:** `voucher_code_from_response` is `true` and the request has `basket.voucherCode` set to `"SPRING15"`:

| Offer in the response | `voucherCode` | Carries `SPRING15` |
| --------------------- | ------------- | ------------------ |
| Free Shipping         | not returned  | No                 |
| Spring Sale - 15% Off | `"SPRING15"`  | Yes                |

## <mark style="color:red;">basket-offers-used (POST)</mark>

This service is used to notify the system about the discounts that were applied to the basket. It ensures that the third-party system is informed about the usage of the offers.

**URL:**

```
^^/use-offers
```

**Request Headers**

<table><thead><tr><th width="182.23828125">Header</th><th width="379.40234375">Description</th><th>Requirement</th></tr></thead><tbody><tr><td>x-akinon-request-id</td><td>Unique ID for problem solving &#x26; tracing.</td><td>Mandatory</td></tr><tr><td>x-akinon-api-version</td><td>Akinon Customer API version.</td><td>Mandatory</td></tr><tr><td>x-app-device</td><td>Client/session type (e.g. <code>default</code>, <code>android</code>, <code>instore</code>).</td><td>Mandatory</td></tr><tr><td>x-store-id</td><td>Store identifier (when available).</td><td>Optional</td></tr><tr><td>x-store-remote-id</td><td>Remote store identifier (when available).</td><td>Optional</td></tr><tr><td>x-store-staff-id</td><td>Staff user identifier (when available).</td><td>Optional</td></tr><tr><td>x-store-staff-remote-id</td><td>Remote staff user identifier (when available).</td><td>Optional</td></tr><tr><td>x-store-staff-email</td><td>Staff user email address (when available).</td><td>Optional</td></tr><tr><td>Authorization</td><td>Basic [BASE64_encoded(username:password)]</td><td>Mandatory</td></tr></tbody></table>

**Request Body Structure**

| Field                                                                                       | Type        | Description                                                                                                      |
| ------------------------------------------------------------------------------------------- | ----------- | ---------------------------------------------------------------------------------------------------------------- |
| basket                                                                                      | Object      | Final state of the basket                                                                                        |
| basket.id                                                                                   | Number      | Unique identifier for the basket                                                                                 |
| basket.version                                                                              | Number      | Version of the basket to ensure consistency                                                                      |
| basket.voucherCode                                                                          | String/Null | Voucher or coupon code (optional)                                                                                |
| basket.basketItems                                                                          | Array       | List of items in the basket                                                                                      |
| basket.basketItems\[].id                                                                    | Number      | Unique identifier for the basket item                                                                            |
| basket.basketItems\[].unitPrice                                                             | String      | Price per unit of the item                                                                                       |
| basket.basketItems\[].retailPrice                                                           | String/Null | Retail (list) price of the product before any discount; null if not available                                    |
| basket.basketItems\[].quantity                                                              | Number      | Quantity of the item in the basket                                                                               |
| basket.basketItems\[].unitType                                                              | String      | Type of unit (e.g., QUANTITY, KILOGRAM)                                                                          |
| basket.basketItems\[].taxRate                                                               | String      | Tax rate applied to the item                                                                                     |
| basket.basketItems\[].totalAmount                                                           | String      | Total price of the item (unitPrice \* quantity)                                                                  |
| basket.basketItems\[].discountAmount                                                        | String      | Total discount applied to the item                                                                               |
| basket.basketItems\[].globallyConsumedQuantity                                              | String      | Quantity consumed globally for discounts (decimal value as string)                                               |
| basket.basketItems\[].currencyType                                                          | String      | Currency code (ISO 4217)                                                                                         |
| basket.basketItems\[].appliedDiscounts                                                      | Array       | List of discounts applied to this item                                                                           |
| basket.basketItems\[].appliedDiscounts\[].discount                                          | Object      | Discount details                                                                                                 |
| basket.basketItems\[].appliedDiscounts\[].discount.type                                     | String      | Type of discount (LOYALTY\_POINT, SAMPLE\_PRODUCT, DEFERRED, POINT, SHIPPING, BASKET)                            |
| basket.basketItems\[].appliedDiscounts\[].discount.description                              | String      | Description of the discount                                                                                      |
| basket.basketItems\[].appliedDiscounts\[].discount.discountedBasketItems                    | Array       | Items to which the discount will be applied and distributed based on quantity                                    |
| basket.basketItems\[].appliedDiscounts\[].discount.discountedBasketItems\[].pk              | Number      | Primary key of the basket item                                                                                   |
| basket.basketItems\[].appliedDiscounts\[].discount.discountedBasketItems\[].quantity        | String      | Quantity of the item affected by the discount                                                                    |
| basket.basketItems\[].appliedDiscounts\[].discount.conditionConsumedBasketItems             | Array       | Items consumed to meet discount conditions; no additional items are consumed once offer conditions are satisfied |
| basket.basketItems\[].appliedDiscounts\[].discount.conditionConsumedBasketItems\[].pk       | Number      | Primary key of the basket item                                                                                   |
| basket.basketItems\[].appliedDiscounts\[].discount.conditionConsumedBasketItems\[].quantity | String      | Quantity consumed for the discount (decimal value as string)                                                     |
| basket.basketItems\[].appliedDiscounts\[].discount.extraArgs                                | Object      | Additional arguments for the discount                                                                            |
| basket.basketItems\[].product                                                               | Object      | Product information                                                                                              |
| basket.basketItems\[].product.id                                                            | Number      | Unique identifier for the product                                                                                |
| basket.basketItems\[].product.sku                                                           | String      | Stock Keeping Unit of the product                                                                                |
| basket.basketItems\[].product.name                                                          | String      | Name of the product                                                                                              |
| basket.basketItems\[].product.attributes                                                    | Object      | Additional attributes of the product                                                                             |
| basket.basketItems\[].product.attributes.categoryId                                         | String      | Category id of the product                                                                                       |
| basket.basketItems\[].product.attributes.variantId                                          | String      | Variant id of the product                                                                                        |
| usedDiscounts                                                                               | Array       | List of used discount identifiers                                                                                |
| usedDiscounts\[]                                                                            | String      | Unique identifier for a used discount                                                                            |
| order                                                                                       | Object      | Order information (sent when notifying after order creation)                                                     |
| order.orderNumber                                                                           | String      | Order number                                                                                                     |

**Request Body Example**

```json
{
    "basket": {
        "id": 32,
        "version": 1758199055052632,
        "voucherCode": null,
        "basketItems": [
            {
                "id": 49,
                "unitPrice": "500.00",
                "retailPrice": "600.00",
                "quantity": 1,
                "unitType": "QUANTITY",
                "taxRate": "20.00",
                "totalAmount": "500.00",
                "discountAmount": "0.00",
                "globallyConsumedQuantity": "0.0",
                "currencyType": "TRY",
                "appliedDiscounts": [
                    {
                        "discount": {
                            "type": "basket",
                            "description": "Internal Offer",
                            "discountedBasketItems": [
                                {
                                    "pk": 49,
                                    "quantity": "1"
                                },
                                {
                                    "pk": 47,
                                    "quantity": "1"
                                }
                            ],
                            "conditionConsumedBasketItems": [
                                {
                                    "pk": 47,
                                    "quantity": "1"
                                }
                            ],
                            "extraArgs": {
                                "discount": "12.32"
                            }
                        }
                    }
                ],
                "product": {
                    "id": 100009,
                    "sku": "SKU8",
                    "name": "Test Product 8",
                    "attributes": {
                        "categoryId": "electronics",
                        "variantId": "red-xl"
                    }
                }
            }
        ]
    },
    "usedDiscounts": [
        "v2-spring-discount-2025",
        "v2-loyalty-reward-2025"
    ],
    "order": {
        "orderNumber": "ORD-12345"
    }
}
```

**Request Body (typescript interface)**

```ts
interface BasketOffersUsedRequest {
  basket: Basket; 
  usedDiscounts: string[];
  order: UsedOffersOrder;
}

/** Order information sent when notifying after order creation (e.g. use_loyalty_card_points) */
interface UsedOffersOrder {
  orderNumber: string;
}

interface Basket {
  id: number;
  version: number;
  voucherCode?: string | null;
  basketItems: BasketItem[];
}

interface BasketItem {
  id: number;
  unitPrice: string;
  retailPrice: string | null;
  quantity: number;
  unitType: string;
  taxRate: string;
  totalAmount: string;
  discountAmount: string;
  globallyConsumedQuantity: string;
  currencyType: string;
  appliedDiscounts: AppliedDiscount[];
  product: Product;
}

interface AppliedDiscount {
  discount: Discount;
}

interface Discount {
  type: 'LOYALTY_POINT' | 'SAMPLE_PRODUCT' | 'DEFERRED' | 'POINT' | 'SHIPPING' | 'BASKET';
  description: string;
  discountedBasketItems: DiscountedBasketItem[];
  conditionConsumedBasketItems: ConditionConsumedBasketItem[];
}

interface DiscountedBasketItem {
  pk: number;
  quantity: string;
}

interface ConditionConsumedBasketItem {
  pk: number;
  quantity: string;
}

interface Product {
  id: number;
  sku: string;
  name: string;
  attributes: Record<string, any>;
}

```

**Response Body (raw 200)**

(no body)

**Response Body For Errors (ALL)**

If any errors are encountered in the services, these errors should be reported in the format below, and the list of error codes should be shared with Akinon.

* **Response Body (raw 4xx/5xx json)**

```json
{
    "errors": [
       {
           "code": "",
           "field": "",
           "message": ""
       }
   ]
}
```

* **Response Body (raw 4xx/5xx typescript interface)**

```ts
interface ErrorResponse {
  errors: ErrorItem[];
}

interface ErrorItem {
  code: string;
  field: string;
  message: string;
}
```

## <mark style="color:red;">Changelog</mark>

### Version 2.2.0 - October 22, 2026

#### Added

* **`voucherCode` in `basket-offers` Response**: Each offer can return `voucherCode` (String/Null, optional) to tell which offers came from the voucher code sent in `basket.voucherCode`.
* **`voucher_code_from_response` Configuration**: When set to `true` (v2 only), the voucher code is attached only to the offers whose `voucherCode` matches it. See the Voucher Code Handling section.

#### Changed

* **Voucher Code on Offers**: Offers no longer carry the voucher code when another applied offer uses it, or when it is an active Commerce voucher, coupon or bulk voucher code available to the customer. Previously every offer carried the code, so an unrelated discount could show a gift card or Commerce voucher code, and a Commerce voucher whose conditions were not met could look applied.

### Version 2.1.0 - August 28, 2026

#### Added

* **Checkout Context in `basket-offers` Request**: Added the selected checkout data to the `basket-offers` (POST) request payload so that shipping-, address-, and payment-dependent promotions can be evaluated by the third-party system:

  * `shippingOption` (Object/Null) — selected shipping option (`id`, `name`, `slug`, `amount`), where `amount` is the shipping fee (decimal value as string)
  * `address` (Object/Null) — selected shipping address (`id`, `city`, `township`, `district`, `country`, `line`, `postcode`)
  * `paymentOption` (Object/Null) — selected payment option (`id`, `name`, `slug`)
  * **`retailPrice` Field**: Added `retailPrice` to `basket.basketItems[]` in the request bodies of both `basket-offers` and `basket-offers-used`. It represents the product's retail (list) price before any discount and is nullable when no retail price is available.

  Each field is `null` until the corresponding option is selected during checkout. These fields are added to the `basket-offers` request only; the `basket-offers-used` request is unchanged.

### Version 2.0.0 - September 18, 2025

#### Changed

* **Request/Response Structure**: Removed inline comments from JSON examples and moved field descriptions to structured tables
* **Data Types**: Updated field types to reflect actual implementation:
  * `unitPrice`, `totalAmount`, `discountAmount`, `taxRate` changed from Number to String
  * `discountedBasketItems[].quantity` in request changed from Number to String (decimal values serialized as strings)
  * `conditionConsumedBasketItems[].quantity` in request changed to String format (decimal values serialized as strings)
  * `extraArgs.discount` and `loyaltyData.amount` changed from Number to String (decimal values serialized as strings)
  * `globallyConsumedQuantity` changed from Number to String (decimal values serialized as strings)
* **Field Removal**: Removed `consumedQuantity` field from request bodies as this value is reset when each offer is applied
* **Field Descriptions**: Enhanced descriptions for `discountedBasketItems` and `conditionConsumedBasketItems` for better clarity
* **Product Attributes**: Changed from Array to Object structure
* **User Fields**: Updated nullable fields to properly reflect optional nature
* **Response Format**: Updated examples to match actual API responses

#### Added

* **Field Documentation**: Comprehensive tables describing all request and response fields
* **Real Examples**: Updated request and response examples with actual data from implementation
* **Type Consistency**: Improved type definitions to match actual API behavior

#### Improved

* **Documentation Structure**: Better organization with separate tables for field descriptions
* **Examples**: More realistic and comprehensive JSON examples
* **Type Safety**: Enhanced TypeScript interfaces to match actual implementation


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://apidocs.akinon.com/flows/basket-offer-flows.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
