Collect Payment API - Non-Seamless v2 Payment

The PayU v2 Payment API enables merchants to process payments through a hosted checkout flow where customers are redirected to PayU's payment page to complete the transaction.

📘

Note

This documentation covers the non-seamless (hosted checkout) integration. For seamless payment flows, refer to the v2 Payment API (Seamless) documentation.

Environment

Request header

ParameterDescription
dateThe current date and time. For example, format of the date is Wed, 28 Jun 2023 11:25:19 GMT.
authorizationThe actual HMAC signature generated using the specified algorithm (sha512) and includes the hashed data. For more information, refer to authorization fields description.

authorization fields description

FieldDescription
usernameRepresents the username or identifier for the client or merchant, for example smsplus.
algorithmUse SHA512 algorithm for hashing and send this as header value.
headersSpecifies which headers have been used in generating the hash, for example date.
signatureThe HMAC signature generated using the specified algorithm. For more information, refer to hashing algorithm.

hashing algorithm

You must hash the request parameters using the following hash logic:

Hash logic: sha512(<Body data> + '|' + date + '|' + merchant_secret)

Where <Body data> contains the request body posted with the request.

Sample header code
var merchant_key = 'smsplus';
var merchant_secret = 'izF09TlpX4ZOwmf9MvXijwYsBPUmxYHD';
// date
var date = new Date();
date = date.toUTCString();

// authorization
var authorization = getAuthHeader(date);

function getAuthHeader(date) {
    var AUTH_TYPE = 'sha512';
    var data = isEmpty(request['data']) ? "" : request['data'];
    var hash_string = data + '|' + date + '|' + merchant_secret;
    var hash = CryptoJS.SHA512(hash_string).toString(CryptoJS.enc.Hex);
    return `hmac username="${merchant_key}", algorithm="${AUTH_TYPE}", headers="date", signature="${hash}"`;
}

Request parameters

Parameter Description Example
accountId
mandatory
String Merchant key provided by PayU. Character limit: 50 "smsplus"
txnId
mandatory
String Unique transaction ID for the transaction. Character limit: 50 "REF_123456789"
order
mandatory
Object Order details containing product information and pricing. For more information, refer to order object {"productInfo": "Product Name", "paymentChargeSpecification": {"price": 1000.00}}
billingDetails
mandatory
Object Customer billing information. For more information, refer to billingDetails object {"firstName": "John", "email": "[email protected]", "phone": "9876543210"}
callBackActions
mandatory
Object Callback URLs for different payment outcomes. For more information, refer to callBackActions object {"successAction": "https://merchant.com/success", "failureAction": "https://merchant.com/failure"}
additionalInfo
mandatory
Object Additional transaction parameters including flow type. For more information, refer to additionalInfo object {"txnFlow": "non-seamless", "enforcePaymethod": "NB"}

order Object

Parameter Description Example
productInfo
mandatory
Product details. Product details
orderedItem
optional
Details about the items ordered. Array of Objects
userDefinedFields
optional
Custom fields for additional information. Fields: udf1, udf2, udf3, udf4, udf5, udf6, udf7, udf8, udf9, udf10. For more information, refer to Object
paymentChargeSpecification
mandatory
Includes amount and charges. For more information, refer to paymentChargeSpecification object fields description Object
paymentChargeSpecification object fields description
Parameter Description Example
price
mandatory
The transaction amount. 1000
netAmountDebit
optional
Net amount to be debited. 1000
taxSpecification
optional
Tax details of the product/order. Object
convenienceFee
optional
Fees format (e.g., CC:12). CC:12
offers
optional
Offers applied or available for the payment. Object
userDefinedFields object fields description
FieldDescription
udf1User defined field.
udf2User defined field.
udf3User defined field.
udf4User defined field.
udf5User defined field.
udf6User defined field.
udf7User defined field.
udf8User defined field.
udf9User defined field.
udf10User defined field.

billingDetails Object

Parameter Description Example
firstName
mandatory
First name of the billing contact. Ashish
lastName
optional
Last name of the billing contact. Kumar
address1
mandatory
Primary billing address. 123 Main Street
address2
optional
Secondary billing address. Apt 4B
phone
optional
Phone number of the billing contact. 9123456789
email
mandatory
Email address of the billing contact. [email protected]
city
optional
City of the billing address. Bharatpur
state
optional
State of the billing address. Rajasthan
country
optional
Country of the billing address. India
zipCode
optional
Postal/Zip code of the billing address. 321028

callBackActions Object

Parameter Description Example
successAction
mandatory
URL to be called on payment success. https://example.com/success
failureAction
mandatory
URL to be called on payment failure. https://example.com/failure
cancelAction
mandatory
URL to be called if user cancels the payment. https://example.com/cancel
codAction
optional
URL for Cash on Delivery (COD) action. https://example.com/cod

additionalInfo Object

Parameter Description Example
enforcePaymethod
optional
Force a transaction with a specified method (e.g., CC, DC). CC
createOrder
optional
A flag to store the order details (true/false). true
txnS2sFlow
optional
For defining seamless/non-seamless flows in handling payments. nonseamless

Sample Request

📘

Plugin for Development Environment:

PayU provides plugin for VS Code and IntelliJ IDEA development environment for faster integration. For more information, refer to Plugins for Development Environment.

curl -X POST \
  https://apitest.payu.in/v2/payments \
  -H 'date: Mon, 05 Oct 2024 11:00:00 GMT' \
  -H 'authorization: HMAC test:4d1ea4e74243ea5b2b5b8b1d8a7b1a2e3c4d5e6f7a8b9c0d1e2f3a4b5c6d7e8f9' \
  -H 'content-type: application/json' \
  -d '{
  "accountId": "test",
  "txnId": "ref_" + Math.random().toString(36).substring(7),
  "order": {
    "productInfo": "iPhone 13",
    "paymentChargeSpecification": {
      "price": 25000.00,
      "convenienceFee": "CC:12,AMEX:19"
    },
    "userDefinedFields": {
      "udf1": "value1",
      "udf2": "value2"
    }
  },
  "billingDetails": {
    "firstName": "John",
    "lastName": "Doe",
    "email": "[email protected]",
    "phone": "9876543210",
    "address": "123 Main Street",
    "city": "New Delhi",
    "state": "Delhi",
    "country": "India",
    "zipCode": "110001"
  },
  "callBackActions": {
    "successAction": "https://merchant.com/success",
    "failureAction": "https://merchant.com/failure",
    "cancelAction": "https://merchant.com/cancel"
  },
  "additionalInfo": {
    "txnFlow": "nonseamless",
    "createOrder": true,
    "enforcePaymethod": "CC,NB,UPI"
  }
}'

Response parameters

Parameter Description
txnId This parameter contains the transaction ID of the transaction.
paymentId This parameter contains the payment ID of the transaction.
message This parameter contains the status message of the transaction.

Sample response

Without order

It returns a URL similar to the following:

{"result":{"checkoutUrl":"https://pp78secure.payu.in/_payment_options?mihpayid=ff2bd7a285ea39d90d31e8d916ce1305&userToken="},"status":"PENDING"}

With order

{"result":{"checkoutUrl":"https://pp78secure.payu.in/_payment_options?mihpayid=ff2bd7a285ea39d90d31e8d916ce1305&userToken="},"orderId":"b5f2d8785768087678f5","status":"PENDING"}

The parsed response is similar the following:

Array
(
    [txnId] => b5f2d8785768087678fm9
    [mihpayId] => 1999110000001769
    [message] => Please call verify api to get the transaction status
)

Verify Payment

⚠️

Important

After creating a payment, you must call the Verify Payment API to get the final transaction status. The initial payment creation response will typically show "PENDING" status.