mirror of
https://github.com/mohamadihsan/topuponline.git
synced 2026-12-06 12:06:28 +00:00
Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 9478cd4a31 | |||
| 8eaf79bfd1 | |||
| 817832d925 | |||
| 79d4269b70 | |||
| 603a74a5b7 | |||
| c9a08d6832 | |||
| 308fef3ecd | |||
| 31d007dd67 | |||
| 6fe3ecc89f | |||
| b6b043b0a2 |
@@ -172,6 +172,7 @@ const _generateCashIn = async (uniqueCode) => {
|
|||||||
let reserve = [];
|
let reserve = [];
|
||||||
let code = '';
|
let code = '';
|
||||||
await knex.transaction(async (trx) => {
|
await knex.transaction(async (trx) => {
|
||||||
|
try {
|
||||||
code = await model.generateCode(
|
code = await model.generateCode(
|
||||||
trx,
|
trx,
|
||||||
item.c_partner_code,
|
item.c_partner_code,
|
||||||
@@ -214,6 +215,7 @@ const _generateCashIn = async (uniqueCode) => {
|
|||||||
}
|
}
|
||||||
dataCahsIn.i_amount = cashInAmount;
|
dataCahsIn.i_amount = cashInAmount;
|
||||||
|
|
||||||
|
if(cashInAmount > 0) {
|
||||||
//INSERT CASH-IN
|
//INSERT CASH-IN
|
||||||
const cashIn = await model.insertCashIn(trx, dataCahsIn);
|
const cashIn = await model.insertCashIn(trx, dataCahsIn);
|
||||||
winston.logger.info(
|
winston.logger.info(
|
||||||
@@ -228,6 +230,7 @@ const _generateCashIn = async (uniqueCode) => {
|
|||||||
trx
|
trx
|
||||||
);
|
);
|
||||||
|
|
||||||
|
let m_amount = 0;
|
||||||
for (const detail of reserv) {
|
for (const detail of reserv) {
|
||||||
// data.push({
|
// data.push({
|
||||||
// i_cash_in: cashIn.i_cash_in,
|
// i_cash_in: cashIn.i_cash_in,
|
||||||
@@ -254,22 +257,46 @@ const _generateCashIn = async (uniqueCode) => {
|
|||||||
d_credit: cashIn.d_credit,
|
d_credit: cashIn.d_credit,
|
||||||
c_in_period: cashIn.c_in_period,
|
c_in_period: cashIn.c_in_period,
|
||||||
};
|
};
|
||||||
|
m_amount += parseInt(detail.i_reservation_amount);
|
||||||
|
|
||||||
|
if(m_amount <= detail.invoice_amount) {
|
||||||
await model.updateIntoReserve(trx, dataReserve, reserveNo);
|
await model.updateIntoReserve(trx, dataReserve, reserveNo);
|
||||||
|
winston.logger.info(
|
||||||
|
`SCHEDULER-FB70-${uniqueCode} CASH-IN UPDATE RESERVE BALANCE ${reserveNo} DATA : ${JSON.stringify(
|
||||||
|
dataReserve
|
||||||
|
)}`
|
||||||
|
);
|
||||||
await model.insertCashInDetail(trx, temp);
|
await model.insertCashInDetail(trx, temp);
|
||||||
|
winston.logger.info(
|
||||||
|
`SCHEDULER-FB70-${uniqueCode} INSERT CASH-IN DETAIL, ID CASH-IN ${cashIn.i_cash_in} : ${JSON.stringify(
|
||||||
|
temp
|
||||||
|
)}`
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
await trx.rollback();
|
||||||
|
winston.logger.info(
|
||||||
|
`${uniqueCode} ROLLBACK CASH-IN: AMOUNT CASH-IN > TOTAL INVOICE. AMOUNT ${m_amount} > INVOICE AMOUNT (${detail.invoice_amount}) : ${JSON.stringify(
|
||||||
|
dataCahsIn
|
||||||
|
)}`
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
await wait(5000);
|
await wait(10000);
|
||||||
winston.logger.info(
|
winston.logger.info(
|
||||||
`SCHEDULER-FB70-${uniqueCode} INSERT CASH-IN TO RESERVE ${code} DATA : ${JSON.stringify(
|
`SCHEDULER-FB70-${uniqueCode} INSERT CASH-IN TO RESERVE ${code} DATA : ${JSON.stringify(
|
||||||
dataCahsIn
|
dataCahsIn
|
||||||
)}`
|
)}`
|
||||||
);
|
);
|
||||||
// await model.insertCashInDetail(trx, data);
|
}
|
||||||
// await model.insertPostingEt(code, item, trx)
|
await trx.commit();
|
||||||
});
|
|
||||||
|
} catch (error) {
|
||||||
|
sts = "error";
|
||||||
|
await trx.rollback();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
return partnerRecon;
|
return partnerRecon;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -275,6 +275,7 @@ const getReserve = async (trx, code, date, invoice) => {
|
|||||||
'tdrb.c_partner_name',
|
'tdrb.c_partner_name',
|
||||||
'tdrb.c_load_balance_no',
|
'tdrb.c_load_balance_no',
|
||||||
'tdi.c_invoice_no',
|
'tdi.c_invoice_no',
|
||||||
|
'tdi.m_amount as invoice_amount'
|
||||||
])
|
])
|
||||||
.from('trx.t_d_reservation_balance AS tdrb')
|
.from('trx.t_d_reservation_balance AS tdrb')
|
||||||
.leftJoin('trx.t_d_load_balance as tdlb', function () {
|
.leftJoin('trx.t_d_load_balance as tdlb', function () {
|
||||||
|
|||||||
@@ -456,6 +456,18 @@ const loadingBalanceRequest = async (req, res) => {
|
|||||||
return res.status(200).json(result);
|
return res.status(200).json(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let cardBlacklist = await model.getCardBlacklist(card_number);
|
||||||
|
if (cardBlacklist) {
|
||||||
|
if(cardBlacklist.c_status == 'B') {
|
||||||
|
result = {
|
||||||
|
code: '445',
|
||||||
|
message: 'Card is Blacklisted',
|
||||||
|
data: {},
|
||||||
|
};
|
||||||
|
return res.status(200).json(result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// log debug
|
// log debug
|
||||||
// winston.logger.debug(
|
// winston.logger.debug(
|
||||||
// `${uniqueCode} [ PROCESSING LOADING-BALANCE-REQUEST ]: checking production card number or not...`
|
// `${uniqueCode} [ PROCESSING LOADING-BALANCE-REQUEST ]: checking production card number or not...`
|
||||||
|
|||||||
@@ -56,6 +56,15 @@ const getIssuer = (id) => {
|
|||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// GET IS CARD ADDED TO BLACKLIST
|
||||||
|
const getCardBlacklist = (card_number) => {
|
||||||
|
let result = knex('public.t_m_card_blacklist')
|
||||||
|
.select('c_status')
|
||||||
|
.where('c_card_number', card_number)
|
||||||
|
.first();
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
// GET CHECKING CARD PRODUCT FROM GLOBAL PARAMETER
|
// GET CHECKING CARD PRODUCT FROM GLOBAL PARAMETER
|
||||||
const getCheckByCardProductStatusValue = () => {
|
const getCheckByCardProductStatusValue = () => {
|
||||||
let result = knex('t_m_global_parameter')
|
let result = knex('t_m_global_parameter')
|
||||||
@@ -1077,6 +1086,7 @@ module.exports = {
|
|||||||
checkCardNumber,
|
checkCardNumber,
|
||||||
getPartner,
|
getPartner,
|
||||||
getIssuer,
|
getIssuer,
|
||||||
|
getCardBlacklist,
|
||||||
getCheckByCardProductStatusValue,
|
getCheckByCardProductStatusValue,
|
||||||
getReservationPending,
|
getReservationPending,
|
||||||
getReservationPendingWithFlagCounter,
|
getReservationPendingWithFlagCounter,
|
||||||
|
|||||||
@@ -136,6 +136,58 @@ const paymentRecon = async (req, res) => {
|
|||||||
return res.status(200).json(result);
|
return res.status(200).json(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log(getPartner);
|
||||||
|
|
||||||
|
// check payment recon status is enable
|
||||||
|
if (getPartner.b_payment_recon != true) {
|
||||||
|
result = {
|
||||||
|
code: '444',
|
||||||
|
message: 'Partner unable to receive payment reconciliations',
|
||||||
|
data: {},
|
||||||
|
};
|
||||||
|
|
||||||
|
// log warn
|
||||||
|
winston.logger.warn(
|
||||||
|
`${uniqueCode} [ RESPONSE PAYMENT-RECON ]: ${JSON.stringify(result)}`
|
||||||
|
);
|
||||||
|
|
||||||
|
return res.status(200).json(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
// check partner reservation number yang di request sama dengan partner yang di token
|
||||||
|
let checkReservation = await model.checkReservation(reservation_number);
|
||||||
|
|
||||||
|
if (!checkReservation) {
|
||||||
|
result = {
|
||||||
|
code: '400',
|
||||||
|
message: 'Reservation number does not exist.',
|
||||||
|
data: {},
|
||||||
|
};
|
||||||
|
|
||||||
|
// log warn
|
||||||
|
winston.logger.warn(
|
||||||
|
`${uniqueCode} [ RESPONSE PAYMENT-RECON ]: ${JSON.stringify(result)}`
|
||||||
|
);
|
||||||
|
|
||||||
|
return res.status(200).json(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (checkReservation.i_partner != partner_id) {
|
||||||
|
result = {
|
||||||
|
code: '443',
|
||||||
|
message:
|
||||||
|
'Partner for payment reconciliation and transaction does not match',
|
||||||
|
data: {},
|
||||||
|
};
|
||||||
|
|
||||||
|
// log warn
|
||||||
|
winston.logger.warn(
|
||||||
|
`${uniqueCode} [ RESPONSE PAYMENT-RECON ]: ${JSON.stringify(result)}`
|
||||||
|
);
|
||||||
|
|
||||||
|
return res.status(200).json(result);
|
||||||
|
}
|
||||||
|
|
||||||
// check reservation number yang di request sudah berhasil di recon atau belum sebelumnnya
|
// check reservation number yang di request sudah berhasil di recon atau belum sebelumnnya
|
||||||
let checkReservationNumberAndAmountAlreadyRecon =
|
let checkReservationNumberAndAmountAlreadyRecon =
|
||||||
await model.checkReservationNumberAndAmountAlreadyRecon(
|
await model.checkReservationNumberAndAmountAlreadyRecon(
|
||||||
|
|||||||
@@ -1,33 +1,34 @@
|
|||||||
const knex = require("../../../infrastructure/database/knex");
|
const knex = require('../../../infrastructure/database/knex');
|
||||||
|
|
||||||
// GET PARTNER, MERCHANT, TERMINAL FROM TID
|
// GET PARTNER, MERCHANT, TERMINAL FROM TID
|
||||||
const getPartner = (mid, tid) => {
|
const getPartner = (mid, tid) => {
|
||||||
let result = knex
|
let result = knex
|
||||||
.select(
|
.select(
|
||||||
"t_m_partner.i_partner",
|
't_m_partner.i_partner',
|
||||||
"t_m_partner.c_code as partner_code",
|
't_m_partner.c_code as partner_code',
|
||||||
"t_m_partner.c_name as partner_name",
|
't_m_partner.c_name as partner_name',
|
||||||
"t_m_merchant.i_merchant",
|
't_m_partner.b_payment_recon',
|
||||||
"t_m_merchant.c_code as merchant_code",
|
't_m_merchant.i_merchant',
|
||||||
"t_m_merchant.c_name as merchant_name",
|
't_m_merchant.c_code as merchant_code',
|
||||||
"t_m_merchant.e_mid as mid",
|
't_m_merchant.c_name as merchant_name',
|
||||||
"t_m_terminal.i_terminal",
|
't_m_merchant.e_mid as mid',
|
||||||
"t_m_terminal.c_code as terminal_code",
|
't_m_terminal.i_terminal',
|
||||||
"t_m_terminal.c_name as terminal_name",
|
't_m_terminal.c_code as terminal_code',
|
||||||
"t_m_terminal.e_tid as tid"
|
't_m_terminal.c_name as terminal_name',
|
||||||
|
't_m_terminal.e_tid as tid'
|
||||||
)
|
)
|
||||||
.from("t_m_terminal")
|
.from('t_m_terminal')
|
||||||
.leftJoin(
|
.leftJoin(
|
||||||
"t_m_merchant",
|
't_m_merchant',
|
||||||
"t_m_terminal.i_merchant",
|
't_m_terminal.i_merchant',
|
||||||
"t_m_merchant.i_merchant"
|
't_m_merchant.i_merchant'
|
||||||
)
|
)
|
||||||
.leftJoin("t_m_partner", "t_m_merchant.i_partner", "t_m_partner.i_partner")
|
.leftJoin('t_m_partner', 't_m_merchant.i_partner', 't_m_partner.i_partner')
|
||||||
.where("t_m_merchant.e_mid", mid)
|
.where('t_m_merchant.e_mid', mid)
|
||||||
.where("t_m_terminal.e_tid", tid)
|
.where('t_m_terminal.e_tid', tid)
|
||||||
.where("t_m_terminal.c_status", "A")
|
.where('t_m_terminal.c_status', 'A')
|
||||||
.where("t_m_merchant.c_status", "A")
|
.where('t_m_merchant.c_status', 'A')
|
||||||
.where("t_m_partner.c_status", "A")
|
.where('t_m_partner.c_status', 'A')
|
||||||
.first();
|
.first();
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
@@ -35,57 +36,66 @@ const getPartner = (mid, tid) => {
|
|||||||
const getPartnerByID = (partner_id) => {
|
const getPartnerByID = (partner_id) => {
|
||||||
let result = knex
|
let result = knex
|
||||||
.select(
|
.select(
|
||||||
"t_m_partner.i_partner",
|
't_m_partner.i_partner',
|
||||||
"t_m_partner.c_code as partner_code",
|
't_m_partner.c_code as partner_code',
|
||||||
"t_m_partner.c_name as partner_name"
|
't_m_partner.c_name as partner_name',
|
||||||
|
't_m_partner.b_payment_recon'
|
||||||
)
|
)
|
||||||
.from("t_m_partner")
|
.from('t_m_partner')
|
||||||
.where("t_m_partner.i_partner", partner_id)
|
.where('t_m_partner.i_partner', partner_id)
|
||||||
.where("t_m_partner.c_status", "A")
|
.where('t_m_partner.c_status', 'A')
|
||||||
.first();
|
.first();
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
const checkReservationNumberAndAmount = (reservationNumber) => {
|
const checkReservationNumberAndAmount = (reservationNumber) => {
|
||||||
let result = knex("trx.t_d_reservation_balance")
|
let result = knex('trx.t_d_reservation_balance')
|
||||||
.count("* as total_transaction")
|
.count('* as total_transaction')
|
||||||
.sum("i_reservation_amount as total_amount")
|
.sum('i_reservation_amount as total_amount')
|
||||||
.groupBy("c_ref_no")
|
.groupBy('c_ref_no')
|
||||||
.where("c_reservation_no", reservationNumber)
|
.where('c_reservation_no', reservationNumber)
|
||||||
// .where("c_status", "A")
|
// .where("c_status", "A")
|
||||||
.whereNull("c_payment_recon_no")
|
.whereNull('c_payment_recon_no')
|
||||||
.first();
|
.first();
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
const checkReservationCanceledStatus = (reservationNumber) => {
|
const checkReservationCanceledStatus = (reservationNumber) => {
|
||||||
let result = knex("trx.t_d_reservation_balance")
|
let result = knex('trx.t_d_reservation_balance')
|
||||||
.where("c_reservation_no", reservationNumber)
|
.where('c_reservation_no', reservationNumber)
|
||||||
.where("c_status", "X")
|
.where('c_status', 'X')
|
||||||
|
.first();
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
|
const checkReservation = (reservationNumber) => {
|
||||||
|
let result = knex('trx.t_d_reservation_balance')
|
||||||
|
.where('c_reservation_no', reservationNumber)
|
||||||
|
.where('c_status', '!=', 'X')
|
||||||
.first();
|
.first();
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
const checkReservationNumberAndAmountAlreadyRecon = (reservationNumber) => {
|
const checkReservationNumberAndAmountAlreadyRecon = (reservationNumber) => {
|
||||||
let result = knex("trx.t_d_reservation_balance")
|
let result = knex('trx.t_d_reservation_balance')
|
||||||
.select("c_payment_recon_no", "d_payment_recon")
|
.select('c_payment_recon_no', 'd_payment_recon')
|
||||||
.where("c_reservation_no", reservationNumber)
|
.where('c_reservation_no', reservationNumber)
|
||||||
// .where("c_status", "A")
|
// .where("c_status", "A")
|
||||||
.whereNotNull("c_payment_recon_no")
|
.whereNotNull('c_payment_recon_no')
|
||||||
.first();
|
.first();
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
// UPDATE PAYMENT RECON
|
// UPDATE PAYMENT RECON
|
||||||
const updatePaymentReconNo = (data) => {
|
const updatePaymentReconNo = (data) => {
|
||||||
let result = knex("trx.t_d_reservation_balance")
|
let result = knex('trx.t_d_reservation_balance')
|
||||||
.update({
|
.update({
|
||||||
c_payment_recon_no: data.payment_recon_no,
|
c_payment_recon_no: data.payment_recon_no,
|
||||||
d_payment: data.date,
|
d_payment: data.date,
|
||||||
d_payment_recon: data.time,
|
d_payment_recon: data.time,
|
||||||
})
|
})
|
||||||
.whereNull("c_payment_recon_no")
|
.whereNull('c_payment_recon_no')
|
||||||
.where("c_reservation_no", data.reservation_number);
|
.where('c_reservation_no', data.reservation_number);
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -104,7 +114,7 @@ const insertPaymentReconTransaction = (
|
|||||||
responseMessage,
|
responseMessage,
|
||||||
responseData
|
responseData
|
||||||
) => {
|
) => {
|
||||||
let result = knex("payment.t_d_payment_recon").insert({
|
let result = knex('payment.t_d_payment_recon').insert({
|
||||||
d_payment: date,
|
d_payment: date,
|
||||||
d_payment_recon: now,
|
d_payment_recon: now,
|
||||||
c_partner_code: partnerCode,
|
c_partner_code: partnerCode,
|
||||||
@@ -123,34 +133,34 @@ const insertPaymentReconTransaction = (
|
|||||||
|
|
||||||
// INSERT TEMP PAYMENT RECON NUMBER
|
// INSERT TEMP PAYMENT RECON NUMBER
|
||||||
const insertPaymentReconNumber = (paymentReconNumber) => {
|
const insertPaymentReconNumber = (paymentReconNumber) => {
|
||||||
let result = knex("payment.t_d_payment_recon_no_validate")
|
let result = knex('payment.t_d_payment_recon_no_validate')
|
||||||
.insert({
|
.insert({
|
||||||
c_payment_recon_no: paymentReconNumber,
|
c_payment_recon_no: paymentReconNumber,
|
||||||
})
|
})
|
||||||
.onConflict("c_payment_recon_no")
|
.onConflict('c_payment_recon_no')
|
||||||
.ignore();
|
.ignore();
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
// GET LAST COUNTER PAYMENT RECON NO
|
// GET LAST COUNTER PAYMENT RECON NO
|
||||||
const getLastCounterPaymentReconNo = (partnerCode, reconDate) => {
|
const getLastCounterPaymentReconNo = (partnerCode, reconDate) => {
|
||||||
let result = knex("payment.t_d_payment_recon")
|
let result = knex('payment.t_d_payment_recon')
|
||||||
.select("c_payment_recon_no", "d_payment_recon")
|
.select('c_payment_recon_no', 'd_payment_recon')
|
||||||
.whereRaw("??::date = ?", ["d_payment_recon", reconDate])
|
.whereRaw('??::date = ?', ['d_payment_recon', reconDate])
|
||||||
.where("c_partner_code", partnerCode)
|
.where('c_partner_code', partnerCode)
|
||||||
// .orderBy("d_payment_recon", "desc")
|
// .orderBy("d_payment_recon", "desc")
|
||||||
.orderBy("c_payment_recon_no", "desc")
|
.orderBy('c_payment_recon_no', 'desc')
|
||||||
.first();
|
.first();
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
const getReservationToRecon = (date) => {
|
const getReservationToRecon = (date) => {
|
||||||
let result = knex("trx.t_d_reservation_balance")
|
let result = knex('trx.t_d_reservation_balance')
|
||||||
.select("c_reservation_no", "i_reservation_amount")
|
.select('c_reservation_no', 'i_reservation_amount')
|
||||||
.whereNull("d_cancel")
|
.whereNull('d_cancel')
|
||||||
.whereNull("c_payment_recon_no")
|
.whereNull('c_payment_recon_no')
|
||||||
.whereRaw("??::date = ?", ["d_reservation", date])
|
.whereRaw('??::date = ?', ['d_reservation', date])
|
||||||
.orderBy("c_reservation_no", "asc");
|
.orderBy('c_reservation_no', 'asc');
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -159,6 +169,7 @@ module.exports = {
|
|||||||
getPartnerByID,
|
getPartnerByID,
|
||||||
checkReservationNumberAndAmount,
|
checkReservationNumberAndAmount,
|
||||||
checkReservationCanceledStatus,
|
checkReservationCanceledStatus,
|
||||||
|
checkReservation,
|
||||||
checkReservationNumberAndAmountAlreadyRecon,
|
checkReservationNumberAndAmountAlreadyRecon,
|
||||||
updatePaymentReconNo,
|
updatePaymentReconNo,
|
||||||
insertPaymentReconTransaction,
|
insertPaymentReconTransaction,
|
||||||
|
|||||||
@@ -0,0 +1,182 @@
|
|||||||
|
const { param, body, validationResult } = require('express-validator');
|
||||||
|
const helper = require('../../helpers/helper');
|
||||||
|
const winston = require('../../helpers/winston.logger');
|
||||||
|
const model = require('./refundkmt.model');
|
||||||
|
const moment = require('moment');
|
||||||
|
moment.locale('id');
|
||||||
|
|
||||||
|
// VALIDATION
|
||||||
|
const validate = (method) => {
|
||||||
|
switch (method) {
|
||||||
|
case 'callbackOy':
|
||||||
|
return [
|
||||||
|
body('partner_trx_id').not().isEmpty().withMessage('Partner Trx Id is required'),
|
||||||
|
body('trx_id').not().isEmpty().withMessage('Trx Id is required'),
|
||||||
|
body('amount').not().isEmpty().withMessage('Amount is required'),
|
||||||
|
body('recipient_bank').not().isEmpty().withMessage('Recipient Bank is required'),
|
||||||
|
body('recipient_account').not().isEmpty().withMessage('Recipient Account is required'),
|
||||||
|
];
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const callbackOy = 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 { status, amount, recipient_name, recipient_bank, recipient_account, trx_id, partner_trx_id, timestamp, created_date, last_updated_date } = req.body;
|
||||||
|
|
||||||
|
// log info
|
||||||
|
winston.logger.info(
|
||||||
|
`${uniqueCode} [ REQUEST REFUND-KMT ]: ${JSON.stringify(req.body)}`
|
||||||
|
);
|
||||||
|
|
||||||
|
// check validator
|
||||||
|
let err = validationResult(req, res);
|
||||||
|
if (!err.isEmpty()) {
|
||||||
|
result = {
|
||||||
|
code: '400',
|
||||||
|
message: err.errors[0].msg,
|
||||||
|
data: {},
|
||||||
|
};
|
||||||
|
|
||||||
|
// log warn
|
||||||
|
winston.logger.warn(
|
||||||
|
`${uniqueCode} [ RESPONSE REFUND-KMT ]: ${JSON.stringify(result)}`
|
||||||
|
);
|
||||||
|
|
||||||
|
return res.status(200).json(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
// time
|
||||||
|
let now = moment().format('YYYY-MM-DD HH:mm:ss');
|
||||||
|
winston.logger.warn(
|
||||||
|
`${uniqueCode} [ RESPONSE REFUND-KMT ]: ${JSON.stringify(result)}`
|
||||||
|
);
|
||||||
|
|
||||||
|
let recipient_bank_code = recipient_bank.toLowerCase();
|
||||||
|
// check trx_id yang di request match
|
||||||
|
let checkRequest = await model.checkRedeem(partner_trx_id, trx_id, amount, recipient_bank_code, recipient_account);
|
||||||
|
|
||||||
|
if (!checkRequest) {
|
||||||
|
result = {
|
||||||
|
code: '400',
|
||||||
|
message: 'Refund Request Transaction is not found.',
|
||||||
|
data: {},
|
||||||
|
};
|
||||||
|
winston.logger.warn(
|
||||||
|
`${uniqueCode} [ RESPONSE REFUND-KMT ]: ${JSON.stringify(result)}`
|
||||||
|
);
|
||||||
|
return res.status(200).json(result);
|
||||||
|
} else if (checkRequest.c_status?.trim() == 'A') {
|
||||||
|
result = {
|
||||||
|
code: '400',
|
||||||
|
message: 'Refund transaction is already completed.',
|
||||||
|
data: {},
|
||||||
|
};
|
||||||
|
winston.logger.warn(
|
||||||
|
`${uniqueCode} [ RESPONSE REFUND-KMT ]: ${JSON.stringify(result)}`
|
||||||
|
);
|
||||||
|
return res.status(200).json(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
winston.logger.warn(
|
||||||
|
`${uniqueCode} [ checkRequest ]: ${JSON.stringify(checkRequest)}`
|
||||||
|
);
|
||||||
|
|
||||||
|
if(status.code != '000') {
|
||||||
|
result = {
|
||||||
|
code: '400',
|
||||||
|
message: status.message,
|
||||||
|
data: {
|
||||||
|
trx_id: trx_id,
|
||||||
|
partner_trx_id: partner_trx_id,
|
||||||
|
amount: amount,
|
||||||
|
recipient_bank: recipient_bank_code,
|
||||||
|
recipient_account: recipient_account,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const unixTimeZero = Date.parse(last_updated_date);
|
||||||
|
const date_reimbursement = moment(unixTimeZero).format("YYYY-MM-DD HH:mm:ss")
|
||||||
|
|
||||||
|
//Update Card Replacement
|
||||||
|
await model.updateReplacementComplete(checkRequest.i_card_replacement, checkRequest.c_request_no, date_reimbursement);
|
||||||
|
|
||||||
|
//Notif Email
|
||||||
|
let urlCMS = '';
|
||||||
|
if (process.env.SERVER_FOR == 'production') {
|
||||||
|
urlCMS = 'https://cms.kci.id';
|
||||||
|
} else if(process.env.SERVER_FOR == 'development') {
|
||||||
|
urlCMS = 'http://10.20.14.18';
|
||||||
|
} else {
|
||||||
|
urlCMS = 'http://localhost:8000';
|
||||||
|
}
|
||||||
|
|
||||||
|
let axios = require('axios');
|
||||||
|
|
||||||
|
const url = urlCMS + '/api/redeem/notifemail'
|
||||||
|
console.log('urlCMS', url)
|
||||||
|
|
||||||
|
// let resp = await axios.post(url, body, config);
|
||||||
|
const responseMail = await axios({
|
||||||
|
method: 'post',
|
||||||
|
url: url,
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
},
|
||||||
|
data: {
|
||||||
|
i_card_replacement: checkRequest.i_card_replacement?.trim(),
|
||||||
|
c_request_no: checkRequest.c_request_no?.trim(),
|
||||||
|
c_card_no: checkRequest.c_card_no?.trim(),
|
||||||
|
status: 'complete'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
console.log('urlCMS', url)
|
||||||
|
|
||||||
|
result = {
|
||||||
|
code: '00',
|
||||||
|
message: 'success',
|
||||||
|
data: {
|
||||||
|
trx_id: trx_id,
|
||||||
|
partner_trx_id: partner_trx_id,
|
||||||
|
amount: amount,
|
||||||
|
recipient_bank: recipient_bank,
|
||||||
|
recipient_account: recipient_account,
|
||||||
|
last_updated_date: last_updated_date
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
// log info
|
||||||
|
winston.logger.info(
|
||||||
|
`${uniqueCode} [ RESPONSE REFUND-KMT ]: ${JSON.stringify(result)}`
|
||||||
|
);
|
||||||
|
|
||||||
|
return res.status(200).json(result);
|
||||||
|
} catch (error) {
|
||||||
|
// create log
|
||||||
|
winston.logger.error(
|
||||||
|
`[ RESPONSE REFUND-KMT ]: 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,
|
||||||
|
callbackOy
|
||||||
|
};
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
const knex = require("../../../infrastructure/database/knex");
|
||||||
|
|
||||||
|
const checkRedeem = (partner_trx_id, trx_id, amount, recipient_bank, recipient_account) => {
|
||||||
|
let result = knex
|
||||||
|
.select(
|
||||||
|
"t_d_card_replacement.i_card_replacement",
|
||||||
|
"t_d_card_replacement.c_request_no",
|
||||||
|
"t_d_card_replacement.c_card_no",
|
||||||
|
"t_d_card_replacement.i_request_disburse",
|
||||||
|
"t_d_card_replacement.c_refund_trx_id",
|
||||||
|
"t_d_card_replacement.c_status"
|
||||||
|
)
|
||||||
|
.from("trx.t_d_card_replacement")
|
||||||
|
// .leftJoin(
|
||||||
|
// "t_m_merchant", "t_m_terminal.c_card_no", "t_m_merchant.i_merchant"
|
||||||
|
// )
|
||||||
|
// .leftJoin("t_m_partner", "t_m_merchant.i_partner", "t_m_partner.i_partner")
|
||||||
|
.where("t_d_card_replacement.c_method", "CASHLESS")
|
||||||
|
// .where("t_d_card_replacement.c_status", "OP")
|
||||||
|
.where("t_d_card_replacement.i_last_balance", amount)
|
||||||
|
.where("t_d_card_replacement.c_request_no", partner_trx_id)
|
||||||
|
.where("t_d_card_replacement.c_refund_trx_id", trx_id)
|
||||||
|
.where("t_d_card_replacement.c_bank_code", recipient_bank)
|
||||||
|
.where("t_d_card_replacement.c_account_number", recipient_account)
|
||||||
|
// .whereNull("t_d_card_replacement.c_status", "OP")
|
||||||
|
.first();
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
|
// UPDATE REPLACEMENT
|
||||||
|
const updateReplacementComplete = (i_replacement, request_no, date_disburse) => {
|
||||||
|
let result = knex("trx.t_d_card_replacement")
|
||||||
|
.where("i_card_replacement", i_replacement)
|
||||||
|
.where("c_request_no", request_no)
|
||||||
|
.update({
|
||||||
|
c_status: "A",
|
||||||
|
c_status_name: "COMPLETED",
|
||||||
|
d_disburse: date_disburse,
|
||||||
|
c_response_code: "000",
|
||||||
|
c_response_message: "Success"
|
||||||
|
});
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
checkRedeem,
|
||||||
|
updateReplacementComplete
|
||||||
|
};
|
||||||
@@ -149,6 +149,18 @@ const checkReservation = async (req, res) => {
|
|||||||
// `${uniqueCode} [ PROCESSING RESERVATION-CHECK ] checking production card number or not...`
|
// `${uniqueCode} [ PROCESSING RESERVATION-CHECK ] checking production card number or not...`
|
||||||
// );
|
// );
|
||||||
|
|
||||||
|
let cardBlacklist = await model.getCardBlacklist(card_number);
|
||||||
|
if (cardBlacklist) {
|
||||||
|
if (cardBlacklist.c_status == 'B') {
|
||||||
|
result = {
|
||||||
|
code: '445',
|
||||||
|
message: 'Card is Blacklisted',
|
||||||
|
data: {},
|
||||||
|
};
|
||||||
|
return res.status(200).json(result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// jika settingan diperuntukan untuk production
|
// jika settingan diperuntukan untuk production
|
||||||
if (process.env.SERVER_FOR == 'production') {
|
if (process.env.SERVER_FOR == 'production') {
|
||||||
// kartu yang di request bukan kartu production maka akan di tolak
|
// kartu yang di request bukan kartu production maka akan di tolak
|
||||||
@@ -343,6 +355,18 @@ const reservationValidate = async (req, res) => {
|
|||||||
// `${uniqueCode} [ PROCESSING RESERVATION-VALIDATE ] checking production card number or not...`
|
// `${uniqueCode} [ PROCESSING RESERVATION-VALIDATE ] checking production card number or not...`
|
||||||
// );
|
// );
|
||||||
|
|
||||||
|
let cardBlacklist = await model.getCardBlacklist(card_number);
|
||||||
|
if (cardBlacklist) {
|
||||||
|
if (cardBlacklist.c_status == 'B') {
|
||||||
|
result = {
|
||||||
|
code: '445',
|
||||||
|
message: 'Card is Blacklisted',
|
||||||
|
data: {},
|
||||||
|
};
|
||||||
|
return res.status(200).json(result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// jika settingan diperuntukan untuk production
|
// jika settingan diperuntukan untuk production
|
||||||
if (process.env.SERVER_FOR == 'production') {
|
if (process.env.SERVER_FOR == 'production') {
|
||||||
// kartu yang di request bukan kartu production maka akan di tolak
|
// kartu yang di request bukan kartu production maka akan di tolak
|
||||||
@@ -768,6 +792,18 @@ const reservationValidateV2 = async (req, res) => {
|
|||||||
return res.status(200).json(result);
|
return res.status(200).json(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let cardBlacklist = await model.getCardBlacklist(card_number);
|
||||||
|
if (cardBlacklist) {
|
||||||
|
if (cardBlacklist.c_status == 'B') {
|
||||||
|
result = {
|
||||||
|
code: '445',
|
||||||
|
message: 'Card is Blacklisted',
|
||||||
|
data: {},
|
||||||
|
};
|
||||||
|
return res.status(200).json(result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// log debug
|
// log debug
|
||||||
// pengecekkan nomor kartu yang di request adalah kartu production atau bukan berdasarkan settingan di .ENV dengan constanta SERVER_FOR.
|
// 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
|
// 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
|
||||||
@@ -1258,6 +1294,18 @@ const reservation = async (req, res) => {
|
|||||||
// `${uniqueCode} [ PROCESSING RESERVATION ] checking production card number or not...`
|
// `${uniqueCode} [ PROCESSING RESERVATION ] checking production card number or not...`
|
||||||
// );
|
// );
|
||||||
|
|
||||||
|
let cardBlacklist = await model.getCardBlacklist(card_number);
|
||||||
|
if (cardBlacklist) {
|
||||||
|
if (cardBlacklist.c_status == 'B') {
|
||||||
|
result = {
|
||||||
|
code: '445',
|
||||||
|
message: 'Card is Blacklisted',
|
||||||
|
data: {},
|
||||||
|
};
|
||||||
|
return res.status(200).json(result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// jika settingan diperuntukan untuk production
|
// jika settingan diperuntukan untuk production
|
||||||
if (process.env.SERVER_FOR == 'production') {
|
if (process.env.SERVER_FOR == 'production') {
|
||||||
// kartu yang di request bukan kartu production maka akan di tolak
|
// kartu yang di request bukan kartu production maka akan di tolak
|
||||||
@@ -1982,6 +2030,20 @@ const reservationV2 = async (req, res) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let cardBlacklist = await model.getCardBlacklist(
|
||||||
|
reservationData.card_number
|
||||||
|
);
|
||||||
|
if (cardBlacklist) {
|
||||||
|
if (cardBlacklist.c_status == 'B') {
|
||||||
|
result = {
|
||||||
|
code: '445',
|
||||||
|
message: 'Card is Blacklisted',
|
||||||
|
data: {},
|
||||||
|
};
|
||||||
|
return res.status(200).json(result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (amount) {
|
if (amount) {
|
||||||
if (reservationData.amount != amount) {
|
if (reservationData.amount != amount) {
|
||||||
result = {
|
result = {
|
||||||
|
|||||||
@@ -72,6 +72,15 @@ const getIssuer = (id, time) => {
|
|||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// GET IS CARD ADDED TO BLACKLIST
|
||||||
|
const getCardBlacklist = (card_number) => {
|
||||||
|
let result = knex('public.t_m_card_blacklist')
|
||||||
|
.select('c_status')
|
||||||
|
.where('c_card_number', card_number)
|
||||||
|
.first();
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
// GET RESERVATION EXPIRATION DATE FROM GLOBAL PARAMETER
|
// GET RESERVATION EXPIRATION DATE FROM GLOBAL PARAMETER
|
||||||
const getReservationExpirationDateValue = () => {
|
const getReservationExpirationDateValue = () => {
|
||||||
let result = knex('t_m_global_parameter')
|
let result = knex('t_m_global_parameter')
|
||||||
@@ -540,6 +549,7 @@ module.exports = {
|
|||||||
getReservationNumberSequence,
|
getReservationNumberSequence,
|
||||||
getPartner,
|
getPartner,
|
||||||
getIssuer,
|
getIssuer,
|
||||||
|
getCardBlacklist,
|
||||||
getReservationExpirationDateValue,
|
getReservationExpirationDateValue,
|
||||||
getReservationExpirationDateMeasure,
|
getReservationExpirationDateMeasure,
|
||||||
getCheckByCardProductStatusValue,
|
getCheckByCardProductStatusValue,
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
const express = require("express");
|
||||||
|
const router = express.Router();
|
||||||
|
// const auth = require("../middlewares/jwt.middleware");
|
||||||
|
const controller = require("../modules/refundkmt/refundkmt.controller");
|
||||||
|
|
||||||
|
router.post(
|
||||||
|
"/refund-callback",
|
||||||
|
// auth.authenticateToken,
|
||||||
|
controller.validate("callbackOy"),
|
||||||
|
controller.callbackOy
|
||||||
|
);
|
||||||
|
|
||||||
|
module.exports = router;
|
||||||
@@ -13,6 +13,7 @@ const paymentReconRoute = require('../application/routes/paymentrecon.routes');
|
|||||||
const invoiceRoute = require('../application/routes/invoiceonline.routes');
|
const invoiceRoute = require('../application/routes/invoiceonline.routes');
|
||||||
const cashinRoute = require('../application/routes/cahsin.routes');
|
const cashinRoute = require('../application/routes/cahsin.routes');
|
||||||
const pooling = require('../application/routes/pooling.routes');
|
const pooling = require('../application/routes/pooling.routes');
|
||||||
|
const refundkmtRoute = require('../application/routes/refundkmt.routes');
|
||||||
const cron = require('node-cron');
|
const cron = require('node-cron');
|
||||||
const moment = require('moment');
|
const moment = require('moment');
|
||||||
require('dotenv').config();
|
require('dotenv').config();
|
||||||
@@ -83,6 +84,7 @@ app.use('/api/', reservationRoute);
|
|||||||
app.use('/api/', invoiceRoute);
|
app.use('/api/', invoiceRoute);
|
||||||
app.use('/api/', cashinRoute);
|
app.use('/api/', cashinRoute);
|
||||||
app.use('/api/', pooling);
|
app.use('/api/', pooling);
|
||||||
|
app.use('/api/', refundkmtRoute);
|
||||||
|
|
||||||
// ============================== SAP SCHEDULLER =============================
|
// ============================== SAP SCHEDULLER =============================
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user