Execute Liquiloans Transaction Script
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

118 lines
4.8 KiB

'use strict'
const request = require("request");
const db = require('../utils/db_config');
const crypto = require('crypto');
const { getCurrentDateTime } = require("./helper");
function generateHMACSHA256(input, key) {
const hmac = crypto.createHmac('sha256', key);
hmac.update(input, 'utf8'); // Ensure input encoding matches C# (UTF-8)
return hmac.digest('hex');
}
function getHashCode(req) {
const inputString_GetInvestorDashboard = `${req} || ${getCurrentDateTime()}`;
const key = "27E6A91CEE689";
const hash_GetInvestorDashboard = generateHMACSHA256(inputString_GetInvestorDashboard, key);
return hash_GetInvestorDashboard
}
const fetchAllInvestorId = async (sendId) => {
let data =JSON.parse(sendId)
for (let i = 0; i < data.length; i++) {
await createLiquiloanInvestor(data[i].investor_id)
}
}
const getAllInvestorId = async () => {
let allInvestorId = await db.liquiloansInvestors.findAll({
attributes: ['investor_id']
});
let sendId = JSON.stringify(allInvestorId, null, 2)
fetchAllInvestorId(sendId);
};
const createLiquiloanInvestor = (investor_id) => {
var options = {
method: 'POST',
url: 'https://supply-integration.liquiloans.com/api/v2/GetInvestmentSummary',
headers: {
'Content-Type': 'application/json',
'Cookie': 'AWSALB=9yK+sr19KPz9dgL+OcWl2hZ9MOhLlvF9PtNolmRnkviHh01CvjlIWH44NtfjIziyJFwnhrn3+JNhztFLJis+Ijq971nXr5QQVJBxId1uvjZyqKSl/6oFuidGkloW; AWSALBCORS=9yK+sr19KPz9dgL+OcWl2hZ9MOhLlvF9PtNolmRnkviHh01CvjlIWH44NtfjIziyJFwnhrn3+JNhztFLJis+Ijq971nXr5QQVJBxId1uvjZyqKSl/6oFuidGkloW'
},
body: JSON.stringify({
"investor_id": investor_id,
"timestamp": getCurrentDateTime(),
"checksum": getHashCode(investor_id),
"mid": "M00201"
})
};
request(options, function (error, response) {
if (error) throw new Error(error);
const data = JSON.parse(response.body);
let callsData = data?.data.past_investments;
if (callsData) {
getUrlAndStore(callsData);
}
});
}
const getUrlAndStore = async (callsData) => {
try {
let summary = []
for (let i = 0; i < callsData.length; i++) {
let record = {};
record.transaction_id = callsData[i].transaction_id,
record.investor_id = callsData[i].investor_id,
record.scheme_id = callsData[i].scheme_id,
record.investment_roi = callsData[i].investment_roi,
record.return_type = callsData[i].return_type,
record.payout_type = callsData[i].payout_type,
record.lockin_tenure = callsData[i].lockin_tenure,
record.lockin_break = callsData[i].lockin_break,
record.last_withdrawal_at = callsData[i].last_withdrawal_at,
record.transaction_sub_type = callsData[i].transaction_sub_type,
record.investment_status = callsData[i].investment_status,
record.parent_investment_id = callsData[i].parent_investment_id,
record.master_parent_investment_id = callsData[i].master_parent_investment_id,
record.quality_name = callsData[i].quality_name,
record.name = callsData[i].name,
record.transaction_date = callsData[i].transaction_date,
record.invested_amount = callsData[i].invested_amount,
record.scheme_name = callsData[i].scheme_name,
record.lockin_type = callsData[i].lockin_type,
record.display_scheme = callsData[i].display_scheme,
record.scheme_details = callsData[i].scheme_details,
record.lockin_end_date = callsData[i].lockin_end_date,
record.redeemed_principal = callsData[i].redeemed_principal,
record.redeemed_erest = callsData[i].redeemed_erest,
record.redeemed_erest_with_request = callsData[i].redeemed_erest_with_request,
record.total_redemption = callsData[i].total_redemption,
record.net_principal_investment = callsData[i].net_principal_investment,
record.interest_amount = callsData[i].interest_amount,
record.accrued_value = callsData[i].accrued_value,
record.withdrawable_balance = callsData[i].withdrawable_balance,
record.scheme_closed_date = callsData[i].scheme_closed_date,
record.request_id = callsData[i].request_id,
record.source = callsData[i].source,
record.created_at = new Date()
summary.push(record);
}
await db.investorSummary.bulkCreate(summary);
}
catch (err) {
console.log(err, "ERROR.........");
}
}
module.exports = {
getAllInvestorId
}

Powered by TurnKey Linux.