diff --git a/application/modules/hsm/authenticate1.js b/application/modules/hsm/authenticate1.js index c8c0af3..175569d 100644 --- a/application/modules/hsm/authenticate1.js +++ b/application/modules/hsm/authenticate1.js @@ -64,20 +64,20 @@ const controller = async (req, res) => { await _sleep(10); } - if (_timeOut) { - result = { - code: "99", - message: "Timeout", - data: {}, - }; + // if (_timeOut) { + // result = { + // code: "5001", + // message: "Timeout", + // data: {}, + // }; - // log warn - winston.logger.warn( - `${uniqueCode} response HSM - auth1v2: ${JSON.stringify(result)}` - ); + // // log warn + // winston.logger.warn( + // `${uniqueCode} response HSM - auth1v2: ${JSON.stringify(result)}` + // ); - return res.status(200).send(result); - } + // return res.status(200).send(result); + // } _stopMessage = 0; @@ -110,7 +110,7 @@ const controller = async (req, res) => { ); return res.status(200).send({ - code: "500", + code: "5001", message: process.env.NODE_ENV != "production" ? error.message diff --git a/application/modules/hsm/authenticate2.js b/application/modules/hsm/authenticate2.js index 00903d4..c0f2b54 100644 --- a/application/modules/hsm/authenticate2.js +++ b/application/modules/hsm/authenticate2.js @@ -23,7 +23,7 @@ const controller = async (req, res) => { if (auth2v2requestData[0] != 0x41) { result = { - code: "403", + code: "5003", message: "Wrong Respone from Card", data: {}, }; @@ -104,7 +104,7 @@ const controller = async (req, res) => { ); return res.status(200).send({ - code: "500", + code: "5001", message: process.env.NODE_ENV != "production" ? error.message diff --git a/application/modules/hsm/authenticateResp.js b/application/modules/hsm/authenticateResp.js index 6ae8531..8ac5a53 100644 --- a/application/modules/hsm/authenticateResp.js +++ b/application/modules/hsm/authenticateResp.js @@ -25,7 +25,7 @@ const controller = async (req, res) => { if (auth2v2responseSetData[0] != 0x43) { result = { - code: "403", + code: "5003", message: "Wrong Respone from Card", data: {}, }; @@ -107,7 +107,7 @@ const controller = async (req, res) => { ); return res.status(200).send({ - code: "500", + code: "5001", message: process.env.NODE_ENV != "production" ? error.message diff --git a/application/modules/hsm/endTranscation.js b/application/modules/hsm/endTranscation.js index d19e268..2b8e370 100644 --- a/application/modules/hsm/endTranscation.js +++ b/application/modules/hsm/endTranscation.js @@ -88,7 +88,7 @@ const controller = async (req, res) => { ); return res.status(200).send({ - code: "500", + code: "5001", message: process.env.NODE_ENV != "production" ? error.message diff --git a/application/modules/hsm/readData.js b/application/modules/hsm/readData.js index afa9aa2..709a0ac 100644 --- a/application/modules/hsm/readData.js +++ b/application/modules/hsm/readData.js @@ -90,7 +90,7 @@ const controller = async (req, res) => { ); return res.status(200).send({ - code: "500", + code: "5001", message: process.env.NODE_ENV != "production" ? error.message diff --git a/application/modules/hsm/readDataResp.js b/application/modules/hsm/readDataResp.js index e2fa8ca..a126c5e 100644 --- a/application/modules/hsm/readDataResp.js +++ b/application/modules/hsm/readDataResp.js @@ -101,7 +101,7 @@ const controller = async (req, res) => { ); return res.status(200).send({ - code: "500", + code: "5001", message: process.env.NODE_ENV != "production" ? error.message diff --git a/application/modules/hsm/service_block.js b/application/modules/hsm/service_block.js index 94ee039..b982aad 100644 --- a/application/modules/hsm/service_block.js +++ b/application/modules/hsm/service_block.js @@ -21,7 +21,7 @@ const controller = async (req, res) => { }) } catch (error) { return res.json({ - code: "500", + code: "5001", message: process.env.NODE_ENV != "production" ? error.message : '500 internal server error - backend server.', data: {}, }); diff --git a/application/modules/hsm/topup.js b/application/modules/hsm/topup.js index 0e3b27c..72ebb4c 100644 --- a/application/modules/hsm/topup.js +++ b/application/modules/hsm/topup.js @@ -92,7 +92,7 @@ const controller = async (req, res) => { ); return res.status(200).send({ - code: "500", + code: "5001", message: process.env.NODE_ENV != "production" ? error.message diff --git a/application/modules/hsm/topupResp.js b/application/modules/hsm/topupResp.js index b65a5cb..aa37c5f 100644 --- a/application/modules/hsm/topupResp.js +++ b/application/modules/hsm/topupResp.js @@ -79,18 +79,25 @@ const controller = async (req, res) => { respData[6] != 0x47 || (respData1[9] != 0x00 && respData1[10] != 0x00) ) { - return res.status(200).send({ - code: "02", - message: "Gagal", + result = { + code: "5002", + message: "failed from HSM", data: { trxID: generate.buf2hex(transactionId), responseCode: respData1.slice(6, 10), transcode: null, }, - }); + }; + + // log warn + winston.logger.warn( + `${uniqueCode} response HSM - topup resp: ${JSON.stringify(result)}` + ); + + return res.status(200).send(result); } - return res.status(200).send({ + result = { code: "00", message: "Topup Succeess", data: { @@ -99,7 +106,14 @@ const controller = async (req, res) => { responseData: respData1, responseLength: respData1.length / 2, }, - }); + }; + + // log debug + winston.logger.debug( + `${uniqueCode} HSM - message topup resp: ${generate.buf2hex(message)}` + ); + + return res.status(200).send(result); } catch (error) { // create log winston.logger.error( @@ -107,7 +121,7 @@ const controller = async (req, res) => { ); return res.status(200).send({ - code: "500", + code: "5001", message: process.env.NODE_ENV != "production" ? error.message diff --git a/docs/error_code b/docs/error_code index e69de29..110d54e 100644 --- a/docs/error_code +++ b/docs/error_code @@ -0,0 +1,30 @@ +# SUCCESS MESSAGE CODE + 00 Success Normal + 01 Success Without Write to the card + +# ERROR MESSAGE CODE TOPUP ONLINE SERVICE + 400 Bad Request Parameter or Validation Parameter Error + 401 Token Required + 402 Invalid Token + 403 Validation Data Invalid + 500 Error Catch + + + 410 MID or TID is not registered + 411 Terminal Login already exists + 412 terminal id is not valid + 413 card number is not registered + 414 reservation doesn't exist + 415 amount must be greater than 0 + 416 your card number has reached the maximum balance + 417 your card number has been limit top up for this month + 418 topup amount is different + 419 load balance doesn't exist + 420 your card number has incomplete transaction. Please unload your balance! + 421 your card number has some pending transaction. Please finished it! + 422 history doesn't exist + +# ERROR MESSAGE CODE CORE HSM + 5001 error catch HSM + 5002 failed from HSM + 5003 wrong response from card \ No newline at end of file