diff --git a/application/helpers/HMAC.js b/application/helpers/HMAC.js new file mode 100644 index 0000000..9e531f5 --- /dev/null +++ b/application/helpers/HMAC.js @@ -0,0 +1,13 @@ +const CryptoJS = require('crypto-js'); + +const createHMAC = async (payload) => { + let hash = await CryptoJS.HmacSHA256( + payload, + process.env.SECRET_KEY + ).toString(); + return hash; +}; + +module.exports = { + createHMAC, +}; diff --git a/application/modules/reservebalance/reservebalance.controller.js b/application/modules/reservebalance/reservebalance.controller.js index 37b4ac4..2a85c37 100644 --- a/application/modules/reservebalance/reservebalance.controller.js +++ b/application/modules/reservebalance/reservebalance.controller.js @@ -1,5 +1,6 @@ const { param, body, validationResult } = require('express-validator'); const helper = require('../../helpers/helper'); +const hmac = require('../../helpers/HMAC'); const winston = require('../../helpers/winston.logger'); const model = require('./reservebalance.model'); const _sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms)); @@ -634,6 +635,424 @@ const reservationValidate = async (req, res) => { } }; +// ================================================================= RESERVATION VALIDATE V2 ================================================================= +// *Created By: Mohamad Ihsan* +// *Description:* +// proses yang digunakan untuk melakukan validasi reservasi saldo. Proses ini seharusnya dilakukan terlebih dahulu sebelum melakukan insert data reservasi ke sistem CMS +// pada proses reservation validate version 2 ini, akan di generate berupa security code yang nanti nya akan digunakan sebagai keamanan data saat melakukan insert data reservasi + +const reservationValidateV2 = async (req, res) => { + try { + // generate unique code + // unique code ini digunakan untuk keperluan log agar mudah untuk dibaca + let uniqueCode = await helper.getUniqueCode(); + let result = {}; + + // param + let { mid, tid, card_number, amount } = req.body; + + // log info + winston.logger.info( + `${uniqueCode} [ REQUEST RESERVATION-VALIDATE-V2 ]: ${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 RESERVATION-VALIDATE-V2 ]: ${JSON.stringify( + result + )}` + ); + + return res.status(200).json(result); + } + + // log debug + // pengecekkan nomor kartu yang di request adalah kartu production atau bukan berdasarkan settingan di .ENV dengan constanta SERVER_FOR. + // Jika settingan .ENV SERVER_FOR adalah production dan nomor kartu KMT yang di request adalah kartu development maka sistem online topup akan menolaknya. Begitupun sebaliknya + // Begitupun sebaliknya, jika settingan .ENV SERVER_FOR adalah development dan nomor kartu KMT yang di request adalah kartu production maka sistem online topup akan menolaknya + winston.logger.debug( + `${uniqueCode} [ PROCESSING RESERVATION-VALIDATE-V2 ] checking production card number or not...` + ); + + // jika settingan diperuntukan untuk production + if (process.env.SERVER_FOR == 'production') { + // kartu yang di request bukan kartu production maka akan di tolak + if (card_number.substring(0, 1) != '1') { + result = { + code: '400', + message: "It's not production card number.", + data: {}, + }; + + // log warn + winston.logger.warn( + `${uniqueCode} [ RESPONSE RESERVATION-VALIDATE-V2 ]: ${JSON.stringify( + result + )}` + ); + + return res.status(200).json(result); + } + } else { + // jika settingan bukan diperuntukan untuk production, bisa development atau local atau yang lainnya dan kemudian kartu yang di request merupakan kartu production maka akan di tolak + if (card_number.substring(0, 1) == '1') { + result = { + code: '400', + message: + "It's production card number. Please use the development card number.", + data: {}, + }; + + // log warn + winston.logger.warn( + `${uniqueCode} [ RESPONSE RESERVATION-VALIDATE-V2 ]: ${JSON.stringify( + result + )}` + ); + + return res.status(200).json(result); + } + } + + // time + let now = moment().format('YYYY-MM-DD HH:mm:ss'); + let today = moment().format('YYYY-MM-DD'); + let year = moment().format('Y'); + let month = moment().format('M'); + + // log debug + // proses pengecekkan data partner berdasarkan mid dan tid yang di request, apakah terdaftar di sistem CMS atau tidak + winston.logger.debug( + `${uniqueCode} [ PROCESSING RESERVATION-VALIDATE-V2 ] checking partner...` + ); + + // get partner, merchant, terminal from tid + let getPartner = await model.getPartner(mid, tid); + + // jika partner (mid atau tid) tidak ditemukan atau tidak terdaftar di sistem CMS + if (!getPartner) { + result = { + code: '412', + message: 'terminal id is not valid', + data: {}, + }; + + // log warn + winston.logger.warn( + `${uniqueCode} [ RESPONSE RESERVATION-VALIDATE-V2 ]: ${JSON.stringify( + result + )}` + ); + + return res.status(200).json(result); + } + + // log debug + // get settingan dari parameter apakah nomor kartu yang di request harus di cek dengan data card product CMS atau tidak + winston.logger.debug( + `${uniqueCode} [ PROCESSING RESERVATION-VALIDATE-V2 ] getting checking card number by card product CMS status on parameter...` + ); + + // get parameter to check with card product cms or not + let getCheckByCardProductStatusValue = + await model.getCheckByCardProductStatusValue(); + let checkByCardProductStatusValue = + getCheckByCardProductStatusValue?.c_value; + + // jika settingan pengecekkan nomor kartu yang di request dengan data card product yang ada di sistem CMS aktif + if (checkByCardProductStatusValue == 'A') { + // log debug + winston.logger.debug( + `${uniqueCode} [ PROCESSING RESERVATION-VALIDATE-V2 ] checking card number...` + ); + + // check card number yang di request terdaftar di card product CMS atau tidak + let checkCardNumber = await model.checkCardNumber(card_number); + + // jika nomor kartu yang di request tidak terdaftar di card prouct CMS + if (!checkCardNumber) { + result = { + code: '413', + message: 'card number is not registered', + data: {}, + }; + + // log warn + winston.logger.warn( + `${uniqueCode} [ RESPONSE RESERVATION-VALIDATE-V2 ]: ${JSON.stringify( + result + )}` + ); + + return res.status(200).json(result); + } + } + + // log debug + winston.logger.debug( + `${uniqueCode} [ PROCESSING RESERVATION-VALIDATE-V2 ] checking reservation amount...` + ); + + // check reservation amount + // amount reservasi harus lebih dari 0 + if (parseInt(amount) <= 0) { + result = { + code: '415', + message: 'amount must be greater than 0', + data: {}, + }; + + // log warn + winston.logger.warn( + `${uniqueCode} [ RESPONSE RESERVATION-VALIDATE-V2 ]: ${JSON.stringify( + result + )}` + ); + + return res.status(200).json(result); + } + + // log debug + // proses pencarian saldo terakhir dari nomor kartu yang di request berdasarkan data log hitory + winston.logger.debug( + `${uniqueCode} [ PROCESSING RESERVATION-VALIDATE-V2 ] getting last balance on the card by card history...` + ); + + // get last balance on the card + let balance = 0; + let getLastBalanceFromCardHistory = + await model.getLastBalanceFromCardHistory(card_number); + if (getLastBalanceFromCardHistory) { + balance = getLastBalanceFromCardHistory.m_balance_after; + } + + // log debug + winston.logger.debug( + `${uniqueCode} [ PROCESSING RESERVATION-VALIDATE-V2 ] checking BI regulation status...` + ); + + // get settingan terkait pengecekkan regulasi BI dari parameter, apakah diaktifkan atau tidak + const getBIRegulationStatus = await model.getBIRegulationStatus(); + + // jika pengecekkan regulasi BI diaktifkan + if (getBIRegulationStatus.c_value == 'A') { + // log debug + // get maksimum saldo yang harus ada di dalam kartu berdasarkan settingan parameter di sistem CMS + winston.logger.debug( + `${uniqueCode} [ PROCESSING RESERVATION-VALIDATE-V2 ] checking max balance on the card...` + ); + + // get max saldo on the card + const getMaxAmountOnTheCard = await model.getMaxAmountOnTheCard(); + + // jika settingan paremeter maksimum saldo di dalam kartu ditemukan + if (getMaxAmountOnTheCard.c_value) { + // jika saldo dalam kartu diakumulasikan dengan amount reservasi dan jumlah nya ternyata melebihi jumlah maksimum saldo berdasarkan settingan parameter, maka akan transaksi akan di tolak + if ( + parseInt(balance) + parseInt(amount) > + parseInt(getMaxAmountOnTheCard.c_value) + ) { + result = { + code: '416', + message: 'your card number has reached the maximum balance', + data: {}, + }; + + // log warn + winston.logger.warn( + `${uniqueCode} [ RESPONSE RESERVATION-VALIDATE-V2 ]: ${JSON.stringify( + result + )}` + ); + + return res.status(200).json(result); + } + } + + // log debug + // proses pengecekkan akumulasi maksimum topup di bulan berjalan berdasarkan parameter setting di sistem CMS + winston.logger.debug( + `${uniqueCode} [ PROCESSING RESERVATION-VALIDATE-V2 ] checking max topup per month...` + ); + + // get accumulated balance in this month dari nomor kartu yang di request + let accumulatedBalance = 0; + let getAccumulationBalanceInThisMonthFromCardHistory = + await model.getAccumulationBalanceInThisMonthFromCardHistory( + card_number, + year, + month + ); + + // jika ditemukan history akumulasi topup dari nomor kartu yang di request, maka set akumulasi saldo di bulan berjalan sama dengan history yang ditemukan + if (getAccumulationBalanceInThisMonthFromCardHistory) { + accumulatedBalance = + getAccumulationBalanceInThisMonthFromCardHistory.accumulation_balance; + } + + // validate max topup per month berdasarkan parameter setting + const getMaxTopupPerMonth = await model.getMaxTopupPerMonth(); + + // jika settingan parameter maksimum akumulasi topup dalam sebulan ditemukan + if (getMaxTopupPerMonth.c_value) { + // jika akumulasi saldo kartu yang di request dijumlahkan dengan amount reservasi dan ternyata melebihi jumlah akumulasi maksumum topup dalam sebelum, maka transaksi akan di tolak + if ( + parseInt(accumulatedBalance) + parseInt(amount) > + parseInt(getMaxTopupPerMonth.c_value) + ) { + result = { + code: '417', + message: 'your card number has been limit top up for this month', + data: {}, + }; + + // log warn + winston.logger.warn( + `${uniqueCode} [ RESPONSE RESERVATION-VALIDATE-V2 ]: ${JSON.stringify( + result + )}` + ); + + return res.status(200).json(result); + } + } + } + + // log debug + // proses pengecekkan maksimum reservasi dengna status pending di parameter setting sistem CMS + winston.logger.debug( + `${uniqueCode} [ PROCESSING RESERVATION-VALIDATE-V2 ] checking max reservation...` + ); + + // get maksimum reservation dengan status pending dari parameter setting + let getMaxReservation = await model.getMaxReservation(); + + // jika parameter setting maksimum reservasi dengan status pending tidak ditemukan maka set menjadi 0 + let maxReservation = getMaxReservation.c_value + ? parseInt(getMaxReservation.c_value) + : 0; + + // log debug + // proses pencarian transaki dari table reservasi balance berdasarkan nomor kartu yang di request + winston.logger.debug( + `${uniqueCode} [ PROCESSING RESERVATION-VALIDATE-V2 ] checking total reservation pending...` + ); + + // get total reservation pending bersarkan nomor kartu yang di request yaitu total transaksi yang status nya pending beserta jumlah amount nya + let getReservationPending = await model.getReservationPending( + card_number, + now + ); + + // jika nomor kartu yang di request ditemukan transaksi reservasi dengan status pending pada transaksi sebelumnya, maka jumlahkan total amount reservasi sebelumnya dengan amount reservasi yang dilakukan sekarang + let totalReservationPending = + getReservationPending.total_nominal_reservation > 0 + ? parseInt(getReservationPending.total_nominal_reservation) + + parseInt(amount) + : parseInt(amount); + + // jika total amount reservasi melebihi maksimum reservasi sesuai dengan parameter setting di sistem CMS maka transaksi akan di tolak + if (totalReservationPending > maxReservation) { + result = { + code: '421', + message: + 'your card number has some pending transaction. Please finished it!', + data: {}, + }; + + // log warn + winston.logger.warn( + `${uniqueCode} [ RESPONSE RESERVATION-VALIDATE-V2 ]: ${JSON.stringify( + result + )}` + ); + + return res.status(200).json(result); + } + + // log debug + // process mendapatkan persentase issuer fee dan channel free berdasarkan settingan dari sistem CMS + winston.logger.debug( + `${uniqueCode} [ PROCESSING RESERVATION-VALIDATE-V2 ] getting issuer fee and channel fee...` + ); + + // set default issuer fee + let issuerFee = 0; + let channelFee = 0; + + // get issuer fee dan channel fee dari table public.t_c_partner_fee + let getIssuer = await model.getIssuer(getPartner.i_partner, now); + if (getIssuer) { + issuerFee = + (getIssuer.i_issuer_fee_perc / 100) * parseInt(getIssuer.i_amount); + channelFee = + (getIssuer.i_channel_fee_perc / 100) * parseInt(getIssuer.i_amount); + } + // if (!getIssuer) { + // return res.status(200).json({ + // code: "403", + // message: "issuer doesn't exist", + // data: {}, + // }); + // } + + // log debug + // process mendapatkan persentase issuer fee dan channel free berdasarkan settingan dari sistem CMS + winston.logger.debug( + `${uniqueCode} [ PROCESSING RESERVATION-VALIDATE-V2 ] generating security code...` + ); + + let hash = card_number + amount + moment().format('YYYYMMDDHHmm'); + let securityCode = await hmac.createHMAC(hash); + + result = { + code: '00', + message: 'validation successfully.', + data: { + reservation: { + card_number: card_number, + amount: amount, + }, + security_code: securityCode, + }, + }; + + // log info + winston.logger.info( + `${uniqueCode} [ RESPONSE RESERVATION-VALIDATE-V2 ]: ${JSON.stringify( + result + )}` + ); + + return res.status(200).json(result); + } catch (error) { + // create log + winston.logger.error( + `[ RESPONSE RESERVATION-VALIDATE-V2 ]: 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: {}, + }); + } +}; + // ================================================================= RESERVATION ================================================================= // *Created By: Mohamad Ihsan* // *Description:* @@ -1234,6 +1653,662 @@ const reservation = async (req, res) => { } }; +// ================================================================= RESERVATION V2 ================================================================= +// *Created By: Mohamad Ihsan* +// *Description:* +// proses insert data transaksi reservasi saldo. Proses ini dilakukan setelah melakukan reservation validate dengan response code 00. Output dari proses ini adalah kode reservation number dan informasi reservasi saldo yang dilakukan +// pada reservation version 2 ini data yang dikirim akan di cek terlebih dahulu sebelum dilakukan insert data, hal ini bertujuan agar data yang dikirim tidak doubah dalam proses perjalanan setelah melakukan reservation validate + +const reservationV2 = async (req, res) => { + try { + // generate unique code + // unique code ini digunakan untuk keperluan log agar mudah untuk dibaca + let uniqueCode = helper.getUniqueCode(); + let result = {}; + + // param + let { mid, tid, card_number, amount, ref_no } = req.body; + const security_code = req.header('Reservation-Security-Code'); + + // log info + winston.logger.info( + `${uniqueCode} [ REQUEST RESERVATION-V2 ]: ${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 RESERVATION-V2 ]: ${JSON.stringify(result)}` + ); + + return res.status(200).json(result); + } + + // cek security code di header request + if (!security_code) { + result = { + code: '400', + message: 'reservation security code is required', + data: {}, + }; + + // log warn + winston.logger.warn( + `${uniqueCode} [ RESPONSE RESERVATION-V2 ]: ${JSON.stringify(result)}` + ); + + return res.status(200).json(result); + } + + // log debug + // pengecekkan konten data yang dikirim dengan security code yang dikirim + winston.logger.debug( + `${uniqueCode} [ PROCESSING RESERVATION-V2 ] checking content data request and security code...` + ); + + let hash = card_number + amount + moment().format('YYYYMMDDHHmm'); + let hash1 = + card_number + + amount + + moment().subtract(1, 'minutes').format('YYYYMMDDHHmm'); + let hash2 = + card_number + amount + moment().add(1, 'minutes').format('YYYYMMDDHHmm'); + + let securityCode = []; + securityCode.push(await hmac.createHMAC(hash)); + securityCode.push(await hmac.createHMAC(hash1)); + securityCode.push(await hmac.createHMAC(hash2)); + + if (!securityCode.includes(security_code)) { + result = { + code: '435', + message: 'bad request. content data is invalid.', + data: {}, + }; + + // log warn + winston.logger.warn( + `${uniqueCode} [ RESPONSE RESERVATION-V2 ]: ${JSON.stringify(result)}` + ); + + return res.status(200).json(result); + } + + // log debug + // pengecekkan nomor kartu yang di request adalah kartu production atau bukan berdasarkan settingan di .ENV dengan constanta SERVER_FOR. + // Jika settingan .ENV SERVER_FOR adalah production dan nomor kartu KMT yang di request adalah kartu development maka sistem online topup akan menolaknya. Begitupun sebaliknya + // Begitupun sebaliknya, jika settingan .ENV SERVER_FOR adalah development dan nomor kartu KMT yang di request adalah kartu production maka sistem online topup akan menolaknya + winston.logger.debug( + `${uniqueCode} [ PROCESSING RESERVATION-V2 ] checking production card number or not...` + ); + + // jika settingan diperuntukan untuk production + if (process.env.SERVER_FOR == 'production') { + // kartu yang di request bukan kartu production maka akan di tolak + if (card_number.substring(0, 1) != '1') { + result = { + code: '400', + message: "It's not production card number.", + data: {}, + }; + + // log warn + winston.logger.warn( + `${uniqueCode} [ RESPONSE RESERVATION-V2 ]: ${JSON.stringify(result)}` + ); + + return res.status(200).json(result); + } + } else { + // jika settingan bukan diperuntukan untuk production, bisa development atau local atau yang lainnya dan kemudian kartu yang di request merupakan kartu production maka akan di tolak + if (card_number.substring(0, 1) == '1') { + result = { + code: '400', + message: + "It's production card number. Please use the development card number.", + data: {}, + }; + + // log warn + winston.logger.warn( + `${uniqueCode} [ RESPONSE RESERVATION-V2 ]: ${JSON.stringify(result)}` + ); + + return res.status(200).json(result); + } + } + + // time + let now = moment().format('YYYY-MM-DD HH:mm:ss'); + let today = moment().format('YYYY-MM-DD'); + let year = moment().format('Y'); + let month = moment().format('M'); + + // log debug + // proses pengecekkan data partner berdasarkan mid dan tid yang di request, apakah terdaftar di sistem CMS atau tidak + winston.logger.debug( + `${uniqueCode} [ PROCESSING RESERVATION-V2 ] 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 RESERVATION-V2 ]: ${JSON.stringify(result)}` + ); + + return res.status(200).json(result); + } + + // log debug + // get settingan dari parameter apakah nomor kartu yang di request harus di cek dengan data card product CMS atau tidak + winston.logger.debug( + `${uniqueCode} [ PROCESSING RESERVATION-VALIDATE ] getting checking card number by card product CMS status on parameter...` + ); + + // get parameter to check with card product cms or not + let getCheckByCardProductStatusValue = + await model.getCheckByCardProductStatusValue(); + let checkByCardProductStatusValue = + getCheckByCardProductStatusValue?.c_value; + + // jika settingan pengecekkan nomor kartu yang di request dengan data card product yang ada di sistem CMS aktif + if (checkByCardProductStatusValue == 'A') { + // log debug + winston.logger.debug( + `${uniqueCode} [ PROCESSING RESERVATION-V2 ] checking card number...` + ); + + // check card number yang di request terdaftar di card product CMS atau tidak + let checkCardNumber = await model.checkCardNumber(card_number); + if (!checkCardNumber) { + result = { + code: '413', + message: 'card number is not registered', + data: {}, + }; + + // log warn + winston.logger.warn( + `${uniqueCode} [ RESPONSE RESERVATION-V2 ]: ${JSON.stringify(result)}` + ); + + return res.status(200).json(result); + } + } + + // log debug + winston.logger.debug( + `${uniqueCode} [ PROCESSING RESERVATION-V2 ] checking reservation amount...` + ); + + // check reservation amount + // amount reservasi harus lebih dari 0 + if (parseInt(amount) <= 0) { + result = { + code: '415', + message: 'amount must be greater than 0', + data: {}, + }; + + // log warn + winston.logger.warn( + `${uniqueCode} [ RESPONSE RESERVATION-V2 ]: ${JSON.stringify(result)}` + ); + + return res.status(200).json(result); + } + + // log debug + // proses pencarian saldo terakhir dari nomor kartu yang di request berdasarkan data log hitory + winston.logger.debug( + `${uniqueCode} [ PROCESSING RESERVATION-V2 ] getting last balance on the card by card history...` + ); + + // get last balance on the card + let balance = 0; + let getLastBalanceFromCardHistory = + await model.getLastBalanceFromCardHistory(card_number); + if (getLastBalanceFromCardHistory) { + balance = getLastBalanceFromCardHistory.m_balance_after; + } + + // log debug + winston.logger.debug( + `${uniqueCode} [ PROCESSING RESERVATION-V2 ] checking BI regulation status...` + ); + + // get settingan terkait pengecekkan regulasi BI dari parameter, apakah diaktifkan atau tidak + const getBIRegulationStatus = await model.getBIRegulationStatus(); + if (getBIRegulationStatus.c_value == 'A') { + // log debug + // get maksimum saldo yang harus ada di dalam kartu berdasarkan settingan parameter di sistem CMS + winston.logger.debug( + `${uniqueCode} [ PROCESSING RESERVATION-V2 ] checking max balance on the card...` + ); + + // get max saldo on the card + const getMaxAmountOnTheCard = await model.getMaxAmountOnTheCard(); + // jika settingan paremeter maksimum saldo di dalam kartu ditemukan + if (getMaxAmountOnTheCard.c_value) { + // jika saldo dalam kartu diakumulasikan dengan amount reservasi dan jumlah nya ternyata melebihi jumlah maksimum saldo berdasarkan settingan parameter, maka akan transaksi akan di tolak + if ( + parseInt(balance) + parseInt(amount) > + parseInt(getMaxAmountOnTheCard.c_value) + ) { + result = { + code: '416', + message: 'your card number has reached the maximum balance', + data: {}, + }; + + // log warn + winston.logger.warn( + `${uniqueCode} [ RESPONSE RESERVATION-V2 ]: ${JSON.stringify( + result + )}` + ); + + return res.status(200).json(result); + } + } + + // log debug + // proses pengecekkan akumulasi maksimum topup di bulan berjalan berdasarkan parameter setting di sistem CMS + winston.logger.debug( + `${uniqueCode} [ PROCESSING RESERVATION-V2 ] checking max topup per month...` + ); + + // get accumulated balance in this month dari nomor kartu yang di request + let accumulatedBalance = 0; + let getAccumulationBalanceInThisMonthFromCardHistory = + await model.getAccumulationBalanceInThisMonthFromCardHistory( + card_number, + year, + month + ); + + // jika ditemukan history akumulasi topup dari nomor kartu yang di request, maka set akumulasi saldo di bulan berjalan sama dengan history yang ditemukan + if (getAccumulationBalanceInThisMonthFromCardHistory) { + accumulatedBalance = + getAccumulationBalanceInThisMonthFromCardHistory.accumulation_balance; + } + + // validate max topup per month berdasarkan parameter setting + const getMaxTopupPerMonth = await model.getMaxTopupPerMonth(); + + // jika settingan parameter maksimum akumulasi topup dalam sebulan ditemukan + if (getMaxTopupPerMonth.c_value) { + // jika akumulasi saldo kartu yang di request dijumlahkan dengan amount reservasi dan ternyata melebihi jumlah akumulasi maksumum topup dalam sebelum, maka transaksi akan di tolak + if ( + parseInt(accumulatedBalance) + parseInt(amount) > + parseInt(getMaxTopupPerMonth.c_value) + ) { + result = { + code: '417', + message: 'your card number has been limit top up for this month', + data: {}, + }; + + // log warn + winston.logger.warn( + `${uniqueCode} [ RESPONSE RESERVATION-V2 ]: ${JSON.stringify( + result + )}` + ); + + return res.status(200).json(result); + } + } + } + + // log debug + // proses pengecekkan maksimum reservasi dengna status pending di parameter setting sistem CMS + winston.logger.debug( + `${uniqueCode} [ PROCESSING RESERVATION-V2 ] checking max reservation...` + ); + + // get maksimum reservation dengan status pending dari parameter setting + let getMaxReservation = await model.getMaxReservation(); + let maxReservation = getMaxReservation.c_value + ? parseInt(getMaxReservation.c_value) + : 0; + + // // log debug + // winston.logger.debug(`${uniqueCode} [ PROCESSING RESERVATION-V2 ] checking reservation with flag...`); + + // // get reservation with flag + // let reservationWithFlag = await model.getReservationWithFlag( + // card_number, + // now + // ); + // let totalReservationWithFlag = + // reservationWithFlag.total_reservation > 0 + // ? reservationWithFlag.total_reservation + // : 0; + // if (totalReservationWithFlag > 0) { + // result = { + // code: "420", + // message: + // "your card number has incomplete transaction. Please unload your balance!", + // data: {}, + // }; + + // // log warn + // winston.logger.warn( + // `${uniqueCode} [ RESPONSE RESERVATION-V2 ]: ${JSON.stringify(result)}` + // ); + + // return res.status(200).json(result); + // } + + // log debug + // proses pencarian transaki dari table reservasi balance berdasarkan nomor kartu yang di request + winston.logger.debug( + `${uniqueCode} [ PROCESSING RESERVATION-V2 ] checking total reservation pending...` + ); + + // get total reservation pending bersarkan nomor kartu yang di request yaitu total transaksi yang status nya pending beserta jumlah amount nya + let getReservationPending = await model.getReservationPending( + card_number, + now + ); + + // jika nomor kartu yang di request ditemukan transaksi reservasi dengan status pending pada transaksi sebelumnya, maka jumlahkan total amount reservasi sebelumnya dengan amount reservasi yang dilakukan sekarang + let totalReservationPending = + getReservationPending.total_nominal_reservation > 0 + ? parseInt(getReservationPending.total_nominal_reservation) + + parseInt(amount) + : parseInt(amount); + + // jika total amount reservasi melebihi maksimum reservasi sesuai dengan parameter setting di sistem CMS maka transaksi akan di tolak + if (totalReservationPending > maxReservation) { + result = { + code: '421', + message: + 'your card number has some pending transaction. Please finished it!', + data: {}, + }; + + // log warn + winston.logger.warn( + `${uniqueCode} [ RESPONSE RESERVATION-V2 ]: ${JSON.stringify(result)}` + ); + + return res.status(200).json(result); + } + + // log debug + // process mendapatkan persentase issuer fee dan channel free berdasarkan settingan dari sistem CMS + winston.logger.debug( + `${uniqueCode} [ PROCESSING RESERVATION-V2 ] getting issuer fee and channel fee...` + ); + + // set default issuer fee + let issuerFee = 0; + let channelFee = 0; + + // get issuer fee dan channel fee dari table public.t_c_partner_fee + let getIssuer = await model.getIssuer(getPartner.i_partner, now); + if (getIssuer) { + issuerFee = + (getIssuer.i_issuer_fee_perc / 100) * parseInt(getIssuer.i_amount); + channelFee = + (getIssuer.i_channel_fee_perc / 100) * parseInt(getIssuer.i_amount); + } + // if (!getIssuer) { + // return res.status(200).json({ + // code: "403", + // message: "issuer doesn't exist", + // data: {}, + // }); + // } + + // generate reservation number + let reservationNumber; + let getReservationNumberSequence; + let reservationNoSequence; + let maxLoop = 0; + + do { + await _sleep(helper.randomNumberInt()); + + // log debug + // proses pencarian sequence terakhir dari transaksi reservasi saldo berdasarkan partner di hari ini + winston.logger.debug( + `${uniqueCode} [ PROCESSING RESERVATION-V2 ] 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} [ PROCESSING RESERVATION-V2 ] generating reservation number...` + ); + + // proses genereate reservasi number untuk transaksi reservasi saldo yang dilakukan + reservationNumber = await generateReservationNumber( + getPartner, + moment(today).format('YYMMDD'), + reservationNoSequence + ); + + // kondisi jika reservasi number yang digenerate selalu mendapatkan kode yang sudha digunakan / tidak unique + 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 (reservationNumber == 'XX'); + + // log debug + // proses pengecekkan value dari setting parameter untuk data reservasi yang tidak di load/topup apakah statusnya diaktifkan atau tidak + winston.logger.debug( + `${uniqueCode} [ PROCESSING RESERVATION-V2 ] 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 + // proses pengecekkan satuan setting parameter untuk data reservasi yang tidak di load/topup di set dalam satuan apa, bisa jam atau hari dan sebagainya + winston.logger.debug( + `${uniqueCode} [ PROCESSING RESERVATION-V2 ] 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} [ PROCESSING RESERVATION-V2 ] inserting reservation transaction...` + ); + + // insert transaction + let insert = await model.insertReservation(data); + + // jika proses insert data semua yang berkaitan dengan reservasi saldo mengalami kegagalan, maka lakukan rollback + // kegagalan insert data transaksi bisa disebabkan karena data ref no yang di berikan client sudah digunakan + if (insert.rowCount < 1) { + // log debug + winston.logger.debug( + `${uniqueCode} [ PROCESSING RESERVATION-V2 ] deleting reservation number validate...` + ); + + // delete data reservasi yang mengalami kegagalan insert data + await model.deleteReservationNumberValidate(reservationNumber); + + result = { + code: '432', + message: 'refno is duplicate', + data: {}, + }; + + // log warn + winston.logger.warn( + `${uniqueCode} [ RESPONSE RESERVATION-V2 ]: ${JSON.stringify(result)}` + ); + + return res.status(200).json(result); + } + + // log debug + winston.logger.debug( + `${uniqueCode} [ PROCESSING RESERVATION-V2 ] 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, + reservation_time: now, + partner: getPartner ? getPartner.partner_name : null, + merchant: getPartner ? getPartner.merchant_name : null, + terminal: getPartner ? getPartner.terminal_name : null, + card_number: card_number, + reserved_amount: amount, + issuer_fee: issuerFee, + channel_fee: channelFee, + }, + }; + + // log info + winston.logger.info( + `${uniqueCode} [ RESPONSE RESERVATION-V2 ]: ${JSON.stringify(result)}` + ); + + return res.status(200).json(result); + } catch (error) { + // create log + winston.logger.error( + `[ RESPONSE RESERVATION-V2 ]: 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: {}, + }); + } +}; + // ================================================================= GENERATE RESERVATION NUMBER ================================================================= // *Created By: Mohamad Ihsan* // *Description:* @@ -1869,7 +2944,9 @@ module.exports = { validate, checkReservation, reservationValidate, + reservationValidateV2, reservation, + reservationV2, cancelReservationValidate, cancelReservation, inquiryReservation, diff --git a/application/routes/reservebalance.routes.js b/application/routes/reservebalance.routes.js index 720a963..c17252d 100644 --- a/application/routes/reservebalance.routes.js +++ b/application/routes/reservebalance.routes.js @@ -1,59 +1,75 @@ -const express = require("express"); +const express = require('express'); const router = express.Router(); -const auth = require("../middlewares/jwt.middleware"); -const controller = require("../modules/reservebalance/reservebalance.controller"); +const auth = require('../middlewares/jwt.middleware'); +const controller = require('../modules/reservebalance/reservebalance.controller'); +// ================================================================= ROUTE V1 ================================================================= router.post( - "/reservation/check", + '/reservation/check', auth.authenticateToken, - controller.validate("checkReservation"), + controller.validate('checkReservation'), controller.checkReservation ); router.post( - "/reservation/validate", + '/reservation/validate', auth.authenticateToken, - controller.validate("reservationValidate"), + controller.validate('reservationValidate'), controller.reservationValidate ); router.post( - "/reservation", + '/reservation', auth.authenticateToken, - controller.validate("reservation"), + controller.validate('reservation'), controller.reservation ); router.post( - "/reservation/cancel/validate", + '/reservation/cancel/validate', auth.authenticateToken, - controller.validate("cancelReservation"), + controller.validate('cancelReservation'), controller.cancelReservationValidate ); router.post( - "/reservation/cancel", + '/reservation/cancel', auth.authenticateToken, - controller.validate("cancelReservation"), + controller.validate('cancelReservation'), controller.cancelReservation ); router.post( - "/reservation/inquiry-hold", + '/reservation/inquiry-hold', auth.authenticateToken, controller.inquiryReservation ); router.post( - "/reservation/inquiry/v1", + '/reservation/inquiry/v1', auth.authenticateToken, controller.inquiryReservationByReservation ); router.post( - "/list-reservation/inquiry/v1", + '/list-reservation/inquiry/v1', auth.authenticateToken, controller.inquiryListReservationByReservation ); +// ================================================================= ROUTE V2 ================================================================= +router.post( + '/reservation/validate/v2', + auth.authenticateToken, + controller.validate('reservationValidate'), + controller.reservationValidateV2 +); + +router.post( + '/reservation/v2', + auth.authenticateToken, + controller.validate('reservation'), + controller.reservationV2 +); + module.exports = router; diff --git a/knexfile.js b/knexfile.js index b10472b..9c72506 100644 --- a/knexfile.js +++ b/knexfile.js @@ -7,11 +7,11 @@ let user; let password; if (process.env.SERVER_FOR == 'local') { - host = 'localhost'; - database = 'postgres'; - port = 5432; - user = 'postgres'; - password = 'postgres'; + host = process.env.DB_HOST_LOCAL; + database = process.env.DB_NAME_LOCAL; + port = process.env.DB_PORT_LOCAL; + user = process.env.DB_USER_LOCAL; + password = process.env.DB_PASSWORD_LOCAL; } else if (process.env.SERVER_FOR == 'development') { host = '10.20.14.14'; database = 'postgres'; diff --git a/server/index.js b/server/index.js index 82310e1..2257799 100644 --- a/server/index.js +++ b/server/index.js @@ -1,28 +1,29 @@ -const express = require("express"); -const bodyParser = require("body-parser"); -const cors = require("cors"); -const helper = require("../application/helpers/helper"); -const winston = require("../application/helpers/winston.logger"); -const authRoute = require("../application/routes/auth.routes"); -const dongleOrderRoute = require("../application/routes/dongleorder.routes"); -const reservationRoute = require("../application/routes/reservebalance.routes"); -const loadBalanceRoute = require("../application/routes/loadbalance.routes"); -const hsmRoute = require("../application/routes/hsm.routes"); -const historyRoute = require("../application/routes/history.routes"); -const paymentReconRoute = require("../application/routes/paymentrecon.routes"); -const invoiceRoute = require("../application/routes/invoiceonline.routes"); -const cashinRoute = require("../application/routes/cahsin.routes"); -const cron = require("node-cron"); -const moment = require("moment"); -require("dotenv").config(); -moment.locale("id"); +const express = require('express'); +const bodyParser = require('body-parser'); +const cors = require('cors'); +const helper = require('../application/helpers/helper'); +const hmac = require('../application/helpers/HMAC.js'); +const winston = require('../application/helpers/winston.logger'); +const authRoute = require('../application/routes/auth.routes'); +const dongleOrderRoute = require('../application/routes/dongleorder.routes'); +const reservationRoute = require('../application/routes/reservebalance.routes'); +const loadBalanceRoute = require('../application/routes/loadbalance.routes'); +const hsmRoute = require('../application/routes/hsm.routes'); +const historyRoute = require('../application/routes/history.routes'); +const paymentReconRoute = require('../application/routes/paymentrecon.routes'); +const invoiceRoute = require('../application/routes/invoiceonline.routes'); +const cashinRoute = require('../application/routes/cahsin.routes'); +const cron = require('node-cron'); +const moment = require('moment'); +require('dotenv').config(); +moment.locale('id'); const app = express(); var corsOptions = { origin: [ - "http://localhost:" + process.env.PORT || 3000, - "http://localhost:3000", + 'http://localhost:' + process.env.PORT || 3000, + 'http://localhost:3000', ], }; @@ -36,173 +37,182 @@ app.use(bodyParser.json()); app.use(bodyParser.urlencoded({ extended: true })); // ============================== ROUTES API ============================== -app.get("/", (req, res) => { +app.get('/', async (req, res) => { + let hash = await hmac.createHMAC('hallo'); res.json({ - message: "Welcome to Topup Online Service.", - // data: { - // text: "0nlinet0pupkci", - // chiper_text: helper.encryptText("0nlinet0pupkci"), - // }, + message: 'Welcome to Topup Online Service.', + data: { + text: '0nlinet0pupkci', + chiper_text: helper.encryptText('0nlinet0pupkci'), + hmac: hash, + date: moment().format('YYYYMMDDHHmm'), + }, }); }); -app.use("/api/", authRoute); -app.use("/api/", dongleOrderRoute); -app.use("/api/", historyRoute); -app.use("/api/", hsmRoute); -app.use("/api/", loadBalanceRoute); -app.use("/api/", paymentReconRoute); -app.use("/api/", reservationRoute); -app.use("/api/", invoiceRoute); -app.use("/api/", cashinRoute); +app.use('/api/', authRoute); +app.use('/api/', dongleOrderRoute); +app.use('/api/', historyRoute); +app.use('/api/', hsmRoute); +app.use('/api/', loadBalanceRoute); +app.use('/api/', paymentReconRoute); +app.use('/api/', reservationRoute); +app.use('/api/', invoiceRoute); +app.use('/api/', cashinRoute); // ============================== SAP SCHEDULLER ============================= // if (process.env.NODE_ENV.toUpperCase() == "PRODUCTION") { - // =================================================== - // SCHEDULER FOR GENERATE INVOICE - // =================================================== +// =================================================== +// SCHEDULER FOR GENERATE INVOICE +// =================================================== - const { - _generateInvoice, - _postingInvoice, - } = require("../application/modules/invoiceonline/invoice.controller"); - - // GENERATE + POSTING INVOICE - cron.schedule("0 1 * * *", async () => { - try { - // let ivoiceDate = moment().add(1, 'days').format("YYYY-MM-DD"); - let ivoiceDate = moment().format("YYYY-MM-DD"); - let uniqueCode = helper.getUniqueCode(); - winston.logger.debug( - `STARTING SCHEDULER-FB70 GENERATE INVOICE ${ivoiceDate} ` - ); - const generate = await _generateInvoice(ivoiceDate, uniqueCode, false); - winston.logger.debug( - `END SCHEDULER-FB70 GENERATE INVOICE ${ivoiceDate} : ${JSON.stringify( - generate - )}` - ); - const reGenerate = await _generateInvoice(ivoiceDate, uniqueCode, true); - winston.logger.debug( - `END SCHEDULER-FB70 RE-GENERATE INVOICE THAT HAVE BEEN DELETED ${ivoiceDate} : ${JSON.stringify( - generate - )}` - ); - } catch (error) { - // create log - winston.logger.error( - `500 internal server error - backend server | ${error.message}` - ); - } - }); +const { + _generateInvoice, + _postingInvoice, +} = require('../application/modules/invoiceonline/invoice.controller'); - // RE-TRY POSTING - cron.schedule("0 7 * * *", async () => { - try { - let uniqueCode = helper.getUniqueCode(); - winston.logger.debug(`STARTING SCHEDULER-FB70 RE-TRY POSTING INVOICE`); - const posting = await _postingInvoice(uniqueCode); - winston.logger.debug( - `END SCHEDULER-FB70 RE-TRY POSTING INVOICE : ${JSON.stringify(posting)}` - ); - } catch (error) { - // create log - winston.logger.error( - `500 internal server error - backend server | ${error.message}` - ); - } - }); +// GENERATE + POSTING INVOICE +cron.schedule('0 1 * * *', async () => { + try { + // let ivoiceDate = moment().add(1, 'days').format("YYYY-MM-DD"); + let ivoiceDate = moment().format('YYYY-MM-DD'); + let uniqueCode = helper.getUniqueCode(); + winston.logger.debug( + `STARTING SCHEDULER-FB70 GENERATE INVOICE ${ivoiceDate} ` + ); + const generate = await _generateInvoice(ivoiceDate, uniqueCode, false); + winston.logger.debug( + `END SCHEDULER-FB70 GENERATE INVOICE ${ivoiceDate} : ${JSON.stringify( + generate + )}` + ); + const reGenerate = await _generateInvoice(ivoiceDate, uniqueCode, true); + winston.logger.debug( + `END SCHEDULER-FB70 RE-GENERATE INVOICE THAT HAVE BEEN DELETED ${ivoiceDate} : ${JSON.stringify( + generate + )}` + ); + } catch (error) { + // create log + winston.logger.error( + `500 internal server error - backend server | ${error.message}` + ); + } +}); - cron.schedule("0 12 * * *", async () => { - try { - let uniqueCode = helper.getUniqueCode(); - winston.logger.debug(`STARTING SCHEDULER-FB70 RE-TRY POSTING INVOICE`); - const posting = await _postingInvoice(uniqueCode); - winston.logger.debug( - `END SCHEDULER-FB70 RE-TRY POSTING INVOICE : ${JSON.stringify(posting)}` - ); - } catch (error) { - // create log - winston.logger.error( - `500 internal server error - backend server | ${error.message}` - ); - } - }); +// RE-TRY POSTING +cron.schedule('0 7 * * *', async () => { + try { + let uniqueCode = helper.getUniqueCode(); + winston.logger.debug(`STARTING SCHEDULER-FB70 RE-TRY POSTING INVOICE`); + const posting = await _postingInvoice(uniqueCode); + winston.logger.debug( + `END SCHEDULER-FB70 RE-TRY POSTING INVOICE : ${JSON.stringify(posting)}` + ); + } catch (error) { + // create log + winston.logger.error( + `500 internal server error - backend server | ${error.message}` + ); + } +}); - cron.schedule("0 17 * * *", async () => { - try { - let uniqueCode = helper.getUniqueCode(); - winston.logger.debug(`STARTING SCHEDULER-FB70 RE-TRY POSTING INVOICE`); - const posting = await _postingInvoice(uniqueCode); - winston.logger.debug( - `END SCHEDULER-FB70 RE-TRY POSTING INVOICE : ${JSON.stringify(posting)}` - ); - } catch (error) { - // create log - winston.logger.error( - `500 internal server error - backend server | ${error.message}` - ); - } - }); +cron.schedule('0 12 * * *', async () => { + try { + let uniqueCode = helper.getUniqueCode(); + winston.logger.debug(`STARTING SCHEDULER-FB70 RE-TRY POSTING INVOICE`); + const posting = await _postingInvoice(uniqueCode); + winston.logger.debug( + `END SCHEDULER-FB70 RE-TRY POSTING INVOICE : ${JSON.stringify(posting)}` + ); + } catch (error) { + // create log + winston.logger.error( + `500 internal server error - backend server | ${error.message}` + ); + } +}); - - // =================================================== - // SCHEDULER FOR GENERATE INVOICE - // =================================================== - // cash in - const { - _generateCashIn, - } = require("../application/modules/cashin/cahsin.controller"); +cron.schedule('0 17 * * *', async () => { + try { + let uniqueCode = helper.getUniqueCode(); + winston.logger.debug(`STARTING SCHEDULER-FB70 RE-TRY POSTING INVOICE`); + const posting = await _postingInvoice(uniqueCode); + winston.logger.debug( + `END SCHEDULER-FB70 RE-TRY POSTING INVOICE : ${JSON.stringify(posting)}` + ); + } catch (error) { + // create log + winston.logger.error( + `500 internal server error - backend server | ${error.message}` + ); + } +}); - cron.schedule('30 7 * * *', async () => { - try { - let uniqueCode = helper.getUniqueCode(); - winston.logger.info(`STARTING SCHEDULER-FB70 GENERATE CASH IN ${uniqueCode}`); - const posting = await _generateCashIn(uniqueCode); - winston.logger.info( - `END SCHEDULER-FB70 GENERATE CASH IN : ${JSON.stringify(posting)}` - ); - } catch (error) { +// =================================================== +// SCHEDULER FOR GENERATE INVOICE +// =================================================== +// cash in +const { + _generateCashIn, +} = require('../application/modules/cashin/cahsin.controller'); +const { createHMAC } = require('../application/helpers/HMAC.js'); + +cron.schedule('30 7 * * *', async () => { + try { + let uniqueCode = helper.getUniqueCode(); + winston.logger.info( + `STARTING SCHEDULER-FB70 GENERATE CASH IN ${uniqueCode}` + ); + const posting = await _generateCashIn(uniqueCode); + winston.logger.info( + `END SCHEDULER-FB70 GENERATE CASH IN : ${JSON.stringify(posting)}` + ); + } catch (error) { // create log winston.logger.error( `500 SCHEDULER-FB70 internal server error - backend server | ${error.message}` - ); - } - }); + ); + } +}); - cron.schedule('30 12 * * *', async () => { - try { - let uniqueCode = helper.getUniqueCode(); - winston.logger.info(`STARTING SCHEDULER-FB70 GENERATE CASH IN ${uniqueCode}`); - const posting = await _generateCashIn(uniqueCode); - winston.logger.info( - `END SCHEDULER-FB70 GENERATE CASH IN : ${JSON.stringify(posting)}` - ); - } catch (error) { +cron.schedule('30 12 * * *', async () => { + try { + let uniqueCode = helper.getUniqueCode(); + winston.logger.info( + `STARTING SCHEDULER-FB70 GENERATE CASH IN ${uniqueCode}` + ); + const posting = await _generateCashIn(uniqueCode); + winston.logger.info( + `END SCHEDULER-FB70 GENERATE CASH IN : ${JSON.stringify(posting)}` + ); + } catch (error) { // create log winston.logger.error( `500 SCHEDULER-FB70 internal server error - backend server | ${error.message}` - ); - } - }); - - cron.schedule('30 17 * * *', async () => { - try { - let uniqueCode = helper.getUniqueCode(); - winston.logger.info(`STARTING SCHEDULER-FB70 GENERATE CASH IN ${uniqueCode}`); - const posting = await _generateCashIn(uniqueCode); - winston.logger.info( - `END SCHEDULER-FB70 GENERATE CASH IN : ${JSON.stringify(posting)}` - ); - } catch (error) { + ); + } +}); + +cron.schedule('30 17 * * *', async () => { + try { + let uniqueCode = helper.getUniqueCode(); + winston.logger.info( + `STARTING SCHEDULER-FB70 GENERATE CASH IN ${uniqueCode}` + ); + const posting = await _generateCashIn(uniqueCode); + winston.logger.info( + `END SCHEDULER-FB70 GENERATE CASH IN : ${JSON.stringify(posting)}` + ); + } catch (error) { // create log winston.logger.error( `500 SCHEDULER-FB70 internal server error - backend server | ${error.message}` - ); - } - }); + ); + } +}); // }