dummyFDS.js 2.6 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. req.on('data', chunk => {
  13. body += chunk.toString();
  14. });
  15. req.on('end', () => {
  16. try {
  17. const parsedBody = JSON.parse(body);
  18. const customMessage = {
  19. AuthToken: "Token Valid",
  20. OriginalMessageRefId: parsedBody.OriginalMessageRefId,
  21. RequestTime: parsedBody.RequestTime,
  22. ResponseCode: "0000",
  23. ResponseCodeDesc: "Approve - Without Check Core",
  24. ResponseTime: getNanosecondTimestamp(),
  25. TransactionRefId: parsedBody.transactionRefId,
  26. amount: "",
  27. ref: "",
  28. rsp: "",
  29. rspdesc: "",
  30. transactionAmount: parsedBody.transactionAmount,
  31. transactionDate: parsedBody.transactionDate,
  32. transactionTime: parsedBody.transactionTime,
  33. // status: "success",
  34. // message: parsedBody.customField,
  35. // data: {
  36. // id: 1,
  37. // active: true
  38. // }
  39. };
  40. res.writeHead(200, { 'Content-Type': 'application/json' });
  41. res.end(JSON.stringify(customMessage));
  42. } catch (error) {
  43. res.writeHead(400, { 'Content-Type': 'application/json' });
  44. res.end(JSON.stringify({ error: "Invalid JSON" }));
  45. }
  46. });
  47. } else {
  48. res.writeHead(405, { 'Content-Type': 'application/json' });
  49. res.end(JSON.stringify({ error: "Only POST allowed" }));
  50. }
  51. });
  52. server.listen(PORT, () => {
  53. console.log(`Server running at http://localhost:${PORT}/`);
  54. });
  55. // const customMessage = {
  56. // AuthToken: "Token Valid",
  57. // OriginalMessageRefId: "B10105001179",
  58. // RequestTime: "2026-05-29T17:05:30.307+07:00",
  59. // ResponseCode: "0000",
  60. // ResponseCodeDesc: "Approve - Without Check Core",
  61. // ResponseTime: "2026-05-29T10:05:32.781824276Z",
  62. // TransactionRefId: "5001179",
  63. // amount: "",
  64. // ref: "",
  65. // rsp: "",
  66. // rspdesc: "",
  67. // transactionAmount: "10000000",
  68. // transactionDate: "2026-05-29",
  69. // transactionTime: "17:05:32",
  70. // };
  71. // const server = http.createServer((req, res) => {
  72. // res.writeHead(200, { 'Content-Type': 'application/octet-stream' });
  73. // res.end(JSON.stringify(customMessage));
  74. // });
  75. // server.listen(PORT, () => {
  76. // console.log(`Server running at http://localhost:${PORT}/`);
  77. // });