---
page_source: https://docs.hdfcbank.juspay.in/docs/hypercheckout-mobile-sdk/web/how-to-integrate-sdks/handle-payment-responses
page_title: Handle Payment Responses
---


# Handle Payment Response




### Step 1 Add Juspay Order Status function in your backend


After being redirected to `return_url` from bank page, it is mandatory to do a Server-to-Server Order Status API call to determine the payment status. Please ensure that you verify the order ID and transaction amount.

Sample return_url : `https://merchant.shop.com/?status_id=21&status=CHARGED&order_id=guest-test-26&signature=wCFja5ZtDzm687LUxkqlw1NQYraC%2Bz540CitnlCouYI%3D&signature_algorithm=HMAC-SHA256`

If you are listening to webhooks from SmartGateway, please refer to the [Webhooks](/hypercheckout-mobile-sdk/web/resources/webhooks) section.

Expose `/handleJuspayResponse` API endpoint on your backend that calls the `Order Status` function of PHP SDK. This API endpoint will be called from your frontend to fetch the payment status.

For ease of implementation, you can refer to orderStatus( ) function from ‘Program.php’ file.



#### Code Snippets: -

#### PHP Code Snippet:

```php
public function orderStatus() {
       try {
        $params = array();
        $params ['order_id'] = $this->orderId;
        $requestOption = new RequestOptions();
        $requestOption->withCustomerId("testing-customer-one");
        $order = Order::status($params, $requestOption);
        echo "id: ". $order->orderId . PHP_EOL;
        echo "amount: ". $order->amount . PHP_EOL;
        echo "status: " . $order->status . PHP_EOL;
        echo "order env" . getenv("ORDER_ID") . 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 Juspay Order Status function in your backend


After being redirected to `return_url` from bank page, it is mandatory to do a Server-to-Server Order Status API call to determine the payment status. Please ensure that you verify the order ID and transaction amount.

If you are listening to webhooks from SmartGateway, please refer to the [Webhooks](/hypercheckout-mobile-sdk/web/resources/webhooks) section.

Expose `/handleJuspayResponse` API endpoint on your backend that calls the `Order Status` function of nodejs SDK. This API endpoint will be called from your frontend to fetch the payment status.

For ease of implementation, you can refer to orderStatus function from ‘index.js’ file.



#### Code Snippets: -

#### NodeJS Code Snippet:

```nodejs
app.post('/handleJuspayResponse', async (req, res) => {
    const orderId = req.body.order_id || req.body.orderId

    if (orderId == undefined) {
        return res.json(makeError('order_id not present or cannot be empty'))
    }

    try {
        const statusResponse = await juspay.order.status(orderId)
        const orderStatus = statusResponse.status
        let message = ''
        switch (orderStatus) {
            case "CHARGED":
                message = "order payment done successfully"
                break
            case "PENDING":
            case "PENDING_VBV":
                message = "order payment pending"
                break
            case "AUTHORIZATION_FAILED":
                message = "order payment authorization failed"
                break
            case "AUTHENTICATION_FAILED":
                message = "order payment authentication failed"
                break
            default:
                message = "order status " + orderStatus
                break
        }

        // removes http field from response, typically you won't send entire structure as response
        return res.send(makeJuspayResponse(statusResponse))
    } 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 Juspay Order Status function in your backend


After being redirected to `return_url` from bank page, it is mandatory to do a Server-to-Server Order Status API call to determine the payment status. Please ensure that you verify the order ID and transaction amount.

If you are listening to webhooks from SmartGateway, please refer to the [Webhooks](/hypercheckout-mobile-sdk/web/resources/webhooks) section. 

Expose `/handleJuspayResponse` API endpoint on your backend that calls the `Order Status` function of Java SDK. This API endpoint will be called from your frontend to fetch the payment status.

For ease of implementation, you can refer to doPost( ) function from ‘HandleJuspayResponse.java’ file.



#### Code Snippets: -

#### Java Code Snippet:

```java
@Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        String orderId = req.getParameter("order_id");

        if (orderId == null || orderId.isEmpty()) {
            resp.setStatus(HttpServletResponse.SC_BAD_REQUEST);
            resp.getWriter().write(makeErrorMsg("order_id not present or cannot be empty"));
            return;
        }

        try {
            Order orderStatus = Order.status(orderId);

            String message;
            switch (orderStatus.getStatus()) {
                case "CHARGED":
                    message = "order payment done successfully";
                    break;
                case "PENDING":
                case "PENDING_VBV":
                    message = "order payment pending";
                    break;
                case "AUTHORIZATION_FAILED":
                    message = "order payment authorization failed";
                    break;
                case "AUTHENTICATION_FAILED":
                    message = "order payment authentication failed";
                    break;
                default:
                    message = "order status " + orderStatus.getStatus();
                    break;
            }

            resp.setStatus(HttpServletResponse.SC_OK);
            resp.setContentType("application/json");
            JsonObject orderStatusResponse = new JsonObject();
            orderStatusResponse.addProperty("order_id", orderId);
            orderStatusResponse.addProperty("message", message);
            orderStatusResponse.addProperty("order_status", orderStatus.getStatus());
            String jsonString = new Gson().toJson(orderStatusResponse);
            resp.getWriter().write(jsonString);
        }
        catch (JuspayException e) {
            e.printStackTrace();
            resp.setStatus(e.getHttpResponseCode());
            resp.setContentType("application/json");
            resp.getWriter().write(makeErrorMsg(e.getStatus()));
        }
    }
```



### Step 1 Add Juspay Order Status function in your backend


After being redirected to `return_url` from bank page, it is mandatory to do a Server-to-Server Order Status API call to determine the payment status. Please ensure that you verify the order ID and transaction amount.

If you are listening to webhooks from SmartGateway, please refer to the [Webhooks](/hypercheckout-mobile-sdk/web/resources/webhooks) section. 

Expose `/handleJuspayResponse` API endpoint on your backend that calls the `Order Status` function of .Net SDK. This API endpoint will be called from your frontend to fetch the payment status.

For ease of implementation, you can refer to getOrderStatus( ) function from ‘HandleJuspayResponse.cs’ file.



#### Code Snippets: -

#### .Net Code Snippet:

```.net
public JuspayResponse getOrderStatus (string orderId)
        {
            string customerId = "testing-customer-one";
            RequestOptions requestOptions = new RequestOptions{ CustomerId = customerId };
            return new Order().Get(orderId, null, requestOptions);
        }
```



### Step 2 How to Handle Transaction Status 


Please refer to [Transaction Status](/hypercheckout-mobile-sdk/web/resources/transaction-status) section to understand how to handle various order status scenarios. Based on the Transaction Status, create a landing page which shows the status to the customer.

The following figure is a workflow of how you can handle the order status:

![Image](https://dth95m2xtyv8v.cloudfront.net/tesseract/assets/hypercheckout-mobile-sdk/.png)






### Step 3 Display Payment Status 


Once the payment status is determined via the API, the final status should be displayed to the user. This screen needs to be handled by the merchant, it is not provided by the Hypercheckout SDK.

