---
page_source: https://docs.hdfcbank.juspay.in/docs/hypercheckout-mobile-sdk/flutter/how-to-integrate-sdks/create-an-order
page_title: Create an Order
---


# Create an Order




### Step 1 Add Session Create function in your backend


Expose `/initiateJuspayPayment` API endpoint in your backend that calls the `Create` function of nodejs SDK. This API endpoint will be called from your frontend to open the payment page.

For ease of implementation, you can refer to order session function from ‘index.js’ file and update the following parameters:


| First Column | Second Column | Third Column |
|---|---|---|
| order_id | Mandatory | Unique identifier for the order |
| customer_id | Optional | It is the ID with which merchant refers to a customer object. This id is used to access the stored payment methods, allow EMI transactions and setup subscriptions. In case of guest login it should be an empty string |
| amount | Mandatory | Amount that the customer has to pay. Will accept stringified double or integer values with upto two decimal places (Example: "100.15" and "100" are valid input but "100.1532" is not valid) |
| return_url | Optional | A fully qualified URL on which the customer will be redirected after payment completion |
| payment_page_client_id | Mandatory | For Sandbox, add 'hdfcmaster' as your client_id |
| merchant_id | Optional | Add the Merchant_ID provided by the bank |


> **Warning**
> Please update ‘merchant_id’ and ‘customer_id’ in both ‘$params’ and ‘$requestOption’ variables





#### Code Snippets: -

#### NodeJS Code Snippet:

```nodejs
app.post('/initiateJuspayPayment', async (req, res) => {
    const orderId = `order_${Date.now()}`
    const amount = 1 + Math.random() * 100 | 0

    // makes return url
    const returnUrl = `${req.protocol}://${req.hostname}:${port}/handleJuspayResponse`

    try {
        const sessionResponse = await juspay.orderSession.create({
            order_id: orderId,
            amount: amount,
            payment_page_client_id: paymentPageClientId,                    // [required] shared with you, in config.json
            customer_id: 'hdfc-testing-customer-one',                       // [optional] your customer id here
            action: 'paymentPage',                                          // [optional] default is paymentPage
            return_url: returnUrl,                                          // [optional] default is value given from dashboard
            currency: 'INR'                                                 // [optional] default is INR
        })

        // removes http field from response, typically you won't send entire structure as response
        return res.json(makeJuspayResponse(sessionResponse))
    } catch (error) {
        if (error instanceof APIError) {
            // handle errors comming from juspay's api
            return res.json(makeError(error.message))
        }
        return res.json(makeError())
    }
})
```



### Step 1 Add Session Create function in your backend


Expose `/initiateJuspayPayment` API endpoint in your backend that calls the `Create` function of PHP SDK. This API endpoint will be called from your frontend to open the payment page.

For ease of implementation, you can refer to session( ) function from ‘Program.php’ file and update the following parameters:


| Parameters | Type  | Description |
|---|---|---|
| order_id | Mandatory  | Unique identifier for the order |
| customer_id | Optional | It is the ID with which merchant refers to a customer object. This id is used to access the stored payment methods, allow EMI transactions and setup subscriptions. In case of guest login it should be an empty string |
| amount | Mandatory | Amount that the customer has to pay. Will accept stringified double or integer values with upto two decimal places (Example: "100.15" and "100" are valid input but "100.1532" is not valid) |
| return_url | Optional  | A fully qualified URL on which the customer will be redirected after payment completion |
| payment_page_client_id | Mandatory  | For Sandbox, add 'hdfcmaster' as your client_id |
| merchant_id  | Optional   | Add the Merchant_ID provided by the bank |


> **Warning**
> Please update ‘merchant_id’ and ‘customer_id’ in both ‘$params’ and ‘$requestOption’ variables





#### Code Snippets: -

#### PHP Code Snippet:

```php
public function session() {
        try {
            $params = array();
            $params['amount'] = 1;
            $params['order_id'] = $this->orderId;
            $params["merchant_id"] = $this->config["MERCHANT_ID"]; # Add merchant id
            $params['customer_id'] = "testing-customer-one";
            $params['payment_page_client_id'] = $this->config["MERCHANT_ID"];
            $params['action'] = "paymentPage";
            $params['return_url'] = "http://0.0.0.0:5000/handleResponse";
            $requestOption = new RequestOptions();
            $requestOption->withCustomerId("testing-customer-one");
            $session = OrderSession::create($params, $requestOption);
            echo "id: " . $session->id . PHP_EOL;
            echo "order id: ". $session->orderId . PHP_EOL;
            echo "status" . $session->status . PHP_EOL;
            echo "payment link: " . $session->paymentLinks["web"] . PHP_EOL;
            echo "sdk payload" . json_encode($session->sdkPayload) . PHP_EOL;
        } catch ( JuspayException $e ) {
            echo "error code" . $e->getHttpResponseCode() . PHP_EOL;
            echo "error message: " . $e->getErrorMessage() . PHP_EOL;
            echo "error code" . $e->getErrorCode() . PHP_EOL;
        }
    }
```



### Step 1 Add OrderSession.Create() function in your backend


Expose `/initiateJuspayPayment` API endpoint on your server that calls the `OrderSession.create()` function of Java SDK. This API endpoint will be called from your frontend to open the payment page.

For ease of implementation, you can refer to `InitiateJuspayPayment` class and update the following parameters:


| Parameter | Type  | Description |
|---|---|---|
| order_id | Mandatory  | Unique identifier for the order |
| customer_id | Optional  | It is the ID with which merchant refers to a customer object. This id is used to access the stored payment methods, allow EMI transactions and setup subscriptions. In case of guest login it should be an empty string |
| payment_page_client_id | Mandatory  | For Sandbox, add 'hdfcmaster' as your client_id |
| amount | Mandatory  | Amount that the customer has to pay. Will accept stringified double or integer values with upto two decimal places. (Example, "100.15" and "100" are valid input but "100.1532" is not valid) |
| return_url | Optional  | A fully qualified URL on which the customer will be redirected after payment completion |
| merchant_id  | Optional  | Add the Merchant_ID provided by the bank |


> **Warning**
> Please update ‘customer_id’ in both ‘params’ and ‘requestOptions’ variables





#### Code Snippets: -

#### Java Code Snippet:

```java
public class InitiateJuspayPayment extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        String orderId = "order_" + UUID.randomUUID().toString().substring(12);
        int amount = new Random().nextInt(100) + 1;

        String serverName = req.getServerName();
        int serverPort = req.getServerPort();
        String contextPath = req.getContextPath();

        String paymentPageClientId = JuspayConfig.payment_page_client_id;
        String customerId = "hdfc-testing-customer-one";
        String scheme = req.getScheme();
        String returnUrl = scheme + "://" + serverName + ":" + serverPort + contextPath + "/handleJuspayResponse";

        try {
            Map<String, Object> params = new LinkedHashMap<>();
            params.put("order_id", orderId);
            params.put("payment_page_client_id", paymentPageClientId);
            params.put("amount", amount);
            params.put("customer_id", customerId);
            params.put("action", "paymentPage");
            params.put("return_url", returnUrl);
            params.put("currency", "INR");
            RequestOptions requestOptions = RequestOptions.createDefault().withCustomerId(customerId);
            OrderSession orderSession = OrderSession.create(params, requestOptions);
            resp.setStatus(HttpServletResponse.SC_OK);
            resp.setContentType("application/json");
            String responseString = new Gson().toJson(orderSession);
            resp.getWriter().write(responseString);
        } catch (JuspayException e) {
            e.printStackTrace();
            resp.setStatus(e.getHttpResponseCode());
            resp.setContentType("application/json");
            resp.getWriter().write(makeErrorMsg(e.getErrorMessage()));
        }
    }

    private String makeErrorMsg(String msg) {
        return "{\n  \"message\": \"" + msg + "\"\n}";
    }
}
```



### Step 1 Add OrderSession( ) function in your backend


Expose `/initiateJuspayPayment` API endpoint on your server that calls the `OrderSession()` function of .NET SDK. This API endpoint will be called from your frontend to open the payment page.

For ease of implementation, you can refer to `OrderSession()` class and update the following parameters:


| Parameter | Type | Description |
|---|---|---|
| orderId | Mandatory | Unique identifier for the order |
| customerId | Optional | It is the ID with which merchant refers to a customer object. This id is used to access the stored payment methods, allow EMI transactions and setup subscriptions. In case of guest login it should be an empty string |
| amount | Mandatory | Amount that the customer has to pay. Will accept stringified double or integer values with upto two decimal places. (Example, "100.15" and "100" are valid input but "100.1532" is not valid) |
| payment_page_client_id | Mandatory | For Sandbox, add 'hdfcmaster' as your client_id |
| return_url | Optional | A fully qualified URL on which the customer will be redirected after payment completion |


> **Warning**
> Please update ‘customerId’ in both ‘CreateOrderSessionInput’ and ‘requestOptions’ variables





#### Code Snippets: -

#### .NET Code Snippet:

```.net
string orderId = $"order_{new Random().Next()}";
                int amount = new Random().Next(0, 100);
                string customerId = "testing-customer-one";
                RequestOptions requestOptions = new RequestOptions{ CustomerId = customerId };
                CreateOrderSessionInput createOrderSessionInput = new CreateOrderSessionInput(new Dictionary<string, object>{{ "amount", amount}, { "order_id",  orderId}, { "customer_id", customerId }, { "payment_page_client_id", Init.Config.PaymentPageClientId }, { "action", "paymentPage" }, { "return_url", "http://localhost:5000/handleJuspayResponse" } });
                JuspayResponse sessionRes = new OrderSession().Create(createOrderSessionInput, requestOptions);
                Dictionary<string, object> res = new Dictionary<string, object> {
                    { "orderId", sessionRes.Response.order_id },
                    { "id", sessionRes.Response.id },
                    { "status", sessionRes.Response.status },
                    { "paymentLinks", sessionRes.Response.payment_links },
                    { "sdkPayload", sessionRes.Response.sdk_payload },
                };
```



### Step 2 (Optional) Additional params for Order Session function


You may add these below mentioned **optional params**  in your order session function added in the previous step as per your usecase:


| Parameters | Description |
|---|---|
| customer_email | Email address of the customer. If the backend gateway requires it, then you must send this value. |
| customer_phone | Mobile number or fixed line number of the customer. If the backend gateway requires it, then you must send this value. We recommend passing a 10-digit number without including the "+91" or any mobile country code at the beginning. |
| first_name | First Name of customer. This value will be used for customer identification. |
| last_name | Last name of customer. This value will be used for customer identification. |
| description | Description for order to be displayed to the user on amountBar. |
| currency | Currency for the order. It should only be passed when supported by the Payment Gateway and enabled in the SmartGateway Dashboard within EC Operations → PGCC → Select PG → Edit → Supported Currencies. |
| udf1, udf2, udf3, udf4, udf5 (No Special Characters Supported) | User Defined Parameter (UDF) field can be used to send any user defined parameters and it can be seen in the SmartGateway dashboard under each order. Example - abc5349       |
| udf6, udf7, udf8, udf9, udf10 (Special Characters Supported) | User Defined Parameter (UDF) field can be used to send any user defined parameters and it can be seen in the SmartGateway dashboard under each order. Example - abc5349       |




> **Note**
> Please pass parameters given above in **String**  format




### Sample Response




#### Sample Response of OrderSession.create Function Code Snippet:

```sample response of ordersession.create function
{
  "status": "NEW",
  "id": "ordeh_xxxxxxxxxxxxxxxxxxxx",
  "order_id": "testing-order-one",
  "payment_links": {
      "web": "https://smartgateway.hdfcuat.bank.in/merchant/ipay/ordeh_57dfd768bb7d4896bc042y0b90bc9ad77/payment-page"
  },
  "sdk_payload": {
      "requestId": "12398b5571d74c3388a74004bc24370c",
      "service": "in.juspay.hyperpay",
      "payload": {
          "clientId": "yourClientId",
          "amount": "1.0",
          "merchantId": "yourMerchantId",
          "clientAuthToken": "tkn_xxxxxxxxxxxxxxxxxxxxx",
          "clientAuthTokenExpiry": "2022-03-12T20:29:23Z",
          "environment": "production",
          "options.getUpiDeepLinks": "true",
          "lastName": "wick",
          "action": "paymentPage",
          "customerId": "testing-customer-one",
          "returnUrl": "https://shop.merchant.com",
          "currency": "INR",
          "firstName": "John",
          "customerPhone": "9876543210",
          "customerEmail": "test@mail.com",
          "orderId": "testing-order-one",
          "description": "Complete your payment"
      }
  }
}

```
