Compare commits

...

4 Commits

Author SHA1 Message Date
Mohamad Ihsan 225fc644d3 Update station code in card replacement example 2026-11-26 14:40:26 +07:00
Mohamad Ihsan 85fa8843d8 Remove card category code from replacement response 2026-11-26 03:43:10 +07:00
Mohamad Ihsan 005746e29f Update card replacement Bruno request and dev environment 2026-11-26 03:39:34 +07:00
Mohamad Ihsan 34610e9515 Handle missing CTS configuration and request failures 2026-11-26 03:39:06 +07:00
3 changed files with 69 additions and 12 deletions
@@ -295,8 +295,20 @@ const validateReplacement = async (req, res) => {
// if (is_warranty == true) {
let result = {};
const ctsUrl = process.env.CTS_URL?.trim();
if (!ctsUrl) {
return res.status(200).json({
code: '500',
message: 'CTS connection has not been configured.',
data: {
status: false,
detail: {},
},
});
}
// const baseUrl = 'https://appdev.kci.id/cts/v2/api/info/last-balance'
const baseUrl = `${process.env.CTS_URL}/v2/api/info/last-balance`;
const baseUrl = `${ctsUrl}/v2/api/info/last-balance`;
const payload = {
card_number: card_number,
};
@@ -306,7 +318,22 @@ const validateReplacement = async (req, res) => {
},
};
const url = baseUrl;
const response = await postWithDeadline(url, payload, config);
let response;
try {
response = await postWithDeadline(url, payload, config);
} catch (error) {
winston.logger.warn(
`${logCorrelation(uniqueCode)} [ CTS REQUEST FAILED ] error_code=${logErrorCode(error)}`
);
return res.status(200).json({
code: '415',
message: 'Failed to retrieve last balance from CTS.',
data: {
status: false,
detail: {},
},
});
}
if (response.data.code == undefined || response.data.code != 200) {
if (response.data.code == 404) {
result = {
@@ -324,7 +351,7 @@ const validateReplacement = async (req, res) => {
}
result = {
code: '415',
message: 'Last Balance not updated.',
message: 'Failed to retrieve last balance from CTS.',
data: {
status: false,
detail: {},
@@ -391,7 +418,6 @@ const validateReplacement = async (req, res) => {
unique_code: uniqueCode,
card_category: {
id: dataCardReplacement.card_category_id,
code: dataCardReplacement.card_category_code,
name: dataCardReplacement.card_category_name
}
},
@@ -20,25 +20,25 @@ auth:bearer {
body:json {
{
"card_number": "0000000000000001",
"station_code": "TEST01"
"card_number": "1003012302000000",
"station_code": "JUA"
}
}
docs {
### Deskripsi
Memeriksa kelayakan kartu untuk penggantian dan menyiapkan data konfirmasi.
### Request
- Endpoint POST /api/pos/cardreplacement/validate
- Kirim Authorization: Bearer dengan accessToken dari login.
- Contoh JSON tersedia di tab Body.
- Route tidak membaca query atau path parameter tambahan.
### Respons
Handler umumnya mengembalikan HTTP 200. Untuk hasil aplikasi, periksa field code, message, dan data. Gunakan header X-Request-Id untuk pencarian log.
| Code | Message |
| --- | --- |
| 00 | Successfully. |
@@ -60,10 +60,10 @@ docs {
| 494 | No data found in CTS for the given card number |
| 500 | *Pesan kegagalan dapat berasal dari exception atau dependensi.* |
| 500 | 500 internal server error - backend server. |
**Pesan validasi yang dapat dikembalikan**
- Card number is required
- Station Code is required
Pesan yang dicetak miring bersifat dinamis. Nilai aktual dapat mengikuti input atau hasil dari service lain.
}
@@ -0,0 +1,31 @@
vars {
baseUrl: https://dev-topup.kci.id/api
reservationData: ISI_DARI_LINGKUNGAN_UJI
cancelReservationData: ISI_DARI_LINGKUNGAN_UJI
replacementUniqueCode: SAMPLE-HSM-01
replacementSecurityCode: ISI_DARI_LINGKUNGAN_UJI
redeemSecurityCode: ISI_DARI_LINGKUNGAN_UJI
topupStep1Data: ISI_DARI_LINGKUNGAN_UJI
topupStep2Data: ISI_DARI_LINGKUNGAN_UJI
topupUniqueCode: SAMPLE-HSM-01
topupTrxId: 0001
topupStep3Data: ISI_DARI_LINGKUNGAN_UJI
topupStep4Data: ISI_DARI_LINGKUNGAN_UJI
topupStep5Data: ISI_DARI_LINGKUNGAN_UJI
topupStep6Data: ISI_DARI_LINGKUNGAN_UJI
topupStep7Data: ISI_DARI_LINGKUNGAN_UJI
topupLoadBalanceNumber: ISI_DARI_LINGKUNGAN_UJI
clearStep1Data: ISI_DARI_LINGKUNGAN_UJI
clearStep2Data: ISI_DARI_LINGKUNGAN_UJI
clearUniqueCode: SAMPLE-HSM-01
clearTrxId: 0001
clearStep3Data: ISI_DARI_LINGKUNGAN_UJI
clearStep4Data: ISI_DARI_LINGKUNGAN_UJI
clearStep5Data: ISI_DARI_LINGKUNGAN_UJI
clearStep6Data: ISI_DARI_LINGKUNGAN_UJI
clearStep7Data: ISI_DARI_LINGKUNGAN_UJI
}
vars:secret [
accessToken,
refreshToken
]