added beneficiary routes, controllers and services

This commit is contained in:
2025-07-30 12:26:04 +05:30
parent d4d741b8cc
commit b88e00f758
3 changed files with 34 additions and 4 deletions

View File

@@ -22,4 +22,29 @@ async function validateWithinBank(req, res) {
}
}
module.exports = { validateWithinBank };
async function validateOutsideBank(req, res) {
res.status(400).send('WIP. Try after sometime');
}
async function npciResponse(req, res) {
const { resp } = req.body;
console.log(req.body);
if (resp === 'Success') {
await handleNPCISuccess(resp);
} else {
await handleNPCIFailure(resp);
}
res.send('ok');
}
async function handleNPCISuccess(response) {
const { txnid, benename } = response;
console.log(txnid);
console.log(benename);
}
async function handleNPCIFailure(response) {
console.log(response);
}
module.exports = { validateWithinBank, npciResponse, validateOutsideBank };

View File

@@ -4,5 +4,7 @@ const beneficiaryController = require('../controllers/beneficiary.controller');
const router = express.Router();
router.get('/validate/within-bank', beneficiaryController.validateWithinBank);
router.get('/validate/outside-bank', beneficiaryController.validateOutsideBank);
router.post('/validate/npci-response', beneficiaryController.npciResponse);
module.exports = router;

View File

@@ -1,10 +1,13 @@
const axios = require('axios');
const { logger } = require('../util/logger');
async function validateWithinBank(accountNo) {
const url = `http://localhost:8687/kccb/cbs/acctInfo/details?stacctno=${accountNo}`;
const url = 'http://localhost:8687/kccb/cbs/acctInfo/details';
try {
const response = await fetch(url);
const data = await response.json();
const response = await axios.get(url, {
params: { stacctno: accountNo },
});
const data = response.data;
const customerName = data.customername;
return customerName;
} catch (error) {