const request = require('request');
|
|
const db = require('../../utils/db_config');
|
|
const { getCurrentDateTime } = require("../helper");
|
|
const crypto = require('crypto');
|
|
const { HASH_KEY } = require('../../utils/consts');
|
|
const { getInvTransIdQuery } = require('./query');
|
|
const { errorLogStatus } = require('../Errorlog');
|
|
|
|
|
|
function generateHMACSHA256(input, key) {
|
|
const hmac = crypto.createHmac('sha256', key);
|
|
hmac.update(input, 'utf8');
|
|
return hmac.digest('hex');
|
|
}
|
|
|
|
function getHashCode(investor_id, request_id) {
|
|
const inputString_GetInvestorDashboard = `${request_id}||${investor_id}||${getCurrentDateTime()}`;
|
|
const key = HASH_KEY;
|
|
const hash_GetInvestorDashboard = generateHMACSHA256(inputString_GetInvestorDashboard, key);
|
|
return hash_GetInvestorDashboard
|
|
|
|
}
|
|
|
|
const getReqAndInvId = ((req, res) => {
|
|
getReqAndInvIdFun();
|
|
res.send("in procress");
|
|
})
|
|
|
|
//get Request_Id and Investor_Id....
|
|
const getReqAndInvIdFun = async () => {
|
|
let allInvestorId = await db.investorSummary.findAll({
|
|
attributes: ['investor_id', 'request_id']
|
|
});
|
|
let sendId = JSON.stringify(allInvestorId, null, 2)
|
|
fetchReqAndInvId(sendId);
|
|
}
|
|
|
|
// Send Request_Id and Investor_Id to the getTransactionById fun
|
|
const fetchReqAndInvId = async (sendId) => {
|
|
let data = JSON.parse(sendId)
|
|
for (let i = 0; i < data.length; i++) {
|
|
let checkInvestorId = data[i].investor_id;
|
|
let checkRequestId = data[i].request_id;
|
|
if (checkInvestorId && checkRequestId) {
|
|
// setTimeout(() => {
|
|
await getTransactionById(checkInvestorId, checkRequestId)
|
|
// }, 10);
|
|
}
|
|
}
|
|
}
|
|
|
|
const getTransactionById = (checkInvestorId, checkRequestId) => {
|
|
try {
|
|
|
|
var options = {
|
|
method: 'POST',
|
|
url: 'https://supply-integration.liquiloans.com/api/v2/GetTransactionById',
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
},
|
|
body: JSON.stringify({
|
|
mid: "M00201",
|
|
checksum: getHashCode(checkInvestorId, checkRequestId),
|
|
timestamp: getCurrentDateTime(),
|
|
investor_id: checkInvestorId.toString(),
|
|
request_id: checkRequestId.toString()
|
|
})
|
|
};
|
|
request(options, async function (error, response) {
|
|
if (error) throw new Error(error);
|
|
if (response.body) {
|
|
// setTimeout(() => {
|
|
await fetchTransactionId(response.body);
|
|
// }, 10);
|
|
}
|
|
});
|
|
} catch (err) {
|
|
errorLogStatus(err, "nodeJs_liquiloan_getTransactionById")
|
|
}
|
|
}
|
|
|
|
const fetchTransactionId = async (data) => {
|
|
try {
|
|
let idDetails = JSON.parse(data);
|
|
let trnId = idDetails.data;
|
|
|
|
let item = {};
|
|
|
|
item.request_id = trnId.id,
|
|
item.investor_id = trnId.investor_id,
|
|
item.amount = trnId.amount,
|
|
item.transaction_type = trnId.transaction_type,
|
|
item.transaction_sub_type = trnId.transaction_sub_type,
|
|
item.withdrawal_method = trnId.withdrawal_method,
|
|
item.manual_parameters = trnId.manual_parameters,
|
|
item.old_investment_id = trnId.old_investment_id,
|
|
item.scheme_id = trnId.scheme_id,
|
|
item.mode = trnId.mode,
|
|
item.transaction_id = trnId.transaction_id,
|
|
item.order_id = trnId.order_id,
|
|
item.settlement_utr = trnId.settlement_utr,
|
|
item.transaction_source = trnId.transaction_source,
|
|
item.approval_status = trnId.approval_status,
|
|
item.transaction_status = trnId.transaction_status,
|
|
item.created_at = trnId.created_at,
|
|
item.authenticated_at = trnId.authenticated_at,
|
|
item.banking_date = trnId.banking_date,
|
|
item.execution_date = trnId.execution_date,
|
|
item.transaction_date = trnId.transaction_date,
|
|
item.ext_transaction_date = trnId.ext_transaction_date,
|
|
item.source_payment = trnId.source_payment,
|
|
item.last_updatedAt = getCurrentDateTime()
|
|
let isRecordPresent = await getInvTransIdQuery(item.request_id);
|
|
if (isRecordPresent.length) {
|
|
await db.transactionById.update(item, {
|
|
where: {
|
|
request_id: item.request_id
|
|
}
|
|
});
|
|
} else {
|
|
await db.transactionById.create(item);
|
|
}
|
|
console.log("done--------->")
|
|
} catch (err) {
|
|
errorLogStatus(err, "nodeJs_liquiloan_fetchTransactionId")
|
|
}
|
|
}
|
|
|
|
// const handleRecordPresent = async (item) => {
|
|
// let id = item.request_id;
|
|
// try {
|
|
// getInvTransIdQuery(id)
|
|
// } catch (err) {
|
|
// errorLogStatus(err, "nodeJs_liquiloan_handleRecordPresent")
|
|
// }
|
|
// }
|
|
|
|
|
|
module.exports = {
|
|
getReqAndInvId
|
|
}
|
Powered by TurnKey Linux.