# ndps-nodejsots

> ```bash npm install ndps-nodejsots ``` import and use like below example ```nodejs const ndps = require('ndps-nodejsots'); ``` ## Usage

Latest version **1.0.2** (published 2022-11-03) · MIT license · 0 weekly downloads

## Install

```sh
npm install ndps-nodejsots
pnpm add ndps-nodejsots
yarn add ndps-nodejsots
bun add ndps-nodejsots
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2022-11-03 |
| First published | 2022-11-03 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 10.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | NTT DATA Payment Services India Limited |
| Maintainers | ndpsnpmuser |

## Links

- npm: https://www.npmjs.com/package/ndps-nodejsots
- npm.io page: https://npm.io/package/ndps-nodejsots

## Dependencies (1)

- [crypto-js](https://npm.io/package/crypto-js.md) ^4.1.1

## Recent versions

- 1.0.2 (latest) — 2022-11-03
- 1.0.1 — 2022-11-03
- 1.0.0 — 2022-11-03

## README

## Installation

```bash
npm install ndps-nodejsots
```
import and use like below example
```nodejs
const ndps = require('ndps-nodejsots');
```
## Usage

Create payment request and to open payment gateway page
```nodejs
 
 var requestNdpsPayment = {
        loginid: "8952",
        password: "Test@123",
        productid: "NSE",
        txnId: "123456",
        amount: "10.00",
        txncurrency: "INR",
        clientcode: "007",
        date: "2022-11-03 17:11:00",
        custName: "test user",
        custEmail: "test@xyz.com",
        custMobile: "8888888888",
        custacc: "125125",
        udf1: "optional data",
        udf2: "optional data",
        udf3: "optional data",
        udf4: "optional data",
        merchType: "R",
        mccCode: "5999",
        ru: "http://localhost:3000/response",
        payUrl: "https://caller.atomtech.in/ots/payment/txn",
        encHashKey: "KEY1234567234",
        encRequestKey: "A4476C2062FFA58980DC8F79EB6A799E"
    }
   // main function to get our redirectional payment url
   console.log(ndps.ndpsencrypt(requestNdpsPayment));
```

After getting response data use below function 
```nodejs
    var responseNdpsPayment = {
        response: req.body.encData,
        decResponseKey: "75AEF0FA1B94B3C10D4F5B268F757F11"
    }
    var response = ndps.ndpsresponse(responseNdpsPayment);
    var signature = ndps.verifysignature(response, "KERESPY1234567234");
    let respSignature = response[0]['payDetails']['signature'];
    let statusCode = response[0]['responseDetails']['statusCode'];

    // important for final payment validation
    if (statusCode != "OTS0101") {
        if (signature === respSignature) {
            if (statusCode == "OTS0000") {
                console.log("Transaction successful");
            } else {
                console.log("Transaction Failed");
            }
        } else {
            // Signature verification failed
            console.log("Transaction Failed");
        }
    } else {
        console.log("Transaction Failed");
    }
    // to read full response
    console.log(response);
```

Full example shown below with Node Js based Express framework

```nodejs
var express = require('express');
var bodyParser = require('body-parser');
var app = express();
const ndps = require('ndps-nodejsots');

// to support URL-encoded bodies
app.use(bodyParser.urlencoded({
    extended: true
}));

app.get('/request', function (req, resp) {
    var requestNdpsPayment = {
        loginid: "8952",
        password: "Test@123",
        productid: "NSE",
        txnId: "123456",
        amount: "10.00",
        txncurrency: "INR",
        clientcode: "007",
        date: "2022-11-03 17:11:00",
        custName: "test user",
        custEmail: "test@xyz.com",
        custMobile: "8888888888",
        custacc: "125125",
        udf1: "optional data",
        udf2: "optional data",
        udf3: "optional data",
        udf4: "optional data",
        merchType: "R",
        mccCode: "5999",
        ru: "http://localhost:3000/response",
        payUrl: "https://caller.atomtech.in/ots/payment/txn",
        encHashKey: "KEY1234567234",
        encRequestKey: "A4476C2062FFA58980DC8F79EB6A799E"
    }
    resp.redirect(ndps.ndpsencrypt(requestNdpsPayment));
});

app.post('/response', function (req, resp) {
    var responseNdpsPayment = {
        response: req.body.encData,
        decResponseKey: "75AEF0FA1B94B3C10D4F5B268F757F11"
    }
    var response = ndps.ndpsresponse(responseNdpsPayment);
    var signature = ndps.verifysignature(response, "KERESPY1234567234");
    let respSignature = response[0]['payDetails']['signature'];
    let statusCode = response[0]['responseDetails']['statusCode'];

    // important for final payment validation
    if (statusCode != "OTS0101") {
        if (signature === respSignature) {
            if (statusCode == "OTS0000") {
                resp.json("Transaction successful");
            } else {
                resp.json("Transaction Failed");
            }
        } else {
            // Signature verification failed
            resp.json("Transaction Failed");
        }
    } else {
        resp.json("Transaction Failed");
    }
    // to read full response
    console.log(response);
});

app.listen(3000, function () {
    console.log("Express server listening on port 3000");
});
```
## License
[MIT]

---
_Source: https://npm.io/package/ndps-nodejsots · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
