# UPI Intent

**UPI Intent Endpoint:**

This endpoint is useful for initiating payments with a custom UPI Intent and redirecting customers after they complete the payment.

```bash
POST /v1/payments/createPaymentIntent
```

#### Code Example: Axios POST Request

Below is an example of how to use Axios to create a UPI Intent:

```javascript
await axios.post(
  "https://api.upitranzact.com/v1/payments/createPaymentIntent",
  {
    mid: "Your Merchant ID", // Example: ABC
    amount: "Numeric value between 1-100000", // Example: 200
    order_id: "Unique order ID", // Example: bd79da4cc3ff1 (optional)
    redirect_url: "https://example.com/success",
    note: "Add money", // Payment remark
    customer_name: "John",
    customer_email: "john@example.com",
    customer_mobile: "Your Customer Mobile", // Correct value needed
  },
  {
    headers: {
      Authorization: "Basic base64(public_key:secret_key)"
    }
  }
);
```

#### Key Points

* **mid**: Your merchant identifier.
* **amount**: Must be a numeric value between 1 and 100000.
* **order\_id**: A unique string for transaction tracking. (optional)
* **redirect\_url**: Redirect to a custom web page after payment
* **customer\_name**: Ensure this contains a name.
* **customer\_email**: Ensure this contains a valid email address.
* **customer\_mobile**: Ensure this contains a valid phone number instead of a name.
* **Authorization**: Basic base64(public\_key:secret\_key).

Ensure all placeholders (e.g., "Your Merchant ID") are replaced with actual values before executing

**Request Body Parameters:**

<mark style="color:green;">`POST`</mark> `/v1/payments/`createPaymentIntent

**Headers**

| Name          | Value                               |
| ------------- | ----------------------------------- |
| Content-Type  | `application/x-www-form-urlencoded` |
| Authorization | `Basic Auth`                        |

**Body**

<table><thead><tr><th width="203">Name</th><th width="90">Type</th><th width="214">Description</th><th width="135">Example Value</th><th>Required</th></tr></thead><tbody><tr><td><code>mid</code></td><td>string</td><td>Merchant ID assigned to you by UPITranzact.</td><td>ABC</td><td>Yes</td></tr><tr><td><code>amount</code></td><td>integer</td><td>The total amount.</td><td>200</td><td>Yes</td></tr><tr><td><code>order_id</code></td><td>string</td><td>A unique identifier for the order.</td><td>bd79da4cccff1</td><td>No</td></tr><tr><td><code>redirect_url</code></td><td>string</td><td>URL to which the customer should be redirected after payment.</td><td>https://example.com/success</td><td>Yes</td></tr><tr><td><code>note</code></td><td>string</td><td>A remark for the payment.</td><td>Add Money</td><td>Yes</td></tr><tr><td><code>customer_name</code></td><td>string</td><td>The name of the customer making for the payment.</td><td>John</td><td>Yes</td></tr><tr><td><code>customer_email</code></td><td>string</td><td>The email address of the payment.</td><td>john@example.com</td><td>Yes</td></tr><tr><td><code>customer_mobile</code></td><td>string</td><td>The mobile number of the customer.</td><td>0123456789</td><td>Yes</td></tr></tbody></table>

**Authorization:**

The request must include an **Authorization header** with a **Base64 encoded string** containing your `public_key` and `secret_key` in the format `public_key:secret_key`. Here's an example of how to generate the **Authorization header**:

**Example:**

```javascript
Authorization: "Basic base64(public_key:secret_key)"
```

For example, if your `public_key` is `your_public_key` and your `secret_key` is `your_secret_key`, you would encode this into Base64 and use it as the Authorization header.

**Example Authorization Header (Base64 encoded):**

```javascript
Authorization: "Basic eW91cl9wdWJsaWNfa2V5OnlvdXJfc2VjcmV0X2tleQ=="
```

**Response**

{% tabs %}
{% tab title="200" %}
```json
{
    "status": true,
    "statusCode": 200,
    "msg": "Payment Intent created successfully",
    "data": {
        "intent": "Link starts with upi://",
        "phonepe": "PhonePe UPI Intent Link",
        "paytm": "Paytm UPI Intent Link",
        "gpay": "Google Pay UPI Intent Link",
        "dynamicQR": "Dynamic QR Link",
        "expiry": "2025-01-20 11:23:10",
        "amount": "115",
        "orderId": "utz_6b3ff790-XXX"
    }
}
```
{% endtab %}

{% tab title="409" %}
```json
{
    "status": false,
    "statusCode": 409,
    "msg": "Order ID already exists"
}
```
{% endtab %}
{% endtabs %}

**Error Codes:**

* **400**: Bad Request - Missing required parameters or invalid data.
* **401**: Unauthorized - Invalid or missing `Authorization` Basic Auth.
* **404**: Not Found - An issue occurred on the server side.
* **409**: Conflict - The request could not be processed due to a conflict with the current state of the resource.
* **500**: Internal Server Error - An issue occurred on the server side.
