# Create a Pay-in Instance

This endpoint allows you to create a new payment instance and receive a URL that can be used to launch the **Tylt CrossRamp Pay-In widget.** Through the widget, the merchant's end customer can make a deposit or payment to the merchant using UPI. The payment is settled in USDT into the merchants wallet.

**Endpoint**

<mark style="color:green;">**`POST`**</mark>`https://api.tylt.money/p2pRampsMerchant/createInstance`

**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 width="121"></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>isBuyTrade</code></td><td><code>number</code></td><td>Must be set to 1 for a Pay-In transaction.</td></tr><tr><td><code>userDetails</code></td><td><code>JSON Object</code></td><td>Custom fields associated with the user, supplied by the merchant. These fields are included in webhook notifications and other API responses for easy reference and tracking. An empty object can be sent.</td></tr><tr><td><code>merchantOrderId</code></td><td><code>string</code></td><td>A UUID used by the merchant to reference this instance or any transaction related to it.</td></tr><tr><td><code>callBackUrl</code></td><td><code>string</code></td><td>The URL to which payment status updates are sent.</td></tr><tr><td><code>redirectUrl</code></td><td><code>string</code></td><td>The URL to redirect the user after completing the payment.</td></tr><tr><td><code>amount</code></td><td><code>number</code></td><td>Non-mandatory. This is the amount the user wants to deposit in USDT or INR equivalent. If this field is empty user can enter the value in the payment flow. </td></tr><tr><td><code>currencySymbol</code></td><td><code>string</code></td><td>To be used if using <code>amount</code>. Supported Currency is "USDT" or "INR" only.</td></tr><tr><td><code>userEmail</code></td><td><code>string</code></td><td>Non-mandatory. If the merchant wants to share the user email id they can use this field. If this field is empty, the user will have to provide the email or SSO login during the payment flow.</td></tr><tr><td><code>isKYCNeeded</code></td><td><code>number</code></td><td>1 or 0. If set to 0 the user will not be required to complete KYC or provide KYC. If field is in passed, default behaviour is KYC is required. This bypass needs to be approved by the admin for the Merchant.</td></tr><tr><td><code>isUTRNeeded</code></td><td>number</td><td>To be set <mark style="color:green;"><code>Mandatorily</code></mark> as 1.  The user will be required to provide the UTR (Unique Transaction Reference) number after making the payment. This is a <mark style="color:green;"><code>compliance</code></mark> step as it significantly reduces payment failures, disputes, and chargebacks while also enabling seamless processing through our automated Lightning Bridge.</td></tr></tbody></table>
{% endtab %}
{% endtabs %}

{% hint style="warning" %}
**Flow Modularity**

Merchants have the flexibility to enable or disable the following modules within the customer flow:

1. **User Email Sign-in**:
   * The system requires an email for user identification.
   * Merchants can provide the email by passing it in the `userEmail` field within the request body.
   * Alternatively, if the merchant prefers the user to enter their email during the payment process, this field can be left empty.
2. **KYC Bypass**:
   * In certain use cases, KYC verification may not be required for the end user.
   * To bypass KYC, set `isKYCNeeded` to 0.
   * When enabled, the user will not be required to complete KYC, and any existing KYC records will not be checked.
   * **Important:** Merchants must have admin pre-authorisation to use the KYC bypass feature.
     {% 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 = {
    isBuyTrade: 1,
    userDetails: {},
    merchantOrderId: crypto.randomUUID(),
    callBackUrl: 'https://www.test.com/callback',
    redirectUrl: 'https://www.test.com/callback',
    isUTRNeeded: 1,
    currencySymbol: "USDT",
    amount: "10",
    isKYCNeeded: 1,
    //userEmail: abc@email.com (required if isKYCNeeded is 0)
};

// Print request body for reference
console.log("requestBody", requestBody);

// 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/p2pRampsMerchant/createInstance', 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
import uuid

# 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": str(uuid.uuid4()),
    "callBackUrl": 'https://www.test.com/callback',
    "redirectUrl": 'https://www.test.com/callback',
    "isUTRNeeded": 1,
    "currencySymbol": "USDT",
    "amount": "10",
    "isKYCNeeded": 1,
    ##userEmail: abc@email.com (required if isKYCNeeded is 0)
}

# Print request body for reference
print('request_body',request_body)

# 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: crypto.randomUUID(),
    callBackUrl: 'https://www.test.com/callback',
    redirectUrl: 'https://www.test.com/callback',
    isUTRNeeded: 1,
    currencySymbol: "USDT",
    amount: "10",
    isKYCNeeded: 1,
    //userEmail: abc@email.com (required if isKYCNeeded is 0)
};

// Print request body for reference
console.log("requestBody", requestBody);

// 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": "Instance created successfully",
    "data": {
        "url": "https://app.tylt.money/prime/d0f6cc25-e8f8-11ef-830e-02d8461243e9",
        "instanceId": "d0f6cc25-e8f8-11ef-830e-02d8461243e9"     
        }    
}
```

{% 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>url</td><td>string</td><td>The unique link to the Tylt Prime Payment widget. You can display this url either on iframe or a browser.</td></tr><tr><td>instanceId</td><td>string</td><td>The instance ID generated by Tylt, used as a global identifier. </td></tr></tbody></table>
{% endtab %}
{% endtabs %}


---

# Agent Instructions: Querying This Documentation

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

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.tylt.money/introduction/tylt-crossramp-fiat-crypto-solutions/india-inr/upi-payin-inr-usdt/create-a-pay-in-instance.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
