Payin P2P Seamless UPI Integration

UPI is a set of APIs developed by NPCI to enable instant online payments. It simplifies immediate payments via mobile devices. Payments can be initiated by both the sender (payer) and the receiver (payee) and can be completed using virtual payment addresses, Aadhaar integration, mobile numbers, and more. The payer’s smartphone can securely capture credentials for these transactions.

Merchant Onboarding: The merchant must provide the following information for onboarding in both the UAT and production environments:

  1. IP Address (For dynamic IPs, please provide the range of IP addresses).

  2. Merchant Callback URL to post the final transaction status from our system.

Once the merchant provides the required technical details, we will complete the necessary back-office configurations and provide a Merchant ID (MID/PID).

Let's see how it works:

  1. The merchant will send payment collection requests through our API. Along with this, the merchant must provide the order ID, PID, amount, UPI ID, name, email, and phone details.

  2. Payment Request: Upon receiving the request in the correct format, we will share the UPI payment string, which is required for QR code generation or intent creation.

  3. The merchant should collect the "Transaction ID" or "Bank Reference" from the customer and submit it to us by invoking the collection_utr API endpoint.

  4. Callback: Once the customer makes the payment, the callback data will be sent to the provided callback URL.

  5. Status Polling: You can confirm or check the payment status at any time by calling the polling_api and updating your system accordingly.

PAYMENT REQUEST :

Before proceeding, ensure you have reviewed the basic workflow. This section explains how to send the payment request.

Note: All requests must come from whitelisted IPs. Please confirm that your IP is whitelisted.

Payment Request

POST https://<domain>/api/request.php

Merchant makes a payment request.

Headers

Name
Value

Content-Type

application/json

Body

Name
Type
Description
Mandatory

pid

string

provided MID/PID

Yes

order_id

string

unique order id

Yes

amount

string

requested amount

Yes

upi_id

string

customer's upi id

No

name

string

customer's name

Yes

email

string

customer's email

Yes

phone

string

customer's phone

Yes

Sample Response Body

TRANSACTION REFERENCE/UTR SUBMIT :

The merchant needs to design a page where the customer can submit the "Bank Reference" or "Transaction ID" for the payment.

Capture Transaction Reference

POST https://<domain>/api/collection_utr.php

Merchant has to capture a transaction reference from the customer and submit it to us to verify the payment for transaction approval.

Headers

Name
Value

Content-Type

application/json

Body

Name
Type
Description
Mandatory

ref_code

string

given ref_code of transaction

Yes

pid

string

merchant PID/MID

Yes

utr

string

"Bank Reference"/"Transaction Id"

Yes

amount

int

amount in integer

Yes

Sample Request Body

Response

CALLBACK

We invoke your callback URL with callback data whenever there is a status change against the transaction.

Valid Transaction status are:

  1. Approved

  2. Declined

  3. Late Approved

  4. Pending

  5. User Timed Out

The most famous transaction changes are (but not limited):

  1. Pending=>Approved

  2. Pending=>Declined

  3. Pending=>User Timed Out

  4. User Timed Out=>Late Approved

The callback landing page must be set up on your server at a secret path, but it should be publicly accessible from our whitelisted IP. (Ensure that it is only accessible from our server IP.)

In the POST body, the following properties will be provided in JSON format:

Name
Type
Description

order_id

string

Your order id shared

requested_amount

int

requested amount

received_amount

int

received amount

bank_ref

string

transaction reference/bank reference/UTR if available

ref_code

string

unique code for the transaction

status

string

status of payment at this time

post_hash

string

signature post hash for security verification

Follow the steps to verify the integrity of received data:

  1. base64_decode post_hash:

  • Capture JSON data from the POST body.

  • JSON decode the data to an array or object.

  • Extract the post_hash from the decoded data.

  • For encrypted post_hash base64_decode the post_hash.

  1. Decrypt hash

Once you decrypt $encrypted_hash, you will get get plain remote_hash.

PHP Decrypt function

Node JS Decrypt function

  1. Compute the local hash using the MD5 128-bit hashing algorithm. Generate the hash locally.

Decrypt function for python given at the end of this document.

  1. Verify hash (Compare hash given at request and local hash)

  1. Acknowledge the payment gateway (You should Acknowledge back to the payment gateway that you saved the status of payment, otherwise we will retry Callback)

Definition of Payment Status:

  • Approved: The payment has been approved by our system.

  • Late Approved: The payment has been approved by our system after manual reconciliation.

  • Declined: The payment has been declined by our system.

  • Pending: The user session is active, awaiting payment completion.

  • User Timed Out: The user did not complete the payment within the session period.

STATUS POLLING :

POST https://<domain>/api/status_polling.php

This API is used to poll the status of a particular transaction.

Headers

Name
Value

Content-Type

application/json

Body

Name
Type
Description
Mandatory

pid

string

Merchant ID/PID

Yes

ref_code

string

unique ref_code which is generated in payment request

Yes

post_hash

string

post hash for signature verification

Yes

Steps to generate post_hash :

  1. Create a hash using md5 algorithm by appending values of ref_code, pid, secret_key

NodeJS Example:

  1. Encrypt hash (You need to encrypt the hash using the secret key)

PHP Encrypt function

Python Encrypt function

Node JS Encrypt function

  1. base64_encode encrypted_hash for transport over the network.

//Compute the payment hash locally

  1. Send a post request to the given URL

Send a POST request containing pid, ref_code, and post_hash as a JSON body to url_of_polling_api, and you will receive a response after validating the data.

  1. Process Response (You will get a JSON response)

Name
Type
Description

order_id

string

Merchant ID/PID

ref_code

string

unique ref_code which is generated in payment request

post_hash

string

post hash for signature verification

Status API Response Process

PHP Decrypt function

Python Decrypt function

Node JS Decrypt function

  1. Verify Response

#PHP Example if $local_hash equal to $remote_hash then the data is verified:

In python you need to import the following packages:

P2P Accounts Wallet Balance API Overview

This API provides detailed information about an operator's payment gateway (PG) accounts, including balance details and account details. It allows you to query and retrieve information related to UPI, IMPS, IMPS with UPI, wallet and payout accounts linked to the operator. For more details on how to use this API, refer to the link below.

COMPLAINT

We have a dedicated Complaint Section where merchants can manage transaction-related complaints. Through this section, merchants can submit complaints with all necessary details and optional evidence. Upon submission, a unique complaint reference ID is generated, allowing merchants to track the complaint’s status and receive real-time updates via the status-check API. This ensures a smooth, secure, and efficient process for resolving any transaction issues.

Complaint

RECONCILIATION

This API endpoint allows authorized users to retrieve payment transactions based on a specific pid (Partner ID) and date. The API performs authentication using a token and signature verification to ensure secure communication.

Reconciliation

Last updated