dummyFDS.js 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. const http = require('http');
  2. const PORT = 13370;
  3. function getNanosecondTimestamp() {
  4. const isoString = new Date().toISOString();
  5. const base = isoString.slice(0, -1);
  6. const nanoseconds = (process.hrtime.bigint() % 1000000n).toString().padStart(6, '0');
  7. return `${base}${nanoseconds}Z`;
  8. }
  9. const server = http.createServer((req, res) => {
  10. if (req.method === 'POST') {
  11. let body = '';
  12. const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms));
  13. req.on('data', chunk => {
  14. body += chunk.toString();
  15. });
  16. req.on('end', async () => {
  17. try {
  18. const parsedBody = JSON.parse(body);
  19. const customMessage = {
  20. AuthToken: "Token Valid",
  21. OriginalMessageRefId: parsedBody.OriginalMessageRefId,
  22. RequestTime: parsedBody.RequestTime,
  23. ResponseCode: "0000",
  24. ResponseCodeDesc: "Approve - Without Check Core",
  25. ResponseTime: getNanosecondTimestamp(),
  26. TransactionRefId: parsedBody.transactionRefId,
  27. amount: "",
  28. ref: "",
  29. rsp: "",
  30. rspdesc: "",
  31. transactionAmount: parsedBody.transactionAmount,
  32. transactionDate: parsedBody.transactionDate,
  33. transactionTime: parsedBody.transactionTime,
  34. // status: "success",
  35. // message: parsedBody.customField,
  36. // data: {
  37. // id: 1,
  38. // active: true
  39. // }
  40. };
  41. res.writeHead(200, { 'Content-Type': 'application/json' });
  42. res.end(JSON.stringify(customMessage));
  43. } catch (error) {
  44. res.writeHead(400, { 'Content-Type': 'application/json' });
  45. res.end(JSON.stringify({ error: "Invalid JSON" }));
  46. console.log(error);
  47. }
  48. });
  49. } else {
  50. res.writeHead(405, { 'Content-Type': 'application/json' });
  51. res.end(JSON.stringify({ error: "Only POST allowed" }));
  52. }
  53. });
  54. server.listen(PORT, () => {
  55. console.log(`Server running at http://localhost:${PORT}/`);
  56. });
  57. // const customMessage = {
  58. // AuthToken: "Token Valid",
  59. // OriginalMessageRefId: "B10105001179",
  60. // RequestTime: "2026-05-29T17:05:30.307+07:00",
  61. // ResponseCode: "0000",
  62. // ResponseCodeDesc: "Approve - Without Check Core",
  63. // ResponseTime: "2026-05-29T10:05:32.781824276Z",
  64. // TransactionRefId: "5001179",
  65. // amount: "",
  66. // ref: "",
  67. // rsp: "",
  68. // rspdesc: "",
  69. // transactionAmount: "10000000",
  70. // transactionDate: "2026-05-29",
  71. // transactionTime: "17:05:32",
  72. // };
  73. // const server = http.createServer((req, res) => {
  74. // res.writeHead(200, { 'Content-Type': 'application/octet-stream' });
  75. // res.end(JSON.stringify(customMessage));
  76. // });
  77. // server.listen(PORT, () => {
  78. // console.log(`Server running at http://localhost:${PORT}/`);
  79. // });