mirror of
https://github.com/mohamadihsan/topuponline.git
synced 2026-12-06 19:26:27 +00:00
update
This commit is contained in:
@@ -0,0 +1,142 @@
|
||||
const { param, body, validationResult } = require("express-validator");
|
||||
const helper = require("../../helpers/helper");
|
||||
const winston = require("../../helpers/winston.logger");
|
||||
const model = require("./paymentverification.model");
|
||||
const moment = require("moment");
|
||||
moment.locale("id");
|
||||
|
||||
var result = {};
|
||||
var uniqueCode;
|
||||
|
||||
// VALIDATION
|
||||
const validate = (method) => {
|
||||
switch (method) {
|
||||
case "paymentVerification":
|
||||
return [
|
||||
body("date")
|
||||
.not()
|
||||
.isEmpty()
|
||||
.withMessage("Date is required")
|
||||
.isDate({ format: "YYYY-MM-DD" })
|
||||
.withMessage("Invalid format date. Format is YYYY-MM-DD"),
|
||||
body("log")
|
||||
.not()
|
||||
.isEmpty()
|
||||
.withMessage("Log is required")
|
||||
.isArray()
|
||||
.withMessage("Log is invalid request"),
|
||||
];
|
||||
default:
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
// PAYMENT VERIFICATION
|
||||
const paymentVerification = async (req, res) => {
|
||||
try {
|
||||
// generate unique code
|
||||
uniqueCode = await helper.getUniqueCode();
|
||||
|
||||
// param
|
||||
let { log } = req.body;
|
||||
let mid = req.mid_token;
|
||||
let tid = req.tid_token;
|
||||
|
||||
// log info
|
||||
winston.logger.info(
|
||||
`${uniqueCode} REQUEST payment verification: ${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 verification: ${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.getPartner(mid, tid);
|
||||
if (!getPartner) {
|
||||
result = {
|
||||
code: "412",
|
||||
message: "terminal id is not valid",
|
||||
data: {},
|
||||
};
|
||||
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} RESPONSE payment verification: ${JSON.stringify(result)}`
|
||||
);
|
||||
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
|
||||
let data = [];
|
||||
|
||||
log.forEach(async (element) => {
|
||||
// check ref no and amount log
|
||||
let check = await model.checkRefNoAndAmount(
|
||||
element.ref_no,
|
||||
element.amount
|
||||
);
|
||||
if (!check) {
|
||||
result = {
|
||||
code: "412",
|
||||
message: "terminal id is not valid",
|
||||
data: {},
|
||||
};
|
||||
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} RESPONSE payment verification: ${JSON.stringify(
|
||||
result
|
||||
)}`
|
||||
);
|
||||
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
});
|
||||
|
||||
// log info
|
||||
winston.logger.info(
|
||||
`${uniqueCode} RESPONSE payment verification: ${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: {},
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
validate,
|
||||
paymentVerification,
|
||||
};
|
||||
Reference in New Issue
Block a user