> For the complete documentation index, see [llms.txt](https://sandbox-doc.gitbook.io/ottu-team-sandbox-doc/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://sandbox-doc.gitbook.io/ottu-team-sandbox-doc/user-guide-proposal/features/smart-router-engine/smart-router-functionality.md).

# Smart Router Functionality

Practical demonstration of smart router functionality.

In this example, we will create a Smart Router instance that utilizes the [Transaction Size Strategy](#transaction-size-strategy-multi-selection). The following steps will demonstrate how to configure the Smart Router and define the criteria for selected MIDs, specifically `MPGS` and  `Knet` MIDs.

### **Step 1: Create a Smart Router Instance**

Navigate to the **PGSR** (Smart Router section) in the **Administration Panel** and click on the **Add Smart Router** button. Fill in the required details as shown in the figure below:

**Smart Router Configuration:**

* **Name:** Smart Router Example
* **Is Active:** Yes
* **Code Identifier:** smart\_router\_example
* **Strategies:** Transaction Size Strategy

<figure><img src="https://content.gitbook.com/content/uvuyQluEi5QMHcp2TcU7/blobs/cNAdeU0m46cM5qB7kg8n/image.png" alt=""><figcaption></figcaption></figure>

### **Step 2: Define Criteria for Selected MIDs**

Since we are using the [Transaction Size Strategy](#transaction-size-strategy-multi-selection), the criteria for this strategy must be defined for each selected MID. The figure below shows the criteria defined for `MPGS` and `Knet` MIDs:

**Knet MID Criteria:**

* **Minimum Amount:** 1
* **Maximum Amount:** 50

**MPGS MID Criteria:**

* **Minimum Amount:** 51
* **Maximum Amount:** 100

<figure><img src="https://content.gitbook.com/content/uvuyQluEi5QMHcp2TcU7/blobs/BYdDBxRTZ13o2BIP4zUg/image.png" alt=""><figcaption></figcaption></figure>

### **Step 3: Create a Checkout Link Using Checkout API**

Using the [Checkout API](broken://pages/w6x1vl3nTj166uTuqUyg), we will create a checkout link. Below is the payload request for creating the checkout link:

```json
{
    "type": "payment_request",
    "pg_codes": ["smart-router-example"],
    "amount": "55",
    "currency_code": "KWD"
}
```

The generated checkout link will redirect to the **Checkout Page** where the customer will click on the **Pay** button.

<figure><img src="https://content.gitbook.com/content/uvuyQluEi5QMHcp2TcU7/blobs/6ti6Jv0qyvR7lnyI4K3L/image.png" alt=""><figcaption></figcaption></figure>

### **Step 4: Payment Processing with Smart Router**

Once the pay button is clicked, the Smart Router starts functioning to choose the best path between the two chosen MIDs (**MPGS** and **Knet**). The path selection is based on the defined criteria.

As shown in the figure below, the chosen MID is **MPGS** since the transaction amount is 55, which falls within the range of the defined **MPGS** criteria.

<figure><img src="https://content.gitbook.com/content/uvuyQluEi5QMHcp2TcU7/blobs/fY9YhAzafqe0j8KOYIZV/image.png" alt=""><figcaption></figcaption></figure>

If we change the amount in the request payload to be 50.

```json
{
    "type": "payment_request",
    "pg_codes": ["smart-router-example"],
    "amount": "50",
    "currency_code": "KWD"
}
```

The Smart Router will choose Knet since the defined range covers the amount, as shown in the figure below:

<figure><img src="https://content.gitbook.com/content/uvuyQluEi5QMHcp2TcU7/blobs/gM0Mmku4QAOldCHJYhgs/image.png" alt=""><figcaption></figcaption></figure>

**Conclusion**

By following these steps, we demonstrated how to create a Smart Router instance using the [Transaction Size Strategy](/ottu-team-sandbox-doc/user-guide-proposal/features/smart-router-engine/transaction-size-strategy-scenario.md) and defined criteria for `MPGS` and `Knet` MIDs. This example illustrates how the Smart Router dynamically selects the most appropriate payment gateway based on the transaction amount, optimizing the payment processing workflow and enhancing overall efficiency.
