mirror of
https://github.com/mohamadihsan/topuponline.git
synced 2026-12-06 21:26:28 +00:00
update
This commit is contained in:
@@ -30,6 +30,25 @@ const validate = (method) => {
|
||||
.isNumeric()
|
||||
.withMessage("Amount is invalid format"),
|
||||
];
|
||||
case "paymentReconSemiTopupOnline":
|
||||
return [
|
||||
body("date")
|
||||
.not()
|
||||
.isEmpty()
|
||||
.withMessage("Date is required")
|
||||
.isDate({ format: "YYYY-MM-DD" })
|
||||
.withMessage("Invalid format date. Format is YYYY-MM-DD"),
|
||||
body("settle_raw")
|
||||
.not()
|
||||
.isEmpty()
|
||||
.withMessage("Settle raw is required"),
|
||||
body("amount")
|
||||
.not()
|
||||
.isEmpty()
|
||||
.withMessage("Amount is required")
|
||||
.isNumeric()
|
||||
.withMessage("Amount is invalid format"),
|
||||
];
|
||||
case "paymentReconBulk":
|
||||
return [
|
||||
body("date")
|
||||
@@ -361,6 +380,317 @@ const paymentRecon = async (req, res) => {
|
||||
}
|
||||
};
|
||||
|
||||
// PAYMENT RECON SEMI TOPUP ONLINE
|
||||
const paymentReconSemiTopupOnline = async (req, res) => {
|
||||
try {
|
||||
// generate unique code
|
||||
uniqueCode = await helper.getUniqueCode();
|
||||
|
||||
// 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 {
|
||||
PaymentReconNumber = await generatePaymentReconNumber(partnerCode, now);
|
||||
|
||||
if (maxLoop > 20) {
|
||||
// create log
|
||||
winston.logger.error(
|
||||
`500 internal server error (max loop) - backend server | ${error.message}`
|
||||
);
|
||||
|
||||
return {
|
||||
code: "500",
|
||||
message:
|
||||
process.env.NODE_ENV != "production"
|
||||
? error.message
|
||||
: "500 internal server error (max loop) - backend server.",
|
||||
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 BULK
|
||||
const paymentReconBulk = async (req, res) => {
|
||||
try {
|
||||
@@ -497,5 +827,6 @@ const generatePaymentReconNumber = async (partnerCode, reconDate) => {
|
||||
module.exports = {
|
||||
validate,
|
||||
paymentRecon,
|
||||
paymentReconSemiTopupOnline,
|
||||
paymentReconBulk,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user