add check balance to CTS

This commit is contained in:
2025-08-26 18:15:45 +07:00
parent 4dccbf20f5
commit d2d44f3ba9
+39 -11
View File
@@ -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);