mirror of
https://github.com/mohamadihsan/topuponline.git
synced 2026-12-06 19:16:27 +00:00
Handle invalid reservation V2 data and improve failure diagnostics
This commit is contained in:
@@ -1474,6 +1474,7 @@ const reservation = async (req, res) => {
|
||||
};
|
||||
|
||||
const reservationV2 = async (req, res) => {
|
||||
let stage = 'validate_request';
|
||||
try {
|
||||
// generate unique code
|
||||
// unique code ini digunakan untuk keperluan log agar mudah untuk dibaca
|
||||
@@ -1521,13 +1522,16 @@ const reservationV2 = async (req, res) => {
|
||||
// `${uniqueCode} [ PROCESSING RESERVATION-V2 ] checking reservation data...`
|
||||
// );
|
||||
|
||||
stage = 'decode_reservation_data';
|
||||
let reservationData;
|
||||
|
||||
try {
|
||||
reservationData = helper.decryptText(reservation_data);
|
||||
} catch (error) { }
|
||||
const plaintext = helper.decryptText(reservation_data);
|
||||
if (typeof plaintext === 'string' && plaintext) reservationData = JSON.parse(plaintext);
|
||||
} catch {
|
||||
// Muatan yang gagal didekripsi atau diurai ditolak sebagai input yang tidak valid.
|
||||
}
|
||||
|
||||
if (!reservationData) {
|
||||
if (!reservationData || typeof reservationData !== 'object' || Array.isArray(reservationData)) {
|
||||
result = {
|
||||
code: '435',
|
||||
message: 'bad request. reservation data is invalid.',
|
||||
@@ -1542,9 +1546,6 @@ const reservationV2 = async (req, res) => {
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
|
||||
// parsing data to json format
|
||||
reservationData = JSON.parse(reservationData);
|
||||
|
||||
if (
|
||||
!reservationData.mid ||
|
||||
!reservationData.tid ||
|
||||
@@ -1584,6 +1585,7 @@ const reservationV2 = async (req, res) => {
|
||||
}
|
||||
}
|
||||
|
||||
stage = 'check_card_blacklist';
|
||||
let cardBlacklist = await model.getCardBlacklist(
|
||||
reservationData.card_number
|
||||
);
|
||||
@@ -1624,6 +1626,7 @@ const reservationV2 = async (req, res) => {
|
||||
let transactionDate = reservationData.transaction_date;
|
||||
let securityCode = reservationData.security_code;
|
||||
|
||||
stage = 'verify_reservation_data';
|
||||
if (securityCode) {
|
||||
// log debug
|
||||
// process enkripsi data reservasi dengan HMAC sebagai pembanding bahwa data yang di decrypt valid
|
||||
@@ -1724,6 +1727,7 @@ const reservationV2 = async (req, res) => {
|
||||
// );
|
||||
|
||||
// get partner, merchant, terminal from tid
|
||||
stage = 'lookup_partner';
|
||||
let getPartner = await model.getPartner(mid, tid);
|
||||
if (!getPartner) {
|
||||
result = {
|
||||
@@ -1757,6 +1761,7 @@ const reservationV2 = async (req, res) => {
|
||||
// );
|
||||
|
||||
// get parameter to check with card product cms or not
|
||||
stage = 'check_reservation_limits';
|
||||
let getCheckByCardProductStatusValue =
|
||||
await model.getCheckByCardProductStatusValue();
|
||||
let checkByCardProductStatusValue =
|
||||
@@ -2010,6 +2015,7 @@ const reservationV2 = async (req, res) => {
|
||||
let channelFee = 0;
|
||||
|
||||
// get issuer fee dan channel fee dari table public.t_c_partner_fee
|
||||
stage = 'lookup_issuer_fee';
|
||||
let getIssuer = await model.getIssuer(getPartner.i_partner, now);
|
||||
|
||||
if (getIssuer) {
|
||||
@@ -2046,6 +2052,7 @@ const reservationV2 = async (req, res) => {
|
||||
// `${uniqueCode} [ PROCESSING RESERVATION-V2 ] getting reservation expiration date on parameter...`
|
||||
// );
|
||||
|
||||
stage = 'lookup_reservation_expiration';
|
||||
const { time, measure } = await model.getReservationExpiration();
|
||||
let expired = moment(now).add(time, measure).format('YYYY-MM-DD HH:mm:ss');
|
||||
|
||||
@@ -2062,6 +2069,7 @@ const reservationV2 = async (req, res) => {
|
||||
phoneNumber = mid + '_' + tid;
|
||||
}
|
||||
|
||||
stage = 'allocate_reservation_number';
|
||||
const { number: reservationNumber, sequence: reservationNoSequence } =
|
||||
await model.allocateReservationNumber(getPartner.partner_code, moment(now).format('YYMMDD'));
|
||||
|
||||
@@ -2123,6 +2131,7 @@ const reservationV2 = async (req, res) => {
|
||||
// (belum) ada issue disini, jadi ada case reservation number nya sama, terus error query harusnya ada handle response message nya, yg sekarang malah masuk ke blok reservation saved successfully.
|
||||
|
||||
// insert transaction
|
||||
stage = 'insert_reservation';
|
||||
let insert = await model.insertReservation(data);
|
||||
|
||||
// jika proses insert data semua yang berkaitan dengan reservasi saldo mengalami kegagalan, maka lakukan rollback
|
||||
@@ -2134,6 +2143,7 @@ const reservationV2 = async (req, res) => {
|
||||
// );
|
||||
|
||||
// log card history
|
||||
stage = 'write_reservation_history';
|
||||
await model.createReserveBalanceLog({
|
||||
i_log_name: 90,
|
||||
d_log: now,
|
||||
@@ -2192,9 +2202,11 @@ const reservationV2 = async (req, res) => {
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
} catch (error) {
|
||||
// create log
|
||||
// Simpan tahap dan kode aman tersedia di audit tanpa menyalin exception mentah.
|
||||
const errorCode = logErrorCode(error);
|
||||
res.locals.reservationFailure = { stage, code: errorCode };
|
||||
winston.logger.error(
|
||||
`[ RESPONSE RESERVATION-V2 ] code=500 error_code=${logErrorCode(error)}`
|
||||
`[ RESPONSE RESERVATION-V2 ] code=500 error_code=${errorCode} error_stage=${stage}`
|
||||
);
|
||||
|
||||
return res.status(200).json({
|
||||
|
||||
Reference in New Issue
Block a user