API Reference

The OrderCreate API is used to create a new order in the Nippy payment gateway.

Overview

The Order Create API allows you to create a new order with transaction details, validate the input data, and generate URLs for UPI, Google Pay, PhonePe, and Paytm.

Prerequisites

Before starting this tutorial, you should have the following installed on your computer:

  • A text editor like Visual Studio Code, nodepad ++
  • PHP or javascript installed

Step 1: Set up the cURL request

Create a new PHP file called create_order_curl.php and add the following code to set up the cURL request to the Order Create API:

<?php

$curl = curl_init();

// Set the API URL
$api_url = 'https://pg.nippy.co.in/api/ordercreate/';

// Set the order data
$order_data = '{
  "mid": "2",
  "userid": "231",
  "mobile": "9840402696",
  "amount": 10.0,
  "name": "fahad",
  "ud1": "data1",
  "ud2": "data2",
  "ud3": "data3",
  "ud4": "",
  "ud5": ""
}';

curl_setopt_array($curl, array(
  CURLOPT_URL => $api_url,
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => '',
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => 'POST',
  CURLOPT_POSTFIELDS => $order_data,
  CURLOPT_HTTPHEADER => array(
    'Authorization: Bearer <AUTHTOKEN>',
    'Content-Type: text/plain'
  ),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;

?>

// just example
const form = document.getElementById('order-form');
const baseUrl = 'https://pg.nippy.co.in';

form.addEventListener('submit', (event) => {
  event.preventDefault();

  const formData = new FormData(form);
  const authToken = 'Bearer token'; // TODO: Get the auth token from your server
  const url = `${baseUrl}/api/ordercreate`;
  const options = {
    method: 'POST',
    headers: {
      Authorization: authToken,
    },
    body: formData,
  };

  fetch(url, options)
    .then(response => response.json())
    .then(data => {
      console.log(data);
    })
    .catch(error => {
      console.error(error);
    });
});

In this code snippet, we initialize a new cURL session using curl_init() and set various options with curl_setopt_array(). Some key options include:

CURLOPT_URL: The API endpoint URL
CURLOPT_RETURNTRANSFER: Set to true to return the API response as a string
CURLOPT_CUSTOMREQUEST: Set to 'POST' for a POST request
CURLOPT_POSTFIELDS: The JSON-formatted order data to send in the request body
CURLOPT_HTTPHEADER: An array of headers, including the Authorization and Content-Type headers

Step 2: Execute the cURL request and parse the response

After setting the cURL options, execute the request using curl_exec() and store the response in the $response variable. Once the request is complete, close the cURL session with curl_close() and echo the response.

$response = curl_exec($curl);
curl_close($curl);
echo $response;

The response will be a JSON-formatted string. To work with the response data, you can use PHP's json_decode() function to convert the JSON string into an associative array:

$response_data = json_decode($response, true);

Now, you can access the data from the response array, like the order ID and payment URLs:

<!DOCTYPE html>
<html>
<head>
    <title>Payment Links</title>
</head>
<body>

<?php

//write before code from before lines

if (isset($response_data['status']) && $response_data['status']) {
    $upi_url = $response_data['data']['upi'];
    $gpay_url = $response_data['data']['gpay'];
    $phonepe_url = $response_data['data']['phonepe'];
?>

    <h2>Payment Links</h2>
    <ul>
        <li><a href="<?php echo $upi_url; ?>">UPI</a></li>
        <li><a href="<?php echo $gpay_url; ?>">Google Pay</a></li>
        <li><a href="<?php echo $phonepe_url; ?>">PhonePe</a></li>
    </ul>

<?php
} else {
    echo "Error: Unable to create order and generate payment links.";
}
?>

</body>
</html>

In this example, the $response_data variable contains the API response converted to an associative array. We first check if the status field is set and true. If so, we extract the UPI, Google Pay, and PhonePe URLs from the response and store them in $upi_url, $gpay_url, and $phonepe_url, respectively.

We then create an HTML list with the URLs as clickable links. If the status is not set or false, we display an error message.

Endpoint

https://pg.nippy.co.in/api/ordercreate/

Request Method

POST

Headers

The following header is required:

Authorization: Bearer <auth_token>

Request Body

The following parameters are required in the request body:

ParameterTypeDescription
midstring*The merchant ID (1 to 4 digits)
useridstring*The user ID
mobilestring*The customer's mobile number
amountfloat*The payment amount
namestring*The customer's name
ud1stringUser-defined field 1
ud2stringUser-defined field 2
ud3stringUser-defined field 3
ud4stringUser-defined field 4
ud5stringUser-defined field 5

Response Body

The API returns a JSON object with the following fields:

FieldTypeDescription
statusstringThe encrypted order data
messagestringThe generated order ID
error_codebooleanWhether the order creation was successful
datastringAn error message (if any)
data.orderidStringUnique order ID
data.order_dateStringDate and time of the order
data.order_amountFloatTransaction amount
data.order_nameStringName of the user
data.upiStringUPI payment link
data.gpayStringGoogle Pay payment link
data.phonepeStringPhonePe payment link
data.paytmStringPaytm payment link

Sample Requestallowed_methods

POST https://pg.nippy.co.in/api/ordercreate/
Authorization: Bearer <auth_token>
Content-Type: application/json

{
  "mid": "1234",
  "userid": "user123",
  "mobile": "9876543210",
  "amount": 1000.0,
  "name": "John Doe",
  "ud1": "data1",
  "ud2": "data2",
  "ud3": "data3",
  "ud4": "data4",
  "ud5": "data5"
}

This request includes the following data:

  • mid: The merchant ID (e.g., "2")
  • userid: The user ID (e.g., "231")
  • mobile: The user's mobile number (e.g., "9840402696")
  • amount: The order amount (e.g., 10.0)
  • name: The user's name (e.g., "fahad")
  • ud1 to ud5: Custom data fields that can be used to store additional information related to the order (e.g., "data1", "data2", "data3", etc.)

Sample Response

HTTP/1.1 200 OK
Content-Type: application/json

{
    "status": true,
    "message": "Data inserted successfully",
    "data": {
        "orderid": "NIPP0002764666932873",
        "order_date": "2023-04-08 12:29:19",
        "order_amount": "10.00",
        "order_name": "fahad",
        "upi": "upi://pay?pn=NIPPY&tn=NIPP0002764666932873&tr=NIPP0002764666932873&am=10.00&cu=INR&mc=5815&pa=airagg%40icici",
        "gpay": "gpay://upi/pay?mc=5815&pa=airagg%40icici&pn=NIPPY&tn=NIPP0002764666932873&tr=NIPP0002764666932873&am=10.00&cu=INR",
        "phonepe": "phonepe://pay?pn=NIPPY&tn=NIPP0002764666932873&tr=NIPP0002764666932873&am=10.00&cu=INR&mc=5815&pa=airagg%40icici",
        "paytm": "paytmmp://pay?pn=NIPPY&tn=NIPP0002764666932873&tr=NIPP0002764666932873&am=10.00&cu=INR&mc=5815&pa=airagg%40icici"
    },
    "error_code": 200
}

This sample response represents a successful API call where the order was created successfully. The data object contains information about the order, such as the order ID, date, amount, and name. It also provides payment links for UPI, Google Pay, PhonePe, and Paytm.

Errors

If the API encounters any errors, it will return an appropriate HTTP status code and an error message in the response body. Some common error codes are:

Status StatusMessageDescription
400Bad RequestThe request was malformed or missing a parameter
401UnauthorizedThe authorization token was invalid or expired
500Internal Server ErrorAn error occurred while processing the request
200SuccessNo issue