ndps-nodejsots
v1.0.2
Published
```bash npm install ndps-nodejsots ``` import and use like below example ```nodejs const ndps = require('ndps-nodejsots'); ``` ## Usage
Downloads
3
Readme
Installation
npm install ndps-nodejsots
import and use like below example
const ndps = require('ndps-nodejsots');
Usage
Create payment request and to open payment gateway page
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: "[email protected]",
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
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
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: "[email protected]",
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]