---
page_source: https://docs.hdfcbank.juspay.in/docs/hypercheckout-mobile-sdk/flutter/how-to-integrate-sdks/getting-the-backend-sdk
page_title: Getting the Backend SDK
---


# Getting the Backend SDK



> **Note**
> The steps described in this and subsequent pages have been already implemented in our sample project. Click on the ‘Download’ button on the top right hand side of the page to download the entire project.



In order to use **expresscheckout**  sdk, we need to add the SDK package and relevant dependencies in the backend files.

Following steps describe how to integrate SDK to setup the backend: 


### Step 1 Add npm package


Run the following command in terminal. 

`npm i expresscheckout-nodejs`





#### Code Snippets: -

#### NodeJS Code Snippet:

```nodejs
const fs = require('fs')
const express = require('express')
// block:start:importing-sdk
const { Juspay, APIError } = require('expresscheckout-nodejs')
// block:end:importing-sdk

/**
 * Setup expresscheckout-node sdk
 */
const SANDBOX_BASE_URL = "https://smartgateway.hdfcuat.bank.in"
const PRODUCTION_BASE_URL = "https://smartgateway.hdfc.bank.in"


/**
 * Read config.json file
 */
const config = require('./config.json')
const path = require('path')
const publicKey = fs.readFileSync(config.PUBLIC_KEY_PATH)
const privateKey = fs.readFileSync(config.PRIVATE_KEY_PATH)
const paymentPageClientId = config.PAYMENT_PAGE_CLIENT_ID // used in orderSession request

/*
Juspay.customLogger = Juspay.silentLogger
*/
const juspay = new Juspay({
    merchantId: config.MERCHANT_ID,
    baseUrl: SANDBOX_BASE_URL,
    jweAuth: {
        keyId: config.KEY_UUID,
        publicKey,
        privateKey
    }
})

/**
 * initialize server
 */
const app = express()
const port = process.env.PORT || 5000

app.use(express.urlencoded({ extended: true }))

/**
 * route:- initiateJuspayPayment
 */

// block:start:session-function
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())
    }
})
 // block:end:session-function

// block:start:order-status-function
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())
    }
})
// block:end:order-status-function


app.get('/', function(req,res) {
    return res.sendfile(path.join(__dirname, 'index.html'))
});

app.listen(port, () => {
    console.log(`Server is running on http://localhost:${port}`)
})

// Utitlity functions
function makeError(message) {
    return {
        message: message || 'Something went wrong'
    }
}

function makeJuspayResponse(successRspFromJuspay) {
    if (successRspFromJuspay == undefined) return successRspFromJuspay
    if (successRspFromJuspay.http != undefined) delete successRspFromJuspay.http
    return successRspFromJuspay
}

```



### Step 2 Importing SDK


Import Juspay and APIError.

`const { Juspay, APIError } = require('expresscheckout-nodejs')`



#### Code Snippets: -

#### NodeJS Code Snippet:

```nodejs
const { Juspay, APIError } = require('expresscheckout-nodejs')
```



### Step 1 Add the SDK package


Run the following command to add the SDK package to your ‘composer.json’ file:

`composer require juspay/expresscheckout-php-sdk`



#### Code Snippets: -

#### PHP Code Snippet:

```php
{
    "name": "ramprakash.v/php_kit",
    "type": "project",
    "require": {
        "juspay/expresscheckout-php-sdk": "2.0.4"
    },
    "autoload": {
        "psr-4": {
            "RamprakashV\\PhpKit\\": "src/"
        }
    },
    "config": {
        "process-timeout":0
    },
    "scripts": {
        "run_server": "composer install && php -S 0.0.0.0:5000 router.php",
        "run_app": "composer install && php Program.php"
    },
    "authors": [
        {
            "name": "Ramprakash Vel"
        }
    ]
}

```



### Step 2 Read the JWT Keys


1. Please refer to ‘init.php’ file in the sample project
2. Please add the path for Public Key and Private Key



#### Code Snippets: -

#### PHP Code Snippet:

```php
$privateKey = array_key_exists("PRIVATE_KEY", $config) ? $config["PRIVATE_KEY"] : file_get_contents($config["PRIVATE_KEY_PATH"]);
$publicKey =  array_key_exists("PUBLIC_KEY", $config) ? $config["PUBLIC_KEY"] : file_get_contents($config["PUBLIC_KEY_PATH"]);
```



### Step 3 Initialize the Configuration


1. Please refer to ‘init.php’ file in the sample project
2. Please update the ‘Base URL’ and ‘Key UUID’

> **Warning**
> Base URL will be different for Sandbox and Production environment 
> 
> * For Sandbox - [https://smartgateway.hdfcuat.bank.in](https://smartgateway.hdfcuat.bank.in)
> * For Production - [https://smartgateway.hdfc.bank.in](https://smartgateway.hdfc.bank.in)





#### Code Snippets: -

#### PHP Code Snippet:

```php
JuspayEnvironment::init()
->withBaseUrl("https://smartgateway.hdfcuat.bank.in")
->withMerchantId($config["MERCHANT_ID"])
->withJuspayJWT(new JuspayJWT($config["KEY_UUID"], $publicKey, $privateKey)); #Add key id
```



### Step 1 Add Dependencies


Add `expresscheckout` dependency in your ‘pom.xml’ file to run the SDK


#### Expresscheckout dependency Code Snippet:

```expresscheckout dependency
<dependency>

      <groupId>in.juspay</groupId>

      <artifactId>expresscheckout</artifactId>

      <version>1.3.3</version>

</dependency>
```


> **Note**
> You may add the below optional dependency if you receive any error as “Exception in thread "main" java.lang.NoClassDefFoundError: javax/xml/bind/DatatypeConverter”




#### Optional dependency Code Snippet:

```optional dependency
<dependency>

      <groupId>javax.xml.bind</groupId>

      <artifactId>jaxb-api</artifactId>

      <version>2.3.1</version>

</dependency>
```




#### Code Snippets: -

#### Java Code Snippet:

```java
<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>in.juspaybackendkit</groupId>
  <artifactId>JuspayBackendKit</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>war</packaging>

  <name>JuspayBackendKit Maven Webapp</name>
  <!-- FIXME change it to the project's website -->
  <url>http://www.example.com</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.7</maven.compiler.source>
    <maven.compiler.target>1.7</maven.compiler.target>
  </properties>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.11</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>javax.servlet-api</artifactId>
      <version>4.0.1</version>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>in.juspay</groupId>
      <artifactId>expresscheckout</artifactId>
      <version>1.3.3</version>
    </dependency>
    <dependency>
      <groupId>javax.xml.bind</groupId>
      <artifactId>jaxb-api</artifactId>
      <version>2.4.0-b180830.0359</version>
    </dependency>
  </dependencies>

  <build>
    <finalName>JuspayBackendKit</finalName>
    <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
      <plugins>
        <plugin>
          <groupId>org.eclipse.jetty</groupId>
          <artifactId>jetty-maven-plugin</artifactId>
          <version>9.4.28.v20200408</version>
          <configuration>
              <stopPort>9966</stopPort>
              <stopKey>stopJuspayFlowDemo</stopKey>
          </configuration>
        </plugin>
        <plugin>
          <artifactId>maven-clean-plugin</artifactId>
          <version>3.1.0</version>
        </plugin>
        <!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_war_packaging -->
        <plugin>
          <artifactId>maven-resources-plugin</artifactId>
          <version>3.0.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-compiler-plugin</artifactId>
          <version>3.8.0</version>
        </plugin>
        <plugin>
          <artifactId>maven-surefire-plugin</artifactId>
          <version>2.22.1</version>
        </plugin>
        <plugin>
          <artifactId>maven-war-plugin</artifactId>
          <version>3.2.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-install-plugin</artifactId>
          <version>2.5.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-deploy-plugin</artifactId>
          <version>2.8.2</version>
        </plugin>
      </plugins>
    </pluginManagement>
  </build>
</project>

```



### Step 2 Read the JWT Keys


1. Please refer to ‘JuspayConfig.java’ file in the sample project
2. Please add the absolute file path for Bank’s Public Key and your Private Key



#### Code Snippets: -

#### Java Code Snippet:

```java
private static String readFileAsString(String filePath) throws IOException {
        return new String(Files.readAllBytes(Paths.get(filePath)), Charset.defaultCharset());
    }
```



### Step 3 Initialize the Configuration


1. Please refer to ‘JuspayConfig.java’ file in the sample project for config initialization
2. Please update the ‘Base URL’ and ‘Key UUID’

> **Warning**
> Base URL will be different for Sandbox and Production environment 
> 
> * For Sandbox - [https://smartgateway.hdfcuat.bank.in](https://smartgateway.hdfcuat.bank.in)
> * For Production - [https://smartgateway.hdfc.bank.in](https://smartgateway.hdfc.bank.in)





#### Code Snippets: -

#### Java Code Snippet:

```java
JweJwsEncryptionKeys jweJwsEncryptionKeys = new JweJwsEncryptionKeys(keyUUID, publicKey, privateKey);
            JuspayEnvironment.withMerchantId(merchantId);
            JuspayEnvironment.withJweJwsEncryption(jweJwsEncryptionKeys);
            JuspayEnvironment.withBaseUrl(JuspayConfig.SANDBOX_BASE_URL);
```



### Step 1 Add the SDK package


Run the following command in terminal to add the SDK package:

`dotnet add package expresscheckout --version 2.0.3`



#### Code Snippets: -

#### .NET Code Snippet:

```.net
# How to run server
- update configuration in config.json file
- run ```dotnet run -f <framework>``` to run the server
- In browser load the website (localhost:5000)
- Option for -f net7.0,net6.0, netcoreapp3.1, netcoreapp3.0 and net5.0

# Curl for GET /handleJuspayResponse.php
```
curl --location 'localhost:5000/handleJuspayResponse?order_id=<order_id>'
```

```



### Step 2 Initialize the Configurations


Please refer to ‘init.cs’ file in the sample project for config initialization and update the Base URL, Key UUID, and file path of the Public Key of the bank and your Private Key

> **Warning**
> Base URL will be different for Sandbox and Production environment 
> 
> * For Sandbox - [https://smartgateway.hdfcuat.bank.in](https://smartgateway.hdfcuat.bank.in)
> * For Production - [https://smartgateway.hdfc.bank.in](https://smartgateway.hdfc.bank.in)





#### Code Snippets: -

#### .NET Code Snippet:

```.net
JuspayEnvironment.Instance.JuspayJWT = new JuspayJWTRSA(Config.KeyUuid, Config.PublicKey, Config.PrivateKey);
                JuspayEnvironment.Instance.MerchantId = Config.MerchantId;
                JuspayEnvironment.Instance.BaseUrl = "https://smartgateway.hdfcuat.bank.in";
```
