From f7e803532fc529f72c3554efcf33afab5e4a2e41 Mon Sep 17 00:00:00 2001 From: Mohamad Ihsan Date: Wed, 31 Aug 2022 17:07:48 +0700 Subject: [PATCH] update --- .../paymentrecon/paymentrecon.controller.js | 331 ++++++++++++++++++ .../reservebalance.controller.js | 5 +- application/routes/paymentrecon.routes.js | 7 + env | 13 +- 4 files changed, 353 insertions(+), 3 deletions(-) diff --git a/application/modules/paymentrecon/paymentrecon.controller.js b/application/modules/paymentrecon/paymentrecon.controller.js index 5083aa8..782df96 100644 --- a/application/modules/paymentrecon/paymentrecon.controller.js +++ b/application/modules/paymentrecon/paymentrecon.controller.js @@ -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, }; diff --git a/application/modules/reservebalance/reservebalance.controller.js b/application/modules/reservebalance/reservebalance.controller.js index a74d6b0..b95521c 100644 --- a/application/modules/reservebalance/reservebalance.controller.js +++ b/application/modules/reservebalance/reservebalance.controller.js @@ -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 ( diff --git a/application/routes/paymentrecon.routes.js b/application/routes/paymentrecon.routes.js index 21a08d3..a38a3a5 100644 --- a/application/routes/paymentrecon.routes.js +++ b/application/routes/paymentrecon.routes.js @@ -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; diff --git a/env b/env index b81cdb6..ec80afd 100644 --- a/env +++ b/env @@ -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