const http = require('http'); const PORT = 13370; function getNanosecondTimestamp() { const isoString = new Date().toISOString(); const base = isoString.slice(0, -1); const nanoseconds = (process.hrtime.bigint() % 1000000n).toString().padStart(6, '0'); return `${base}${nanoseconds}Z`; } const server = http.createServer((req, res) => { if (req.method === 'POST') { let body = ''; req.on('data', chunk => { body += chunk.toString(); }); req.on('end', () => { try { const parsedBody = JSON.parse(body); const customMessage = { AuthToken: "Token Valid", OriginalMessageRefId: parsedBody.OriginalMessageRefId, RequestTime: parsedBody.RequestTime, ResponseCode: "0000", ResponseCodeDesc: "Approve - Without Check Core", ResponseTime: getNanosecondTimestamp(), TransactionRefId: parsedBody.transactionRefId, amount: "", ref: "", rsp: "", rspdesc: "", transactionAmount: parsedBody.transactionAmount, transactionDate: parsedBody.transactionDate, transactionTime: parsedBody.transactionTime, // status: "success", // message: parsedBody.customField, // data: { // id: 1, // active: true // } }; res.writeHead(200, { 'Content-Type': 'application/json' }); res.end(JSON.stringify(customMessage)); } catch (error) { res.writeHead(400, { 'Content-Type': 'application/json' }); res.end(JSON.stringify({ error: "Invalid JSON" })); } }); } else { res.writeHead(405, { 'Content-Type': 'application/json' }); res.end(JSON.stringify({ error: "Only POST allowed" })); } }); server.listen(PORT, () => { console.log(`Server running at http://localhost:${PORT}/`); }); // const customMessage = { // AuthToken: "Token Valid", // OriginalMessageRefId: "B10105001179", // RequestTime: "2026-05-29T17:05:30.307+07:00", // ResponseCode: "0000", // ResponseCodeDesc: "Approve - Without Check Core", // ResponseTime: "2026-05-29T10:05:32.781824276Z", // TransactionRefId: "5001179", // amount: "", // ref: "", // rsp: "", // rspdesc: "", // transactionAmount: "10000000", // transactionDate: "2026-05-29", // transactionTime: "17:05:32", // }; // const server = http.createServer((req, res) => { // res.writeHead(200, { 'Content-Type': 'application/octet-stream' }); // res.end(JSON.stringify(customMessage)); // }); // server.listen(PORT, () => { // console.log(`Server running at http://localhost:${PORT}/`); // });