mirror of
https://github.com/mohamadihsan/topuponline.git
synced 2026-12-05 10:36:28 +00:00
update
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
var queueRecon = [];
|
||||
var queueReservation = [];
|
||||
|
||||
const reconReceive = (reservationNumber) => {
|
||||
queueRecon.push(reservationNumber);
|
||||
@@ -16,7 +17,21 @@ const reconFinish = (queueRecon) => {
|
||||
return queueRecon;
|
||||
};
|
||||
|
||||
const reservationReceive = (reservationNumber) => {
|
||||
queueReservation.push(reservationNumber);
|
||||
|
||||
return queueReservation;
|
||||
};
|
||||
|
||||
const reservationFinish = (queueReservation) => {
|
||||
queueReservation.shift();
|
||||
|
||||
return queueReservation;
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
reconReceive,
|
||||
reconFinish,
|
||||
reservationReceive,
|
||||
reservationFinish,
|
||||
};
|
||||
|
||||
@@ -9,7 +9,8 @@ const _sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
||||
moment.locale("id");
|
||||
|
||||
var maxLoopParameter = 100;
|
||||
var dataQueue = [];
|
||||
var dataReconQueue = [];
|
||||
var isProccessingRecon = false;
|
||||
|
||||
// VALIDATION
|
||||
const validate = (method) => {
|
||||
@@ -74,7 +75,7 @@ const validate = (method) => {
|
||||
};
|
||||
|
||||
// PAYMENT RECON
|
||||
const paymentRecon = async (req, res) => {
|
||||
const paymentReconQueue = async (req, res) => {
|
||||
try {
|
||||
// generate unique code
|
||||
let uniqueCode = helper.getUniqueCode();
|
||||
@@ -126,290 +127,294 @@ const paymentRecon = async (req, res) => {
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
|
||||
dataQueue = queue.reconReceive(reservation_number);
|
||||
dataReconQueue = queue.reconReceive(reservation_number);
|
||||
|
||||
let partnerCode = getPartner.partner_code;
|
||||
let PaymentReconNumber;
|
||||
|
||||
var i = 0;
|
||||
while (dataQueue.length != 0) {
|
||||
PaymentReconNumber = await generatePaymentReconNumber(
|
||||
partnerCode,
|
||||
moment().format("YYYY-MM-DD HH:mm:ss")
|
||||
);
|
||||
if (PaymentReconNumber != "XX") {
|
||||
queue.reconFinish(dataQueue);
|
||||
i++;
|
||||
|
||||
// check ref no and amount
|
||||
let checkReservationNumberAndAmountAlreadyRecon =
|
||||
await model.checkReservationNumberAndAmountAlreadyRecon(
|
||||
while (dataReconQueue.length != 0) {
|
||||
console.log('HAHAHA');
|
||||
if (dataReconQueue[0] == reservation_number && isProccessingRecon == false) {
|
||||
isProccessingRecon == true;
|
||||
PaymentReconNumber = await generatePaymentReconNumber(
|
||||
partnerCode,
|
||||
moment().format("YYYY-MM-DD HH:mm:ss")
|
||||
);
|
||||
if (PaymentReconNumber != "XX") {
|
||||
queue.reconFinish(dataReconQueue);
|
||||
isProccessingRecon == false
|
||||
|
||||
// check ref no and amount
|
||||
let checkReservationNumberAndAmountAlreadyRecon =
|
||||
await model.checkReservationNumberAndAmountAlreadyRecon(
|
||||
reservation_number
|
||||
);
|
||||
if (checkReservationNumberAndAmountAlreadyRecon) {
|
||||
result = {
|
||||
code: "04",
|
||||
message: `success. Transaction has been recon at ${checkReservationNumberAndAmountAlreadyRecon.d_payment_recon}`,
|
||||
data: {
|
||||
payment_recon_no:
|
||||
checkReservationNumberAndAmountAlreadyRecon.c_payment_recon_no,
|
||||
recon_date:
|
||||
checkReservationNumberAndAmountAlreadyRecon.d_payment_recon,
|
||||
},
|
||||
};
|
||||
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} RESPONSE payment recon: ${JSON.stringify(result)}`
|
||||
);
|
||||
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
|
||||
// log debug
|
||||
winston.logger.debug(
|
||||
`${uniqueCode} checking reservation canceled status...`
|
||||
);
|
||||
|
||||
// check reservation status
|
||||
let checkReservationCanceledStatus =
|
||||
await model.checkReservationCanceledStatus(reservation_number);
|
||||
if (checkReservationCanceledStatus) {
|
||||
result = {
|
||||
code: "431",
|
||||
message: "transaction has been canceled",
|
||||
data: {
|
||||
payment_recon_no: PaymentReconNumber,
|
||||
recon_date: moment().format("YYYY-MM-DD HH:mm:ss"),
|
||||
},
|
||||
};
|
||||
|
||||
// log debug
|
||||
winston.logger.debug(
|
||||
`${uniqueCode} inserting payment recon transaction...`
|
||||
);
|
||||
|
||||
// insert payment recon transaction
|
||||
await model.insertPaymentReconTransaction(
|
||||
date,
|
||||
moment().format("YYYY-MM-DD HH:mm:ss"),
|
||||
getPartner.partner_code,
|
||||
PaymentReconNumber,
|
||||
bank_ref,
|
||||
reservation_number,
|
||||
amount,
|
||||
"F",
|
||||
"FAILED",
|
||||
result.code,
|
||||
result.message.toUpperCase(),
|
||||
result.data
|
||||
);
|
||||
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} RESPONSE payment recon: ${JSON.stringify(result)}`
|
||||
);
|
||||
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
|
||||
// log debug
|
||||
winston.logger.debug(
|
||||
`${uniqueCode} checking total transaction and amount by reservation number...`
|
||||
);
|
||||
|
||||
// check ref no and amount
|
||||
let check = await model.checkReservationNumberAndAmount(
|
||||
reservation_number
|
||||
);
|
||||
if (checkReservationNumberAndAmountAlreadyRecon) {
|
||||
result = {
|
||||
code: "04",
|
||||
message: `success. Transaction has been recon at ${checkReservationNumberAndAmountAlreadyRecon.d_payment_recon}`,
|
||||
data: {
|
||||
payment_recon_no:
|
||||
checkReservationNumberAndAmountAlreadyRecon.c_payment_recon_no,
|
||||
recon_date:
|
||||
checkReservationNumberAndAmountAlreadyRecon.d_payment_recon,
|
||||
},
|
||||
};
|
||||
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} RESPONSE payment recon: ${JSON.stringify(result)}`
|
||||
);
|
||||
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
|
||||
// log debug
|
||||
winston.logger.debug(
|
||||
`${uniqueCode} checking reservation canceled status...`
|
||||
);
|
||||
|
||||
// check reservation status
|
||||
let checkReservationCanceledStatus =
|
||||
await model.checkReservationCanceledStatus(reservation_number);
|
||||
if (checkReservationCanceledStatus) {
|
||||
result = {
|
||||
code: "431",
|
||||
message: "transaction has been canceled",
|
||||
data: {
|
||||
payment_recon_no: PaymentReconNumber,
|
||||
recon_date: moment().format("YYYY-MM-DD HH:mm:ss"),
|
||||
},
|
||||
};
|
||||
|
||||
// log debug
|
||||
winston.logger.debug(
|
||||
`${uniqueCode} inserting payment recon transaction...`
|
||||
);
|
||||
|
||||
// insert payment recon transaction
|
||||
await model.insertPaymentReconTransaction(
|
||||
date,
|
||||
moment().format("YYYY-MM-DD HH:mm:ss"),
|
||||
getPartner.partner_code,
|
||||
PaymentReconNumber,
|
||||
bank_ref,
|
||||
reservation_number,
|
||||
amount,
|
||||
"F",
|
||||
"FAILED",
|
||||
result.code,
|
||||
result.message.toUpperCase(),
|
||||
result.data
|
||||
);
|
||||
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} RESPONSE payment recon: ${JSON.stringify(result)}`
|
||||
);
|
||||
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
|
||||
// log debug
|
||||
winston.logger.debug(
|
||||
`${uniqueCode} checking total transaction and amount by reservation number...`
|
||||
);
|
||||
|
||||
// check ref no and amount
|
||||
let check = await model.checkReservationNumberAndAmount(
|
||||
reservation_number
|
||||
);
|
||||
if (!check) {
|
||||
result = {
|
||||
code: "427",
|
||||
message: "transaction doesn't exists",
|
||||
data: {
|
||||
payment_recon_no: PaymentReconNumber,
|
||||
recon_date: moment().format("YYYY-MM-DD HH:mm:ss"),
|
||||
},
|
||||
};
|
||||
|
||||
// log debug
|
||||
winston.logger.debug(
|
||||
`${uniqueCode} inserting payment recon transaction...`
|
||||
);
|
||||
|
||||
// insert payment recon transaction
|
||||
await model.insertPaymentReconTransaction(
|
||||
date,
|
||||
moment().format("YYYY-MM-DD HH:mm:ss"),
|
||||
getPartner.partner_code,
|
||||
PaymentReconNumber,
|
||||
bank_ref,
|
||||
reservation_number,
|
||||
amount,
|
||||
"F",
|
||||
"FAILED",
|
||||
result.code,
|
||||
result.message.toUpperCase(),
|
||||
result.data
|
||||
);
|
||||
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} RESPONSE payment recon: ${JSON.stringify(result)}`
|
||||
);
|
||||
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
|
||||
let totalTransactions = check.total_transaction;
|
||||
|
||||
if (totalTransactions > 1) {
|
||||
result = {
|
||||
code: "424",
|
||||
message: "Duplicate Ref No.",
|
||||
data: {
|
||||
payment_recon_no: PaymentReconNumber,
|
||||
recon_date: moment().format("YYYY-MM-DD HH:mm:ss"),
|
||||
},
|
||||
};
|
||||
|
||||
// log debug
|
||||
winston.logger.debug(
|
||||
`${uniqueCode} inserting payment recon transaction...`
|
||||
);
|
||||
|
||||
// insert payment recon transaction
|
||||
await model.insertPaymentReconTransaction(
|
||||
date,
|
||||
moment().format("YYYY-MM-DD HH:mm:ss"),
|
||||
getPartner.partner_code,
|
||||
PaymentReconNumber,
|
||||
bank_ref,
|
||||
reservation_number,
|
||||
amount,
|
||||
"F",
|
||||
"FAILED",
|
||||
result.code,
|
||||
result.message.toUpperCase(),
|
||||
result.data
|
||||
);
|
||||
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} RESPONSE payment recon: ${JSON.stringify(result)}`
|
||||
);
|
||||
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
|
||||
let totalAmount = check.total_amount;
|
||||
|
||||
if (parseInt(totalAmount) != parseInt(amount)) {
|
||||
result = {
|
||||
code: "425",
|
||||
message: "Total amount is different.",
|
||||
data: {
|
||||
payment_recon_no: PaymentReconNumber,
|
||||
recon_date: moment().format("YYYY-MM-DD HH:mm:ss"),
|
||||
},
|
||||
};
|
||||
|
||||
// log debug
|
||||
winston.logger.debug(
|
||||
`${uniqueCode} inserting payment recon transaction...`
|
||||
);
|
||||
|
||||
// insert payment recon transaction
|
||||
await model.insertPaymentReconTransaction(
|
||||
date,
|
||||
moment().format("YYYY-MM-DD HH:mm:ss"),
|
||||
getPartner.partner_code,
|
||||
PaymentReconNumber,
|
||||
bank_ref,
|
||||
reservation_number,
|
||||
amount,
|
||||
"F",
|
||||
"FAILED",
|
||||
result.code,
|
||||
result.message.toUpperCase(),
|
||||
result.data
|
||||
);
|
||||
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} RESPONSE payment recon: ${JSON.stringify(result)}`
|
||||
);
|
||||
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
|
||||
let data = {
|
||||
reservation_number: reservation_number,
|
||||
payment_recon_no: PaymentReconNumber,
|
||||
date: date,
|
||||
time: moment().format("YYYY-MM-DD HH:mm:ss"),
|
||||
};
|
||||
|
||||
// log debug
|
||||
winston.logger.debug(`${uniqueCode} updating payment recon number...`);
|
||||
|
||||
let update = await model.updatePaymentReconNo(data);
|
||||
if (!update) {
|
||||
result = {
|
||||
code: "428",
|
||||
message:
|
||||
"failed recon. The other transaction with same data is running.",
|
||||
data: {
|
||||
payment_recon_no: PaymentReconNumber,
|
||||
recon_date: moment().format("YYYY-MM-DD HH:mm:ss"),
|
||||
},
|
||||
};
|
||||
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} RESPONSE payment recon: ${JSON.stringify(result)}`
|
||||
);
|
||||
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
|
||||
// log debug
|
||||
winston.logger.debug(
|
||||
`${uniqueCode} inserting payment recon transaction...`
|
||||
);
|
||||
|
||||
result = {
|
||||
code: "00",
|
||||
message: "success",
|
||||
data: {
|
||||
if (!check) {
|
||||
result = {
|
||||
code: "427",
|
||||
message: "transaction doesn't exists",
|
||||
data: {
|
||||
payment_recon_no: PaymentReconNumber,
|
||||
recon_date: moment().format("YYYY-MM-DD HH:mm:ss"),
|
||||
},
|
||||
};
|
||||
|
||||
// log debug
|
||||
winston.logger.debug(
|
||||
`${uniqueCode} inserting payment recon transaction...`
|
||||
);
|
||||
|
||||
// insert payment recon transaction
|
||||
await model.insertPaymentReconTransaction(
|
||||
date,
|
||||
moment().format("YYYY-MM-DD HH:mm:ss"),
|
||||
getPartner.partner_code,
|
||||
PaymentReconNumber,
|
||||
bank_ref,
|
||||
reservation_number,
|
||||
amount,
|
||||
"F",
|
||||
"FAILED",
|
||||
result.code,
|
||||
result.message.toUpperCase(),
|
||||
result.data
|
||||
);
|
||||
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} RESPONSE payment recon: ${JSON.stringify(result)}`
|
||||
);
|
||||
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
|
||||
let totalTransactions = check.total_transaction;
|
||||
|
||||
if (totalTransactions > 1) {
|
||||
result = {
|
||||
code: "424",
|
||||
message: "Duplicate Ref No.",
|
||||
data: {
|
||||
payment_recon_no: PaymentReconNumber,
|
||||
recon_date: moment().format("YYYY-MM-DD HH:mm:ss"),
|
||||
},
|
||||
};
|
||||
|
||||
// log debug
|
||||
winston.logger.debug(
|
||||
`${uniqueCode} inserting payment recon transaction...`
|
||||
);
|
||||
|
||||
// insert payment recon transaction
|
||||
await model.insertPaymentReconTransaction(
|
||||
date,
|
||||
moment().format("YYYY-MM-DD HH:mm:ss"),
|
||||
getPartner.partner_code,
|
||||
PaymentReconNumber,
|
||||
bank_ref,
|
||||
reservation_number,
|
||||
amount,
|
||||
"F",
|
||||
"FAILED",
|
||||
result.code,
|
||||
result.message.toUpperCase(),
|
||||
result.data
|
||||
);
|
||||
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} RESPONSE payment recon: ${JSON.stringify(result)}`
|
||||
);
|
||||
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
|
||||
let totalAmount = check.total_amount;
|
||||
|
||||
if (parseInt(totalAmount) != parseInt(amount)) {
|
||||
result = {
|
||||
code: "425",
|
||||
message: "Total amount is different.",
|
||||
data: {
|
||||
payment_recon_no: PaymentReconNumber,
|
||||
recon_date: moment().format("YYYY-MM-DD HH:mm:ss"),
|
||||
},
|
||||
};
|
||||
|
||||
// log debug
|
||||
winston.logger.debug(
|
||||
`${uniqueCode} inserting payment recon transaction...`
|
||||
);
|
||||
|
||||
// insert payment recon transaction
|
||||
await model.insertPaymentReconTransaction(
|
||||
date,
|
||||
moment().format("YYYY-MM-DD HH:mm:ss"),
|
||||
getPartner.partner_code,
|
||||
PaymentReconNumber,
|
||||
bank_ref,
|
||||
reservation_number,
|
||||
amount,
|
||||
"F",
|
||||
"FAILED",
|
||||
result.code,
|
||||
result.message.toUpperCase(),
|
||||
result.data
|
||||
);
|
||||
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} RESPONSE payment recon: ${JSON.stringify(result)}`
|
||||
);
|
||||
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
|
||||
let data = {
|
||||
reservation_number: reservation_number,
|
||||
payment_recon_no: PaymentReconNumber,
|
||||
recon_date: moment().format("YYYY-MM-DD HH:mm:ss"),
|
||||
},
|
||||
};
|
||||
|
||||
// insert payment recon transaction
|
||||
await model.insertPaymentReconTransaction(
|
||||
date,
|
||||
moment().format("YYYY-MM-DD HH:mm:ss"),
|
||||
getPartner.partner_code,
|
||||
PaymentReconNumber,
|
||||
bank_ref,
|
||||
reservation_number,
|
||||
amount,
|
||||
"S",
|
||||
"SUCCESS",
|
||||
result.code,
|
||||
result.message.toUpperCase(),
|
||||
result.data
|
||||
);
|
||||
|
||||
// log info
|
||||
winston.logger.info(
|
||||
`${uniqueCode} RESPONSE payment recon: ${JSON.stringify(result)}`
|
||||
);
|
||||
|
||||
return res.status(200).json(result);
|
||||
date: date,
|
||||
time: moment().format("YYYY-MM-DD HH:mm:ss"),
|
||||
};
|
||||
|
||||
// log debug
|
||||
winston.logger.debug(`${uniqueCode} updating payment recon number...`);
|
||||
|
||||
let update = await model.updatePaymentReconNo(data);
|
||||
if (!update) {
|
||||
result = {
|
||||
code: "428",
|
||||
message:
|
||||
"failed recon. The other transaction with same data is running.",
|
||||
data: {
|
||||
payment_recon_no: PaymentReconNumber,
|
||||
recon_date: moment().format("YYYY-MM-DD HH:mm:ss"),
|
||||
},
|
||||
};
|
||||
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} RESPONSE payment recon: ${JSON.stringify(result)}`
|
||||
);
|
||||
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
|
||||
// log debug
|
||||
winston.logger.debug(
|
||||
`${uniqueCode} inserting payment recon transaction...`
|
||||
);
|
||||
|
||||
result = {
|
||||
code: "00",
|
||||
message: "success",
|
||||
data: {
|
||||
payment_recon_no: PaymentReconNumber,
|
||||
recon_date: moment().format("YYYY-MM-DD HH:mm:ss"),
|
||||
},
|
||||
};
|
||||
|
||||
// insert payment recon transaction
|
||||
await model.insertPaymentReconTransaction(
|
||||
date,
|
||||
moment().format("YYYY-MM-DD HH:mm:ss"),
|
||||
getPartner.partner_code,
|
||||
PaymentReconNumber,
|
||||
bank_ref,
|
||||
reservation_number,
|
||||
amount,
|
||||
"S",
|
||||
"SUCCESS",
|
||||
result.code,
|
||||
result.message.toUpperCase(),
|
||||
result.data
|
||||
);
|
||||
|
||||
// log info
|
||||
winston.logger.info(
|
||||
`${uniqueCode} RESPONSE payment recon: ${JSON.stringify(result)}`
|
||||
);
|
||||
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
} catch (error) {
|
||||
// create log
|
||||
@@ -428,6 +433,316 @@ const paymentRecon = async (req, res) => {
|
||||
}
|
||||
};
|
||||
|
||||
const paymentRecon = async (req, res) => {
|
||||
try {
|
||||
// generate unique code
|
||||
let uniqueCode = helper.getUniqueCode();
|
||||
let result = {};
|
||||
|
||||
// param
|
||||
let { date, bank_ref, reservation_number, amount } = req.body;
|
||||
let partner_id = req.partner_id_token;
|
||||
|
||||
// log info
|
||||
winston.logger.info(
|
||||
`${uniqueCode} REQUEST payment recon: ${JSON.stringify(req.body)}`
|
||||
);
|
||||
|
||||
// check validator
|
||||
const err = validationResult(req, res);
|
||||
if (!err.isEmpty()) {
|
||||
result = {
|
||||
code: "400",
|
||||
message: err.errors[0].msg,
|
||||
data: {},
|
||||
};
|
||||
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} RESPONSE payment recon: ${JSON.stringify(result)}`
|
||||
);
|
||||
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
|
||||
// time
|
||||
let now = moment().format("YYYY-MM-DD HH:mm:ss");
|
||||
|
||||
// log debug
|
||||
winston.logger.debug(`${uniqueCode} checking partner...`);
|
||||
|
||||
// get partner, merchant, terminal from tid
|
||||
let getPartner = await model.getPartnerByID(partner_id);
|
||||
if (!getPartner) {
|
||||
result = {
|
||||
code: "426",
|
||||
message: "Partner doesn't exists.",
|
||||
data: {},
|
||||
};
|
||||
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} RESPONSE payment recon: ${JSON.stringify(result)}`
|
||||
);
|
||||
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
|
||||
let partnerCode = getPartner.partner_code;
|
||||
let PaymentReconNumber;
|
||||
let maxLoop = 0;
|
||||
do {
|
||||
await _sleep(helper.randomNumberInt());
|
||||
PaymentReconNumber = await generatePaymentReconNumber(partnerCode, now);
|
||||
|
||||
if (maxLoop > maxLoopParameter) {
|
||||
// create log
|
||||
winston.logger.error(`server is busy. please try again.`);
|
||||
|
||||
return {
|
||||
code: "500",
|
||||
message:
|
||||
process.env.NODE_ENV != "production"
|
||||
? error.message
|
||||
: "server is busy. please try again.",
|
||||
data: {},
|
||||
};
|
||||
}
|
||||
|
||||
maxLoop++;
|
||||
} while (PaymentReconNumber == "XX");
|
||||
|
||||
// check ref no and amount
|
||||
let checkReservationNumberAndAmountAlreadyRecon =
|
||||
await model.checkReservationNumberAndAmountAlreadyRecon(
|
||||
reservation_number
|
||||
);
|
||||
if (checkReservationNumberAndAmountAlreadyRecon) {
|
||||
result = {
|
||||
code: "04",
|
||||
message: `success. Transaction has been recon at ${checkReservationNumberAndAmountAlreadyRecon.d_payment_recon}`,
|
||||
data: {
|
||||
payment_recon_no:
|
||||
checkReservationNumberAndAmountAlreadyRecon.c_payment_recon_no,
|
||||
recon_date:
|
||||
checkReservationNumberAndAmountAlreadyRecon.d_payment_recon,
|
||||
},
|
||||
};
|
||||
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} RESPONSE payment recon: ${JSON.stringify(result)}`
|
||||
);
|
||||
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
|
||||
// check ref no and amount
|
||||
let check = await model.checkReservationNumberAndAmount(reservation_number);
|
||||
if (!check) {
|
||||
result = {
|
||||
code: "427",
|
||||
message: "transaction doesn't exists",
|
||||
data: {
|
||||
payment_recon_no: PaymentReconNumber,
|
||||
recon_date: now,
|
||||
},
|
||||
};
|
||||
|
||||
// log debug
|
||||
winston.logger.debug(
|
||||
`${uniqueCode} inserting payment recon transaction...`
|
||||
);
|
||||
|
||||
// insert payment recon transaction
|
||||
await model.insertPaymentReconTransaction(
|
||||
date,
|
||||
now,
|
||||
getPartner.partner_code,
|
||||
PaymentReconNumber,
|
||||
bank_ref,
|
||||
reservation_number,
|
||||
amount,
|
||||
"F",
|
||||
"FAILED",
|
||||
result.code,
|
||||
result.message.toUpperCase(),
|
||||
result.data
|
||||
);
|
||||
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} RESPONSE payment recon: ${JSON.stringify(result)}`
|
||||
);
|
||||
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
|
||||
let totalTransactions = check.total_transaction;
|
||||
|
||||
if (totalTransactions > 1) {
|
||||
result = {
|
||||
code: "424",
|
||||
message: "Duplicate Ref No.",
|
||||
data: {
|
||||
payment_recon_no: PaymentReconNumber,
|
||||
recon_date: now,
|
||||
},
|
||||
};
|
||||
|
||||
// log debug
|
||||
winston.logger.debug(
|
||||
`${uniqueCode} inserting payment recon transaction...`
|
||||
);
|
||||
|
||||
// insert payment recon transaction
|
||||
await model.insertPaymentReconTransaction(
|
||||
date,
|
||||
now,
|
||||
getPartner.partner_code,
|
||||
PaymentReconNumber,
|
||||
bank_ref,
|
||||
reservation_number,
|
||||
amount,
|
||||
"F",
|
||||
"FAILED",
|
||||
result.code,
|
||||
result.message.toUpperCase(),
|
||||
result.data
|
||||
);
|
||||
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} RESPONSE payment recon: ${JSON.stringify(result)}`
|
||||
);
|
||||
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
|
||||
let totalAmount = check.total_amount;
|
||||
|
||||
if (parseInt(totalAmount) != parseInt(amount)) {
|
||||
result = {
|
||||
code: "425",
|
||||
message: "Total amount is different.",
|
||||
data: {
|
||||
payment_recon_no: PaymentReconNumber,
|
||||
recon_date: now,
|
||||
},
|
||||
};
|
||||
|
||||
// log debug
|
||||
winston.logger.debug(
|
||||
`${uniqueCode} inserting payment recon transaction...`
|
||||
);
|
||||
|
||||
// insert payment recon transaction
|
||||
await model.insertPaymentReconTransaction(
|
||||
date,
|
||||
now,
|
||||
getPartner.partner_code,
|
||||
PaymentReconNumber,
|
||||
bank_ref,
|
||||
reservation_number,
|
||||
amount,
|
||||
"F",
|
||||
"FAILED",
|
||||
result.code,
|
||||
result.message.toUpperCase(),
|
||||
result.data
|
||||
);
|
||||
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} RESPONSE payment recon: ${JSON.stringify(result)}`
|
||||
);
|
||||
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
|
||||
let data = {
|
||||
reservation_number: reservation_number,
|
||||
payment_recon_no: PaymentReconNumber,
|
||||
date: date,
|
||||
time: now,
|
||||
};
|
||||
|
||||
// log debug
|
||||
winston.logger.debug(`${uniqueCode} updating payment recon number...`);
|
||||
|
||||
let update = await model.updatePaymentReconNo(data);
|
||||
if (!update) {
|
||||
result = {
|
||||
code: "428",
|
||||
message:
|
||||
"failed recon. The other transaction with same data is running.",
|
||||
data: {
|
||||
payment_recon_no: PaymentReconNumber,
|
||||
recon_date: now,
|
||||
},
|
||||
};
|
||||
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} RESPONSE payment recon: ${JSON.stringify(result)}`
|
||||
);
|
||||
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
|
||||
// log debug
|
||||
winston.logger.debug(
|
||||
`${uniqueCode} inserting payment recon transaction...`
|
||||
);
|
||||
|
||||
result = {
|
||||
code: "00",
|
||||
message: "success",
|
||||
data: {
|
||||
payment_recon_no: PaymentReconNumber,
|
||||
recon_date: now,
|
||||
},
|
||||
};
|
||||
|
||||
// insert payment recon transaction
|
||||
await model.insertPaymentReconTransaction(
|
||||
date,
|
||||
now,
|
||||
getPartner.partner_code,
|
||||
PaymentReconNumber,
|
||||
bank_ref,
|
||||
reservation_number,
|
||||
amount,
|
||||
"S",
|
||||
"SUCCESS",
|
||||
result.code,
|
||||
result.message.toUpperCase(),
|
||||
result.data
|
||||
);
|
||||
|
||||
// log info
|
||||
winston.logger.info(
|
||||
`${uniqueCode} RESPONSE payment recon: ${JSON.stringify(result)}`
|
||||
);
|
||||
|
||||
return res.status(200).json(result);
|
||||
} catch (error) {
|
||||
// create log
|
||||
winston.logger.error(
|
||||
`500 internal server error - backend server | ${error.message}`
|
||||
);
|
||||
|
||||
return res.status(200).json({
|
||||
code: "500",
|
||||
message:
|
||||
process.env.NODE_ENV != "production"
|
||||
? error.message
|
||||
: "500 internal server error - backend server.",
|
||||
data: {},
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
// PAYMENT RECON SEMI TOPUP ONLINE
|
||||
const paymentReconSemiTopupOnline = async (req, res) => {
|
||||
try {
|
||||
|
||||
@@ -2,11 +2,14 @@ const { param, body, validationResult } = require("express-validator");
|
||||
const helper = require("../../helpers/helper");
|
||||
const winston = require("../../helpers/winston.logger");
|
||||
const model = require("./reservebalance.model");
|
||||
const queue = require("../../helpers/queue");
|
||||
const _sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
||||
const moment = require("moment");
|
||||
moment.locale("id");
|
||||
|
||||
var maxLoopParameter = 100;
|
||||
var dataReservationQueue = [];
|
||||
var isProcessing = false;
|
||||
|
||||
// VALIDATION
|
||||
const validate = (method) => {
|
||||
@@ -896,6 +899,215 @@ const reservation = async (req, res) => {
|
||||
);
|
||||
|
||||
return res.status(200).json(result);
|
||||
|
||||
// if (dataReservationQueue.length > 0) {
|
||||
// if (dataReservationQueue.includes(ref_no)) {
|
||||
// result = {
|
||||
// code: "432",
|
||||
// message: "refno is duplicate",
|
||||
// data: {},
|
||||
// };
|
||||
|
||||
// // log warn
|
||||
// winston.logger.warn(
|
||||
// `${uniqueCode} RESPONSE reservation: ${JSON.stringify(result)}`
|
||||
// );
|
||||
|
||||
// return res.status(200).json(result);
|
||||
// }
|
||||
// }
|
||||
|
||||
// dataReservationQueue = queue.reservationReceive(ref_no);
|
||||
|
||||
// console.log(dataReservationQueue);
|
||||
|
||||
// while (dataReservationQueue.length != 0) {
|
||||
|
||||
// if (dataReservationQueue[0] == ref_no && isProcessing == false) {
|
||||
// isProcessing = true;
|
||||
|
||||
// // generate reservation number
|
||||
// let reservationNumber;
|
||||
// let getReservationNumberSequence;
|
||||
// let reservationNoSequence;
|
||||
|
||||
// // log debug
|
||||
// winston.logger.debug(`${uniqueCode} checking reservation sequence...`);
|
||||
|
||||
// // get reservation
|
||||
// getReservationNumberSequence = await model.getReservationNumberSequence(
|
||||
// getPartner,
|
||||
// today
|
||||
// );
|
||||
|
||||
// reservationNoSequence = getReservationNumberSequence
|
||||
// ? parseInt(getReservationNumberSequence.i_reservation_no_seq) + 1
|
||||
// : 1;
|
||||
|
||||
// // log debug
|
||||
// winston.logger.debug(`${uniqueCode} generating reservation number...`);
|
||||
|
||||
// reservationNumber = await generateReservationNumber(
|
||||
// getPartner,
|
||||
// moment(today).format("YYMMDD"),
|
||||
// reservationNoSequence
|
||||
// );
|
||||
|
||||
// if (reservationNumber != "XX") {
|
||||
// queue.reservationFinish(dataReservationQueue);
|
||||
// isProcessing = false;
|
||||
|
||||
// // log debug
|
||||
// winston.logger.debug(
|
||||
// `${uniqueCode} getting reservation expiration date on parameter...`
|
||||
// );
|
||||
|
||||
// // get reservation expiration date by parameter
|
||||
// let getReservationExpirationDateValue =
|
||||
// await model.getReservationExpirationDateValue();
|
||||
// let time = getReservationExpirationDateValue.c_value
|
||||
// ? parseInt(getReservationExpirationDateValue.c_value)
|
||||
// : 1;
|
||||
|
||||
// // log debug
|
||||
// winston.logger.debug(
|
||||
// `${uniqueCode} getting reservation expiration date measure on parameter...`
|
||||
// );
|
||||
|
||||
// // get reservation expiration date measure by parameter
|
||||
// let getReservationExpirationDateMeasure =
|
||||
// await model.getReservationExpirationDateMeasure();
|
||||
// let measure = getReservationExpirationDateMeasure.c_value
|
||||
// ? getReservationExpirationDateMeasure.c_value
|
||||
// : "hours";
|
||||
|
||||
// let expired = moment(now)
|
||||
// .add(time, measure)
|
||||
// .format("YYYY-MM-DD HH:mm:ss");
|
||||
|
||||
// // binding data
|
||||
// let data = {
|
||||
// c_reservation_no: reservationNumber,
|
||||
// d_reservation: now,
|
||||
// c_ref_no: ref_no,
|
||||
// i_partner: getPartner ? getPartner.i_partner : null,
|
||||
// c_partner_code: getPartner ? getPartner.partner_code : null,
|
||||
// c_partner_name: getPartner ? getPartner.partner_name : null,
|
||||
// i_merchant: getPartner ? getPartner.i_merchant : null,
|
||||
// c_merchant_code: getPartner ? getPartner.merchant_code : null,
|
||||
// c_merchant_name: getPartner ? getPartner.merchant_name : null,
|
||||
// c_mid: getPartner ? getPartner.mid : null,
|
||||
// i_terminal: getPartner ? getPartner.i_terminal : null,
|
||||
// c_terminal_code: getPartner ? getPartner.terminal_code : null,
|
||||
// c_terminal_name: getPartner ? getPartner.terminal_name : null,
|
||||
// c_tid: getPartner ? getPartner.tid : null,
|
||||
// c_card_number: card_number,
|
||||
// i_reservation_amount: amount,
|
||||
// // i_issuer: getIssuer ? getIssuer.i_issuer : null,
|
||||
// // c_issuer_code: getIssuer ? getIssuer.issuer_code : null,
|
||||
// // c_issuer_name: getIssuer ? getIssuer.issuer_name : null,
|
||||
// i_issuer_fee: issuerFee,
|
||||
// // i_channel: null,
|
||||
// // c_channel_code: null,
|
||||
// // c_channel_name: null,
|
||||
// i_channel_fee: channelFee,
|
||||
// c_payment_ref_no: null,
|
||||
// i_reservation_no_seq: reservationNoSequence,
|
||||
// d_expired: expired,
|
||||
// d_load_balance: null,
|
||||
// c_load_balance_no: null,
|
||||
// c_status: "P",
|
||||
// c_status_name: "PENDING",
|
||||
// d_create: now,
|
||||
// i_create: null,
|
||||
// c_create_username: null,
|
||||
// c_create_fullname: null,
|
||||
// d_modify: null,
|
||||
// i_modify: null,
|
||||
// c_modify_username: null,
|
||||
// c_modify_fullname: null,
|
||||
// d_delete: null,
|
||||
// i_delete: null,
|
||||
// c_delete_username: null,
|
||||
// c_delete_fullname: null,
|
||||
// c_flag: "-1",
|
||||
// };
|
||||
|
||||
// // log debug
|
||||
// winston.logger.debug(
|
||||
// `${uniqueCode} inserting reservation transaction...`
|
||||
// );
|
||||
|
||||
// // insert transaction
|
||||
// let insert = await model.insertReservation(data);
|
||||
|
||||
// if (insert.rowCount < 1) {
|
||||
// // log debug
|
||||
// winston.logger.debug(
|
||||
// `${uniqueCode} deleting reservation number validate...`
|
||||
// );
|
||||
|
||||
// await model.deleteReservationNumberValidate(reservationNumber);
|
||||
|
||||
// result = {
|
||||
// code: "432",
|
||||
// message: "refno is duplicate",
|
||||
// data: {},
|
||||
// };
|
||||
|
||||
// // log warn
|
||||
// winston.logger.warn(
|
||||
// `${uniqueCode} RESPONSE reservation: ${JSON.stringify(result)}`
|
||||
// );
|
||||
|
||||
// return res.status(200).json(result);
|
||||
// }
|
||||
|
||||
// // log debug
|
||||
// winston.logger.debug(
|
||||
// `${uniqueCode} inserting log for card history...`
|
||||
// );
|
||||
|
||||
// // log card history
|
||||
// await model.createReserveBalanceLog({
|
||||
// i_log_name: 90,
|
||||
// d_log: now,
|
||||
// c_card_number: card_number,
|
||||
// c_source: "CMS",
|
||||
// c_location: getPartner ? getPartner.partner_name : null,
|
||||
// m_balance_before: balance > 0 ? balance : 0,
|
||||
// m_amount: 0,
|
||||
// m_balance_after: balance > 0 ? balance : 0,
|
||||
// j_new_data: data,
|
||||
// j_old_data: null,
|
||||
// c_note: `RESERVED BALANCE ${amount} FROM ${
|
||||
// getPartner ? getPartner.partner_name : null
|
||||
// } SUCCESSFULLY`,
|
||||
// c_status: "S",
|
||||
// d_created: now,
|
||||
// i_create: null,
|
||||
// c_create_username: "HSM",
|
||||
// c_create_fullname: "HARDWARE SECURE MODULE",
|
||||
// c_category: "T",
|
||||
// });
|
||||
|
||||
// result = {
|
||||
// code: "00",
|
||||
// message: "reservation saved successfully.",
|
||||
// data: {
|
||||
// reservation_number: reservationNumber,
|
||||
// },
|
||||
// };
|
||||
|
||||
// // log info
|
||||
// winston.logger.info(
|
||||
// `${uniqueCode} RESPONSE reservation: ${JSON.stringify(result)}`
|
||||
// );
|
||||
|
||||
// return res.status(200).json(result);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
} catch (error) {
|
||||
// create log
|
||||
winston.logger.error(
|
||||
|
||||
@@ -11,6 +11,7 @@ const checkCardNumber = (cardNumber) => {
|
||||
|
||||
// GET RESERVATION
|
||||
const getReservationNumberSequence = (data, date) => {
|
||||
console.log('AKU DIPANGGIL');
|
||||
let result = knex("trx.t_d_reservation_balance")
|
||||
.select("i_reservation_no_seq")
|
||||
.orderBy("i_reservation_no_seq", "desc")
|
||||
|
||||
Reference in New Issue
Block a user