From d2d44f3ba9032140b96777602843f9df6fa8ba1a Mon Sep 17 00:00:00 2001 From: Mohamad Ihsan Date: Tue, 26 Aug 2025 18:15:45 +0700 Subject: [PATCH] add check balance to CTS --- application/modules/pos/pos.controller.js | 50 ++++++++++++++++++----- 1 file changed, 39 insertions(+), 11 deletions(-) diff --git a/application/modules/pos/pos.controller.js b/application/modules/pos/pos.controller.js index 7fcb793..db79d60 100644 --- a/application/modules/pos/pos.controller.js +++ b/application/modules/pos/pos.controller.js @@ -1310,19 +1310,47 @@ const validateRedeem = async (req, res) => { last_balance = dataCardReplacement.i_last_balance; if (last_balance == null) { - result = { - code: '415', - message: 'Last Balance not updated.', - data: { - status: false, - detail: {}, + let result = {}; + // const baseUrl = 'https://appdev.kci.id/cts/v2/api/info/last-balance' + const baseUrl = `${process.env.CTS_URL}/v2/api/info/last-balance` + const payload = { + card_number: card_number, + }; + let config = { + headers: { + 'Content-Type': 'application/json' }, }; - //LOG-INFO - winston.logger.info( - `${uniqueCode} [ RESPONSE VALIDATE-REDEEM ]: ${JSON.stringify(result)}` - ); - return res.status(200).json(result); + const url = baseUrl; + const response = await axios.post(url, payload, config); + if (response.data.code == undefined || response.data.code != 200) { + if (response.data.code == 404) { + result = { + code: '494', + message: 'No data found in CTS for the given card number', + data: { + status: false, + detail: {} + } + }; + winston.logger.info( + `${uniqueCode} [ FAILED HIT - card_number : ${card_number} ]: ${response.data.message}` + ); + return res.status(200).json(result); + } + result = { + code: '415', + message: 'Last Balance not updated.', + data: { + status: false, + detail: {} + }, + }; + winston.logger.info( + `${uniqueCode} [ FAILED HIT - card_number : ${card_number} ]: ${response.data.message}` + ); + return res.status(200).json(result); + } } let security_code = await helper.createHMAC(card_number);