# Remote Price

The Remote Price feature allows product prices in the basket to be dynamically set at checkout, independently from the predefined price lists. This document provides the technical setup required to enable this feature, including backend configuration, storefront behavior, and how the external service (extension) should operate.

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

* Products must include an attribute named `has_remote_price`.
* The value for this attribute must be the string "true" (not boolean).
* The attribute key can be customized through the **Sales Channels > Sales Channel Settings > Dynamic Setting** `REMOTE_PRICE_ATTRIBUTE_KEY`.

  <div align="left"><figure><img src="https://2911598027-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FlQinVPnOffBiOp126ldR%2Fuploads%2Fgit-blob-d9707ff4da1f5e60838ce6cae4fd6d97d7f944fa%2Fimage.png?alt=media" alt="" width="563"><figcaption></figcaption></figure></div>

{% hint style="warning" %}
Customizing this attribute key is optional. If not customized, the default key **has\_remote\_price** will be used.
{% endhint %}

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

A dynamic configuration named `BASKET_ITEM_REMOTE_PRICE_CLIENT_CONF` must be defined via **Sales Channels > Sales Channel Settings > Dynamic Setting** in the admin panel. This configuration must include both a `url` and `headers` section:

<div align="left"><figure><img src="https://2911598027-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FlQinVPnOffBiOp126ldR%2Fuploads%2Fgit-blob-6ae596c383f91870849f5a5f8c3e66dc859ee14c%2Fimage.png?alt=media" alt="" width="563"><figcaption></figcaption></figure></div>

* The `url` refers to the endpoint of the external service responsible for calculating the product prices dynamically during the checkout step.
* The `headers` section must include necessary authentication information required to authorize the request to the 3rd party service.

This configuration allows the Commerce to send requests to the extension, retrieving updated prices based on business logic.

```json
{
  "headers": {
    "Authorization": "*******"
  },
  "url": "https://3rdparty.service"
}
```

## <mark style="color:red;">Remote Price Flow</mark>

The Remote Price flow is triggered during the normal checkout steps as follows:

1. After **address selection**, the system checks if the basket contains any items with the `has_remote_price` attribute.
2. If such items exist, the next page becomes a hidden **Remote Price calculation** step.
3. The customer does **not** see this page—it’s system-handled and immediately followed by the **shipping method selection**.
4. Commerce sends a POST request to the external service defined in `BASKET_ITEM_REMOTE_PRICE_CLIENT_CONF`.
5. Prices returned in the response are applied into the corresponding basket items.

## `POST` Get Remote Price

**Path**: `https://3rdparty.service`

The extension must expose a **POST** endpoint that accepts the basket and address information in the following format:

#### **Example Request**

```json
{
  "basket": {
    "basket_items": [
      {
        "pk": 4,
        "quantity": 1,
        "currency_type": "TL",
        "product": {
          "sku": "BASE0001REDS",
          "attributes": {
            "has_remote_price": true
          }
        },
        "unit_price": "100.00",
        "total_amount": "100.00",
        "form_data": {}
      }
    ]
  },
  "address": {
    "pk": 1,
    "email": "joe.doe@akinon.com",
    "phone_number": "phone number",
    "first_name": "Joe",
    "last_name": "Doe",
    "country": {
      "pk": 1,
      "is_active": true,
      "name": "Türkiye",
      "code": "TR",
      "translations": null
    },
    "city": {
      "pk": 1,
      "is_active": true,
      "name": "İstanbul",
      "country": 1,
      "translations": null,
      "priority": null,
      "postcode": null
    },
    "line": "address line",
    "title": "Ev",
    "township": {
      "pk": 1,
      "is_active": true,
      "name": "Kadıköy",
      "city": 1,
      "postcode": null,
      "translations": null
    },
    "district": {
      "pk": 1,
      "is_active": true,
      "name": "Moda",
      "city": 1,
      "township": 1,
      "postcode": null,
      "translations": null
    },
    "postcode": "34000",
    "notes": null,
    "company_name": "",
    "tax_office": "",
    "tax_no": "",
    "e_bill_taxpayer": false,
    "hash_data": "135b6352b4d63027a6fa9b7ec3ab43cd",
    "address_type": "customer",
    "retail_store": null,
    "remote_id": null,
    "identity_number": null,
    "extra_field": null,
    "user": {
      "pk": 3,
      "username": "joe.doe",
      "first_name": "Joe",
      "last_name": "Doe",
      "email": "joe.doe@akinon.com",
      "is_active": true,
      "date_joined": "2025-03-24T18:14:14.419000Z",
      "last_login": "2025-04-09T11:22:52.355150Z",
      "email_allowed": false,
      "sms_allowed": false,
      "call_allowed": null,
      "gender": null,
      "attributes": {
        "logged_ip": "127.0.0.1"
      },
      "phone": null,
      "date_of_birth": null,
      "attributes_kwargs": {},
      "user_type": null,
      "modified_date": "2025-03-24T18:14:26.554000Z"
    },
    "is_corporate": false,
    "primary": false
  }
}
```

### Service Behavior

* Only items with the `has_remote_price` attribute set to `true` should be considered.
* The service **must only return items whose prices were updated**.
* The system will retry the request **up to 3 times** if the response is not successful (HTTP 200).
* The timeout is **20 seconds** per request.
* If the service fails or does not return valid data, the basket proceeds with original prices (the order process is not blocked).

#### **Example Response**

```json
{
  "basket": {
    "basket_items": [
      {
        "pk": 4,
        "unit_price": 200,
        "currency_type": "try"
      }
    ]
  },
}
```

When placing the order, the final unit price for each order item is determined by the `unit_price` parameter in the response.
