# Create a Pay-out Instance

This endpoint allows you to create a new Pay-out ( USDT to INR) instanc&#x65;**.** Using this API the merchant can make a pay-out to their customer. The API is designed such that it can support a payout to a single beneficiary  and also to multiple beneficiaries ( bulk payout).&#x20;

**Endpoint**

<mark style="color:green;">**`POST`**</mark>`https://api.tylt.money/fiatPayout/h2h/create`

**Request Headers**

{% tabs %}
{% tab title="First Tab" %}

<table data-full-width="true"><thead><tr><th width="133">Name</th><th width="79">Type</th><th width="167">Example</th><th>Description</th></tr></thead><tbody><tr><td>X-TLP-APIKEY</td><td>string</td><td>93ee3c5e133697251b5362bcf9cc8532476785t8768075616f58d88</td><td>Your Tylt API Key, used to identify your account in API requests.</td></tr><tr><td>X-TLP-SIGNATURE</td><td>string</td><td>d0afef3853dfc8489c8b9affa5825171fdd7y7685675e4966a05f66ed2b3eaf9462b3c9c0</td><td>HMAC SHA-256 signature generated using the API Secret Key to secure the request.</td></tr></tbody></table>
{% endtab %}
{% endtabs %}

{% hint style="warning" %}
When using the API, ensure to include your API Key and generate the signature for the request payload using your API Secret. The tables provided above contain example values for illustration purposes only. Please refer to the code snippets for detailed instructions on how to sign the request and generate the signature properly.
{% endhint %}

**Request Body**

{% tabs %}
{% tab title="Body" %}

<table data-header-hidden><thead><tr><th width="204"></th><th></th><th></th></tr></thead><tbody><tr><td><strong>Field Name</strong></td><td><strong>Type</strong></td><td><strong>Description</strong></td></tr><tr><td><code>currency</code></td><td><code>string</code></td><td>Must be set to "INR" for INR payouts.</td></tr><tr><td><code>payoutRequests</code></td><td><code>Array of JSON Objects</code></td><td>An array of JSON objects, where each JSON object represents a payment request / transaction</td></tr><tr><td><code>beneficiary_name</code></td><td><code>string</code></td><td>The bank of the beneficiary as it appears on the bank account.</td></tr><tr><td><code>beneficiary_IFSC</code></td><td><code>string</code></td><td>The beneficiary bank IFSC Code.</td></tr><tr><td><code>beneficiary_account_number</code></td><td><code>string</code></td><td>The bank account number of the beneficiary. Please ensure that the Type is string to accommodate bank account numbers starting with 0.</td></tr><tr><td><code>amount</code></td><td><code>number</code></td><td>The amount that needs to be paid out to the beneficiary. Please ensure the amount field is set to a number data type and restricted to whole numbers only, with no decimal places allowed.</td></tr><tr><td><code>reference_id</code></td><td><code>string</code></td><td>A UUID used by the merchant to reference each payout request.</td></tr></tbody></table>

{% endtab %}
{% endtabs %}

{% hint style="warning" %}
**Keep in Mind**

1. **`beneficiary_account_number`**:

   Please ensure the data type is set to **string**, as bank account numbers that begin with **0** may be misinterpreted or truncated if stored as a number. Using a numeric data type can lead to errors or loss of critical digits—particularly for account numbers starting with zero.
2. **`amount`** :\
   \
   Please ensure the **amount** field is set to a **number** data type and restricted to **whole numbers only**, with **no decimal places** allowed.
   {% endhint %}

**Code Snippet**

{% tabs %}
{% tab title="JavaScript (Axios)" %}

```javascript
const axios = require('axios');
const crypto = require('crypto');

// Replace with your API Key and Secret
const apiKey = 'your-api-key';
const apiSecret = 'your-api-secret';

// Request body
const requestBody = {
  "currency": "INR",
  "payoutRequests": [
    {
      "beneficiary_name": "Jon Doe",
      "beneficiary_account_number": "001245728274589", 
      "beneficiary_IFSC": "IFSC000008",
      "amount": 100,
      "reference_id": "payoutid_12345"
    },
    {
      "beneficiary_name": "Mary Jane",
      "beneficiary_account_number": "001245788774589", 
      "beneficiary_IFSC": "IFSC000010",
      "amount": 1000,
      "reference_id": "payoutid_12346"
    }
  ]
}

// Convert request body to JSON
const raw = JSON.stringify(requestBody);

// Function to create HMAC SHA-256 signature
const createSignature = (secret, data) => {
    return crypto.createHmac('sha256', secret)
                 .update(data)
                 .digest('hex');
};

// Generate signature
const signature = createSignature(apiSecret, raw);

// Define headers
const headers = {
    "Content-Type": "application/json",
    "X-TLP-APIKEY": apiKey,
    "X-TLP-SIGNATURE": signature
};

// Send the request
axios.post('https://api.tylt.money/fiatPayout/h2h/create', raw, { headers })
    .then(response => console.log("Success:", response.data))
    .catch(error => console.error("Error:", error));

```

{% endtab %}

{% tab title="Python" %}

```python
import json
import hashlib
import hmac
import requests

# Replace with your API Key and Secret
api_key = 'your-api-key'
api_secret = 'your-api-secret'

# Function to create HMAC SHA-256 signature
def create_signature(secret, data):
    return hmac.new(secret.encode(), data.encode(), hashlib.sha256).hexdigest()

# Function to send a POST request
def send_post_request(url, body):
    raw = json.dumps(body, separators=(',', ':'), ensure_ascii=False)
    signature = create_signature(api_secret, raw)

    headers = {
        'Content-Type': 'application/json',
        'X-TLP-APIKEY': api_key,
        'X-TLP-SIGNATURE': signature
    }

    response = requests.post(url, headers=headers, data=raw)
    return response.json()

# Request body
request_body = {
    "isBuyTrade": 1,
    "userDetails": {},
    "merchantOrderId": 'b73b73b-87wtbc-q36gbc-331n3',
    "callBackUrl": 'https://www.test.com/callback',
    "redirectUrl": 'https://www.test.com/callback',
}

# Send the request
response = send_post_request('https://api.tylt.money/p2pRampsMerchant/createInstance', request_body)
print("Response:", response)


```

{% endtab %}

{% tab title="JavaScript (Fetch)" %}

```javascript
const fetch = require('node-fetch');
const crypto = require('crypto');

// Replace with your API Key and Secret
const apiKey = 'your-api-key';
const apiSecret = 'your-api-secret';

// Request body
const requestBody = {
    isBuyTrade: 1,
    userDetails: {},
    merchantOrderId: 'b73b73b-87wtbc-q36gbc-331n3',
    callBackUrl: 'https://www.test.com/callback',
    redirectUrl: 'https://www.test.com/callback',
};

// Convert request body to JSON
const raw = JSON.stringify(requestBody);

// Function to create HMAC SHA-256 signature
const createSignature = (secret, data) => {
    return crypto.createHmac('sha256', secret)
                 .update(data)
                 .digest('hex');
};

// Generate signature
const signature = createSignature(apiSecret, raw);

// Define headers
const headers = {
    "Content-Type": "application/json",
    "X-TLP-APIKEY": apiKey,
    "X-TLP-SIGNATURE": signature
};

// Function to send the request
const sendRequest = async (url, headers, body) => {
    const response = await fetch(url, {
        method: 'POST',
        headers: headers,
        body: body,
    });
    return response.json();
};

// Send the request
sendRequest('https://api.tylt.money/p2pRampsMerchant/createInstance', headers, raw)
    .then(result => console.log("Success:", result))
    .catch(error => console.error("Error:", error));

```

{% endtab %}
{% endtabs %}

**Response**

{% tabs %}
{% tab title="200" %}

```json
{
  "msg": "Fiat payout request created and submitted successfully",
  "data": {
    "requestId": "uuid",
    "totalPayouts": "number",
    "totalFiatAmount": "number", 
    "totalCryptoAmount": "number",
    "fiatCurrencySymbol": "string",
    "requestFileUrl": "string",
    "status": "submitted"
  }
}
```

{% endtab %}

{% tab title="Response Fields" %}

<table data-header-hidden><thead><tr><th width="236"></th><th width="96"></th><th></th></tr></thead><tbody><tr><td><strong>Field Name</strong></td><td><strong>Type</strong></td><td><strong>Description</strong></td></tr><tr><td>requestId</td><td>string</td><td>The UUID the identifies the payout instance. The instance may contain one or more payout requests depending on the payoutRequests data sent in the API request body.</td></tr><tr><td>totalPayouts</td><td>number</td><td>The total number of payouts that have been correctly parsed for processing</td></tr><tr><td>totalFiatAmount</td><td>number</td><td>The total value of the payouts in INR</td></tr><tr><td>totalCryptoAmount</td><td>number</td><td>The total value of the payouts in USDT. This amount will be debited from the merchant balance to proceed with the payouts.</td></tr><tr><td>fiatCurrencySymbol</td><td>string</td><td>The symbol of the Fiat Currency: INR </td></tr><tr><td>requestFileUrl</td><td>string</td><td>A URL of the payouts for future reference and audit</td></tr><tr><td>status</td><td>string</td><td>The status of the payout instance</td></tr></tbody></table>
{% endtab %}
{% endtabs %}

#### Payout Instance Status IDs

{% hint style="warning" %}
**How do I check the status of my Payout-Instance**\
The **`requestId`** returned in the response can be used to query the status of the payout-instance.

**How do I check the status of an individual payout request?** \
The **reference\_id** sent in the requestBody can be used to query the status of each individual payout- request.
{% endhint %}

| status     | Description                                                                                 |
| ---------- | ------------------------------------------------------------------------------------------- |
| created    | Payout Instance created but not submitted for processing                                    |
| submitted  | Payout Instance submitted for processing                                                    |
| processing | Payout Instance is  being processed. Each request within the instance is processed in queue |
| completed  | Payout Instance processing is completed                                                     |
| failed     | Failed to process the payout instance                                                       |
| deleted    | Request deleted. Requests cannot be deleted once it is in "submitted" or "processing" state |

\
**Payout Request Status IDs**

| Event Name | Description                                                                                              |
| ---------- | -------------------------------------------------------------------------------------------------------- |
| created    | Payout request created                                                                                   |
| initiated  | Payout request has been initiated and awaiting further processing                                        |
| processing | Payout request is being processed. Transaction is currently in progress and being handled by the system. |
| pending    | Payout request has completed processing and is awaiting  status confirmation                             |
| completed  | Payout request has completed  processing successfully and the UTR confirmation is returned.              |
| failed     | Payout request could not be processed and the transaction failed.                                        |
| deleted    | Payout deleted                                                                                           |
