Files
yume_js/src/controllers/transfer.controller.js

42 lines
823 B
JavaScript

const axios = require('axios');
const {
recordIntraBankTransaction,
} = require('../services/recordkeeping.service');
async function transfer(
fromAccountNo,
toAccountNo,
toAccountType,
amount,
customerNo,
narration = ''
) {
try {
const response = await axios.post(
'http://localhost:8689/kccb/Interbankfundtranfer',
{
fromAccountNo,
toAccountNo,
toAccountType,
amount,
narration,
}
);
await recordIntraBankTransaction(
customerNo,
fromAccountNo,
toAccountNo,
toAccountType,
amount,
response.data.status
);
return response.data;
} catch (error) {
throw new Error(
'API call failed: ' + (error.response?.data?.message || error.message)
);
}
}
module.exports = { transfer };