mirror of
https://github.com/mohamadihsan/topuponline.git
synced 2026-12-06 02:06:27 +00:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 4495f910b0 |
@@ -86,38 +86,38 @@ const loadingBalanceRequest = async (req, res) => {
|
||||
`${uniqueCode} checking production card number or not...`
|
||||
);
|
||||
|
||||
// if (process.env.SERVER_FOR == 'production') {
|
||||
// if (card_number.substring(0, 1) != '1') {
|
||||
// result = {
|
||||
// code: '400',
|
||||
// message: "It's not production card number.",
|
||||
// data: {},
|
||||
// };
|
||||
if (process.env.SERVER_FOR == 'production') {
|
||||
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 check reservation: ${JSON.stringify(result)}`
|
||||
// );
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} RESPONSE check reservation: ${JSON.stringify(result)}`
|
||||
);
|
||||
|
||||
// return res.status(200).json(result);
|
||||
// }
|
||||
// } else {
|
||||
// if (card_number.substring(0, 1) == '1') {
|
||||
// result = {
|
||||
// code: '400',
|
||||
// message:
|
||||
// "It's production card number. Please use the development card number.",
|
||||
// data: {},
|
||||
// };
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
} else {
|
||||
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 check reservation: ${JSON.stringify(result)}`
|
||||
// );
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} RESPONSE check reservation: ${JSON.stringify(result)}`
|
||||
);
|
||||
|
||||
// return res.status(200).json(result);
|
||||
// }
|
||||
// }
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
}
|
||||
|
||||
// time
|
||||
let now = moment().format('YYYY-MM-DD HH:mm:ss');
|
||||
@@ -412,150 +412,194 @@ const loadingBalanceRequest = async (req, res) => {
|
||||
`${uniqueCode} checking the card number in list fraud transaction or not...`
|
||||
);
|
||||
|
||||
// log debug
|
||||
winston.logger.debug(`${uniqueCode} checking total topup amount...`);
|
||||
|
||||
// check total amount topup
|
||||
if (parseInt(amountTopup) <= 0) {
|
||||
result = {
|
||||
code: '415',
|
||||
message: 'amount must be greater than 0',
|
||||
data: {},
|
||||
};
|
||||
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} RESPONSE load balance validate: ${JSON.stringify(
|
||||
result
|
||||
)}`
|
||||
);
|
||||
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
|
||||
// log debug
|
||||
winston.logger.debug(`${uniqueCode} checking BI regulation status...`);
|
||||
|
||||
// get BI regulation status
|
||||
const getBIRegulationStatus = await model.getBIRegulationStatus();
|
||||
if (getBIRegulationStatus.c_value == 'A') {
|
||||
// log debug
|
||||
winston.logger.debug(`${uniqueCode} checking max balance on the card...`);
|
||||
|
||||
// get max saldo on the card
|
||||
const getMaxAmountOnTheCard = await model.getMaxAmountOnTheCard();
|
||||
if (getMaxAmountOnTheCard.c_value) {
|
||||
if (
|
||||
parseInt(balance) + parseInt(amountTopup) >
|
||||
parseInt(getMaxAmountOnTheCard.c_value)
|
||||
) {
|
||||
result = {
|
||||
code: '416',
|
||||
message: 'your card number has reached the maximum balance',
|
||||
data: {},
|
||||
};
|
||||
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} RESPONSE load balance validate: ${JSON.stringify(
|
||||
result
|
||||
)}`
|
||||
);
|
||||
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
}
|
||||
|
||||
// log debug
|
||||
winston.logger.debug(`${uniqueCode} checking max topup per month...`);
|
||||
|
||||
// get accumulated balance in this month
|
||||
let accumulatedBalance = 0;
|
||||
let getAccumulationBalanceInThisMonthFromCardHistory =
|
||||
await model.getAccumulationBalanceInThisMonthFromCardHistory(
|
||||
card_number,
|
||||
year,
|
||||
month
|
||||
);
|
||||
if (getAccumulationBalanceInThisMonthFromCardHistory) {
|
||||
accumulatedBalance =
|
||||
getAccumulationBalanceInThisMonthFromCardHistory.accumulation_balance;
|
||||
}
|
||||
|
||||
// validate max topup per month
|
||||
const getMaxTopupPerMonth = await model.getMaxTopupPerMonth();
|
||||
if (getMaxTopupPerMonth.c_value) {
|
||||
if (
|
||||
parseInt(accumulatedBalance) + parseInt(amountTopup) >
|
||||
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 load balance validate: ${JSON.stringify(
|
||||
result
|
||||
)}`
|
||||
);
|
||||
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// log debug
|
||||
winston.logger.debug(
|
||||
`${uniqueCode} updating status reservation to in progress...${reservationNumberTemp}, ${now}, ${flag}`
|
||||
// check fraud transaction by card number and how much fraud amount
|
||||
let fraudTransaction = await model.getFraudTopupAndDeductTransaction(
|
||||
card_number
|
||||
);
|
||||
|
||||
// update status to in progress
|
||||
let updateStatusReservation = await model.updateStatusReservation(
|
||||
reservationNumberTemp,
|
||||
now,
|
||||
flag
|
||||
);
|
||||
let fraudReservationNumber = [];
|
||||
let amountFraudTopup = 0;
|
||||
let amountFraudDeduct = 0;
|
||||
let restAmountFraud = 0;
|
||||
let totalFraudReservation = 0;
|
||||
|
||||
// log debug
|
||||
winston.logger.debug(`${uniqueCode} XXXXX ${updateStatusReservation}`);
|
||||
// if card number has fraud transaction
|
||||
if (fraudTransaction.length > 0) {
|
||||
let i = 0;
|
||||
|
||||
if (fraudTransaction.length > 0) {
|
||||
fraudTransaction.forEach((rsv) => {
|
||||
fraudReservationNumber.push(rsv.c_reservation_no);
|
||||
amountFraudTopup += parseInt(rsv.i_reservation_amount);
|
||||
i++;
|
||||
});
|
||||
}
|
||||
totalFraudReservation = i;
|
||||
}
|
||||
|
||||
// calculate rest amount fraud
|
||||
restAmountFraud = parseInt(amountFraudTopup) - parseInt(amountFraudDeduct);
|
||||
|
||||
// if card number has fraud transaction and amount greater than 0
|
||||
if (parseInt(restAmountFraud) > 0) {
|
||||
// fraud reservation found, and tell the lib to deduct transaction
|
||||
|
||||
if (updateStatusReservation) {
|
||||
result = {
|
||||
code: '00',
|
||||
message: 'reservation exists',
|
||||
data: {
|
||||
amount: amountTopup,
|
||||
total_reservation: totalReservation,
|
||||
reservation_number: reservationNumber,
|
||||
amount: parseInt(amountFraudTopup) * -1,
|
||||
total_reservation: totalFraudReservation,
|
||||
reservation_number: fraudReservationNumber,
|
||||
},
|
||||
};
|
||||
|
||||
// log info
|
||||
winston.logger.info(
|
||||
`${uniqueCode} RESPONSE load balance validate: ${JSON.stringify(
|
||||
result
|
||||
)}`
|
||||
);
|
||||
} else {
|
||||
result = {
|
||||
code: '434',
|
||||
message: '[434] Failed, please try again later',
|
||||
data: {
|
||||
amount: amountTopup,
|
||||
total_reservation: totalReservation,
|
||||
reservation_number: reservationNumber,
|
||||
},
|
||||
};
|
||||
// card number does't have fraud transaction
|
||||
|
||||
// log info
|
||||
winston.logger.info(
|
||||
`${uniqueCode} RESPONSE load balance validate: ${JSON.stringify(
|
||||
result
|
||||
)}`
|
||||
// log debug
|
||||
winston.logger.debug(`${uniqueCode} checking total topup amount...`);
|
||||
|
||||
// check total amount topup
|
||||
if (parseInt(amountTopup) <= 0) {
|
||||
result = {
|
||||
code: '415',
|
||||
message: 'amount must be greater than 0',
|
||||
data: {},
|
||||
};
|
||||
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} RESPONSE load balance validate: ${JSON.stringify(
|
||||
result
|
||||
)}`
|
||||
);
|
||||
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
|
||||
// log debug
|
||||
winston.logger.debug(`${uniqueCode} checking BI regulation status...`);
|
||||
|
||||
// get BI regulation status
|
||||
const getBIRegulationStatus = await model.getBIRegulationStatus();
|
||||
if (getBIRegulationStatus.c_value == 'A') {
|
||||
// log debug
|
||||
winston.logger.debug(
|
||||
`${uniqueCode} checking max balance on the card...`
|
||||
);
|
||||
|
||||
// get max saldo on the card
|
||||
const getMaxAmountOnTheCard = await model.getMaxAmountOnTheCard();
|
||||
if (getMaxAmountOnTheCard.c_value) {
|
||||
if (
|
||||
parseInt(balance) + parseInt(amountTopup) >
|
||||
parseInt(getMaxAmountOnTheCard.c_value)
|
||||
) {
|
||||
result = {
|
||||
code: '416',
|
||||
message: 'your card number has reached the maximum balance',
|
||||
data: {},
|
||||
};
|
||||
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} RESPONSE load balance validate: ${JSON.stringify(
|
||||
result
|
||||
)}`
|
||||
);
|
||||
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
}
|
||||
|
||||
// log debug
|
||||
winston.logger.debug(`${uniqueCode} checking max topup per month...`);
|
||||
|
||||
// get accumulated balance in this month
|
||||
let accumulatedBalance = 0;
|
||||
let getAccumulationBalanceInThisMonthFromCardHistory =
|
||||
await model.getAccumulationBalanceInThisMonthFromCardHistory(
|
||||
card_number,
|
||||
year,
|
||||
month
|
||||
);
|
||||
if (getAccumulationBalanceInThisMonthFromCardHistory) {
|
||||
accumulatedBalance =
|
||||
getAccumulationBalanceInThisMonthFromCardHistory.accumulation_balance;
|
||||
}
|
||||
|
||||
// validate max topup per month
|
||||
const getMaxTopupPerMonth = await model.getMaxTopupPerMonth();
|
||||
if (getMaxTopupPerMonth.c_value) {
|
||||
if (
|
||||
parseInt(accumulatedBalance) + parseInt(amountTopup) >
|
||||
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 load balance validate: ${JSON.stringify(
|
||||
result
|
||||
)}`
|
||||
);
|
||||
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// log debug
|
||||
winston.logger.debug(
|
||||
`${uniqueCode} updating status reservation to in progress...`
|
||||
);
|
||||
|
||||
// update status to in progress
|
||||
let updateStatusReservation = await model.updateStatusReservation(
|
||||
reservationNumberTemp,
|
||||
now,
|
||||
flag
|
||||
);
|
||||
|
||||
if (updateStatusReservation) {
|
||||
result = {
|
||||
code: '00',
|
||||
message: 'reservation exists',
|
||||
data: {
|
||||
amount: amountTopup,
|
||||
total_reservation: totalReservation,
|
||||
reservation_number: reservationNumber,
|
||||
},
|
||||
};
|
||||
|
||||
// log info
|
||||
winston.logger.info(
|
||||
`${uniqueCode} RESPONSE load balance validate: ${JSON.stringify(
|
||||
result
|
||||
)}`
|
||||
);
|
||||
} else {
|
||||
result = {
|
||||
code: '434',
|
||||
message: '[434] Failed, please try again later',
|
||||
data: {
|
||||
amount: amountTopup,
|
||||
total_reservation: totalReservation,
|
||||
reservation_number: reservationNumber,
|
||||
},
|
||||
};
|
||||
|
||||
// log info
|
||||
winston.logger.info(
|
||||
`${uniqueCode} RESPONSE load balance validate: ${JSON.stringify(
|
||||
result
|
||||
)}`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return res.json(result);
|
||||
@@ -624,38 +668,38 @@ const loadingBalance = async (req, res) => {
|
||||
`${uniqueCode} checking production card number or not...`
|
||||
);
|
||||
|
||||
// if (process.env.SERVER_FOR == 'production') {
|
||||
// if (card_number.substring(0, 1) != '1') {
|
||||
// result = {
|
||||
// code: '400',
|
||||
// message: "It's not production card number.",
|
||||
// data: {},
|
||||
// };
|
||||
if (process.env.SERVER_FOR == 'production') {
|
||||
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 check reservation: ${JSON.stringify(result)}`
|
||||
// );
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} RESPONSE check reservation: ${JSON.stringify(result)}`
|
||||
);
|
||||
|
||||
// return res.status(200).json(result);
|
||||
// }
|
||||
// } else {
|
||||
// if (card_number.substring(0, 1) == '1') {
|
||||
// result = {
|
||||
// code: '400',
|
||||
// message:
|
||||
// "It's production card number. Please use the development card number.",
|
||||
// data: {},
|
||||
// };
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
} else {
|
||||
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 check reservation: ${JSON.stringify(result)}`
|
||||
// );
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} RESPONSE check reservation: ${JSON.stringify(result)}`
|
||||
);
|
||||
|
||||
// return res.status(200).json(result);
|
||||
// }
|
||||
// }
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
}
|
||||
|
||||
// time
|
||||
let now = moment().format('YYYY-MM-DD HH:mm:ss');
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user