[update] - fixed api

This commit is contained in:
Swapnil Bendal
2024-09-18 16:12:28 +05:30
parent 4c811297df
commit 54bf1c4eb9
3 changed files with 33 additions and 35 deletions

View File

@@ -4,38 +4,36 @@ const path = require('path');
const { iciciApi } = require('../../api');
const { AsyncHandler } = require('../../utils/handler/Async.handler');
const bankApi = AsyncHandler(async (req, res) => {
const publicKeyPath = path.join(__dirname, 'public_key.pem');
const publicKeyPem = fs.readFileSync(publicKeyPath, 'utf8');
const jsonData = {
"AGGRNAME": "CIBTESTING",
"AGGRID": "TXBCIBTEST001",
"CORPID": "TXBCORP1",
"USERID": "USER1",
"URN": "TESTING123",
"ALIASID": ""
};
const jsonString = JSON.stringify(jsonData);
// Encrypt JSON data with the public key
const buffer = Buffer.from(jsonString, 'utf-8');
const encrypted = crypto.publicEncrypt(
{
key: publicKeyPem,
padding: crypto.constants.RSA_PKCS1_PADDING
},
buffer
);
// Encode encrypted bytes to Base64
const base64Encrypted = encrypted.toString('base64');
const data = await iciciApi.Registration(base64Encrypted)
res.status(200).json(data);
});
module.exports = {
bankApi
Registration: AsyncHandler(async (req, res) => {
const publicKeyPath = path.join(__dirname, 'public_key.pem');
const publicKeyPem = fs.readFileSync(publicKeyPath, 'utf8');
const jsonData = {
"AGGRNAME": "CIBTESTING",
"AGGRID": "TXBCIBTEST001",
"CORPID": "TXBCORP1",
"USERID": "USER1",
"URN": "TESTING123",
"ALIASID": ""
};
const jsonString = JSON.stringify(jsonData);
// Encrypt JSON data with the public key
const buffer = Buffer.from(jsonString, 'utf-8');
const encrypted = crypto.publicEncrypt(
{
key: publicKeyPem,
padding: crypto.constants.RSA_PKCS1_PADDING
},
buffer
);
// Encode encrypted bytes to Base64
const base64Encrypted = encrypted.toString('base64');
const data = await iciciApi.Registration(base64Encrypted)
res.status(200).json(data);
}),
}

View File

@@ -2,6 +2,6 @@ const { bankDetailsController } = require('../../controllers')
const userRoutes = require('express').Router()
userRoutes.post('/', bankDetailsController.bankApi)
userRoutes.post('/registration', bankDetailsController.Registration)
module.exports = userRoutes

View File

@@ -5,7 +5,7 @@ const router = express.Router();
const defaultRoutes = [
{
path: '/bankDetails',
path: '/icici',
route: require('./icici'),
},
];