This commit is contained in:
2022-08-31 17:07:48 +07:00
parent 4475e83160
commit f7e803532f
4 changed files with 353 additions and 3 deletions
@@ -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,
};
@@ -95,8 +95,11 @@ const checkReservation = async (req, res) => {
return res.status(200).json(result);
}
// log debug
winston.logger.debug(`${uniqueCode} checking reservation with pending status and in progress status...`);
// get reservation pending & in progress status
let checkSecure = false;
var checkSecure = false;
let getReservationWithPendingAndInProgressStatus =
await model.getReservationWithPendingAndInProgressStatus(card_number);
if (
@@ -10,4 +10,11 @@ router.post(
controller.paymentRecon
);
router.post(
"/payment-recon/semi-topup-online",
auth.authenticateToken,
controller.validate("paymentReconSemiTopupOnline"),
controller.paymentReconSemiTopupOnline
);
module.exports = router;
+11 -2
View File
@@ -1,8 +1,9 @@
# environment
NODE_ENV=development
PORT=3000
PORT=4000
# SYSTEM CODE IN HEXA STRING
# system code nutech profile
SYSTEM_CODE=939E
#SERVICE BLOCK
@@ -10,6 +11,14 @@ SERVICEBLOCK_SERVICE_MUTUAL="102001A04C2001A0882001A0"
SERVICEBLOCK_BLOCK_READ="80008200"
SERVICEBLOCK_BLOCK_WRITE="800081008200"
# system code kci profile
SYSTEM_CODE=90B7
#SERVICE BLOCK
SERVICEBLOCK_SERVICE_MUTUAL="101001A00C2001A0483001A0"
SERVICEBLOCK_BLOCK_READ="80008200"
SERVICEBLOCK_BLOCK_WRITE="800081008200"
# HSM DC (DATA CENTER)
# KCI PCI
URL_HSM_SERVER_1="ws://10.1.201.215/feliqserver/v1/wsapi"
@@ -34,7 +43,7 @@ SECRETKEY_HSM_SERVER_BACKUP_2="U5xs7nVonhtbQ+XiYATRSg8Nk5sPu1IpVx7X40KyWiw="
CHANGE_TO_DRC=NO
# HIGH AVABILITY (1 = SERVER_HSM_1 ONLY RUNNING, 2 = SERVER_HSM_2 ONLY RUNNING, 12 = SERVER_HSM_1 && SERVER_HSM_2 RUNNING)
NUMBER_SERVER_ACTIVE=2
NUMBER_SERVER_ACTIVE=12
# database
DB_URL=postgresql://postgres:postgres@localhost:5432/CMS_DEV