# Paying Out

By following these steps, you can seamlessly integrate a instant payout function via DuitNow network to any bank and e-wallet account holder in Malaysia.

## Authentication

LeanX uses **Auth Token** to authenticate in each request's header.

{% hint style="info" %}
**Auth Token** can be retrieved in your portal dashboard under **API** page.
{% endhint %}

**Request Header**

{% code overflow="wrap" %}

```json
{
    "auth-token": "LP-0D7C06DE-MM|7394e58e-edee-4c42-9ca5-bcbc449f1b9f|2141df4a3cb633d5ce8683bb0c55067e5caebfbe07390dde277dc455bcc95c91723a81b5e565c7c02d68fb84e396722563016bf99e576a4b8cdbe4423fbf226b"
}
```

{% endcode %}

## Step 1 : Getting Payout Service List

You are advised to verify the recipient before proceeding with the transfer. We have provided bank verification endpoints which you can view via the link below.&#x20;

{% content-ref url="../payout/bank-account-verification" %}
[bank-account-verification](https://docs.leanx.io/api-docs/payout/bank-account-verification)
{% endcontent-ref %}

HTTP Method: <mark style="color:yellow;">POST</mark>

```
https://api.leanx.dev/api/v1/merchant/list-payout-services
```

#### Request Body

```
no request body
```

#### Response

```json
{
  "response_code": 2000,
  "description": "SUCCESS",
  "app_version": "/api/v1",
  "talk_to_server_before": "2023-11-28T18:00:18.547062",
  "data": {
    "list": {
      "draw": 30,
      "record_total": 30,
      "record_filtered": 30,
      "data": [
        {
          "SWITCH_PAYOUT_WEBPAY": [
            {
              "payout_service_id": 1,
              "payment_model_reference_id": 1,
              "payment_model_reference": "B2C",
              "unique_reference": "PAYOUT_MBSB_BANK_WEBPAY",
              "payment_service": "SWITCH_PAYOUT_WEBPAY",
              "name": "MBSB BANK BERHAD",
              "record_status_id": 1,
              "record_status": "ACTIVE"
            },
            .....
            {
              "payout_service_id": 2,
              "payment_model_reference_id": 1,
              "payment_model_reference": "B2C",
              "unique_reference": "PAYOUT_AGROBANK_WEBPAY",
              "payment_service": "SWITCH_PAYOUT_WEBPAY",
              "name": "BANK PERTANIAN MALAYSIA BHD (AGROBANK)",
              "record_status_id": 1,
              "record_status": "ACTIVE"
            }
          ]
        }
      ],
      "next_page_start": null,
      "next_page_length": null,
      "previous_page_start": null,
      "previous_page_length": null
    }
  },
  "breakdown_errors": null,
  "token": ""
}
```

***

## Step 2 : Create Payout Request

HTTP Method: <mark style="color:yellow;">POST</mark>

```
https://api.leanx.dev/api/v1/merchant/create-payout-invoice
```

#### Request body

```json
{
  "virtual_pool_reference": "VA-8F9FD0-132317969417-PAYOUT",
  "payout_service_id": 23,
  "amount": 13.00,
  "recipient_name": "John Doe",
  "client_callback_url": "https://www.yourdomain.com/api-callback-url",
  "third_party_account_no": "8011408168",
  "external_invoice_ref": "INVOICE1234",
  "recipient_reference": "test"
}
```

#### Attribute

<table><thead><tr><th width="234">Property</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td>virtual_pool_reference<mark style="color:red;">*</mark></td><td>String</td><td>Your virtual pool reference can be found in the portal under <strong>Pool Fund</strong> Page</td></tr><tr><td>payout_service_id<mark style="color:red;">*</mark></td><td>Number</td><td>Payout service ID from <a href="../payout/payout-service">payout service</a> list</td></tr><tr><td>amount<mark style="color:red;">*</mark></td><td>Decimal (10,2)</td><td>The amount that you want to payout.</td></tr><tr><td>recipient_name</td><td>String</td><td>Required</td></tr><tr><td>client_callback_url<mark style="color:red;">*</mark></td><td>String</td><td>Callback url after the payout is made.</td></tr><tr><td>third_party_account_no<mark style="color:red;">*</mark></td><td>String</td><td>Account number of the recipient</td></tr><tr><td>external_invoice_ref</td><td>String</td><td>Reference to your own invoice ID. Can be use to query back the payout status</td></tr><tr><td>recipient_reference<mark style="color:red;">*</mark></td><td>String</td><td>Recipient reference for the transfer</td></tr></tbody></table>

#### Response

```json
{
  "response_code": 2000,
  "description": "SUCCESS",
  "app_version": "/api/v1",
  "talk_to_server_before": "2023-12-05T17:43:07.620538",
  "data": {
    "status": "SUCCESS",
    "invoice_no": "PAYOUT-A9D5:174307-LEANX"
  },
  "breakdown_errors": "",
  "token": "18e0933d-6bc1-4808-9bc7-aad2bcd38686"
}
```

***

## Step 3 : Getting Payout Status

HTTP Method: <mark style="color:yellow;">POST</mark>

```
https://api.leanx.dev/api/v1/merchant/get-payout-transaction-by-id
```

#### Request Query

```json
?_id=PAYOUT-A9D5:174307-LEANX
```

```
?_id=INVOICE1234
```

You may choose to search for transaction status based on **payout id** (given by the system) or **external\_invoice\_ref** (given by your side upon create payout request) based on necessity. However, it is advisable to always search based on **external\_invoice\_ref** to ensure that your internal record and payout request is in-sync.&#x20;

#### Attributes

<table><thead><tr><th width="281.3333333333333">Property</th><th width="103">Type</th><th>Description</th></tr></thead><tbody><tr><td>_id</td><td>String</td><td><strong>Payout invoice number</strong> that you want to get the status or <strong>external invoice reference</strong> added upon create payout request</td></tr></tbody></table>

#### Response

```json
{
  "response_code": 2000,
  "description": "SUCCESS",
  "app_version": "/api/v1",
  "talk_to_server_before": "2023-12-05T18:02:55.948983",
  "data": {
    "payout_invoice_no": "PAYOUT-A9D5:174307-LEANX",
    "merchant_invoice_id": "VA-F04EC4-164712020277-PAYOUT",
    "id": 419,
    "payout_account_number": "8011408168",
    "transaction_fee": 0.00,
    "account_id": 3,
    "record_status": 1,
    "updated_at": "2023-12-05T17:44:05",
    "switch_invoice_id": "VP1678085468bA52B",
    "transaction_invoice_no": "PAYOUT1701769387uG4ENyls",
    "transaction_status": "SUCCESS",
    "value": 13.00,
    "switch_transaction_fee": 0.00,
    "api_key": "18e0933d-6bc1-4808-9bc7-aad2bcd38686",
    "created_at": "2023-12-05T17:43:07"
  },
  "breakdown_errors": null,
  "token": "18e0933d-6bc1-4808-9bc7-aad2bcd38686"
}
```
