dummyBPJSKes.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. const http = require('http');
  2. const server = http.createServer((req, res) => {
  3. let body = '';
  4. let hasInquiry = false;
  5. let hasPayment = false;
  6. req.on('data', (chunk) => {
  7. body += chunk;
  8. });
  9. req.on('end', () => {
  10. hasInquiry = /<(\w+:)?Inquiry\b/.test(body);
  11. hasPayment = /<(\w+:)?Payment\b/.test(body);
  12. if (req.url === '/dummy-bpjskes' && req.method === 'POST') {
  13. const xmlInquiryResponse = `<?xml version="1.0" encoding="utf-8"?>
  14. <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
  15. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  16. xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  17. <soap:Body>
  18. <InquiryResponse xmlns="http://BTN-BPJSKES/">
  19. <InquiryResult>
  20. <billinfo1>BPJSKES</billinfo1>
  21. <billinfo2>COR</billinfo2>
  22. <billinfo3>8888890001100299</billinfo3>
  23. <billinfo4>COR</billinfo4>
  24. <billinfo5>1</billinfo5>
  25. <billinfo6>1-H A AZIZ MACHMUD FA</billinfo6>
  26. <billinfo7>PANGKAL PINANG</billinfo7>
  27. <billinfo8>4C1E89221DDC2017</billinfo8>
  28. <billinfo9/>
  29. <billinfo10/>
  30. <billinfo11>0602</billinfo11>
  31. <billinfo12/>
  32. <totalAmount>13023415</totalAmount>
  33. <terminalID>I99</terminalID>
  34. <idTransaksi>88888900011002990099991058002520260421</idTransaksi>
  35. <transDateTime>2026-04-21 11:13:10</transDateTime>
  36. <billDetails/>
  37. <status>
  38. <Status>
  39. <isError>false</isError>
  40. <errorCode>00</errorCode>
  41. <errorDescription>success</errorDescription>
  42. </Status>
  43. </status>
  44. </InquiryResult>
  45. </InquiryResponse>
  46. </soap:Body>
  47. </soap:Envelope>`;
  48. const xmlPaymentResponse = `<?xml version="1.0" encoding="utf-8"?>
  49. <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
  50. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  51. xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  52. <soap:Body>
  53. <PaymentResponse xmlns="http://BTN-BPJSKES/">
  54. <PaymentResult>
  55. <billinfo1/>
  56. <billinfo2/>
  57. <billinfo3/>
  58. <billinfo4/>
  59. <billinfo5/>
  60. <billinfo6/>
  61. <billinfo7/>
  62. <billinfo8/>
  63. <billinfo9/>
  64. <billinfo10/>
  65. <billinfo11/>
  66. <billinfo12/>
  67. <totalAmount>0</totalAmount>
  68. <terminalID/>
  69. <idTransaksi/>
  70. <transDateTime/>
  71. <billDetails/>
  72. <status>
  73. <Status>
  74. <isError>false</isError>
  75. <errorCode>00</errorCode>
  76. <errorDescription>success</errorDescription>
  77. </Status>
  78. </status>
  79. </PaymentResult>
  80. </PaymentResponse>
  81. </soap:Body>
  82. </soap:Envelope>`;
  83. if (hasInquiry) {
  84. res.writeHead(200, { 'Content-Type': 'text/xml; charset=utf-8' });
  85. res.end(xmlInquiryResponse);
  86. } else if (hasPayment) {
  87. res.writeHead(200, { 'Content-Type': 'text/xml; charset=utf-8' });
  88. res.end(xmlPaymentResponse);
  89. } else {
  90. res.writeHead(400, { 'Content-Type': 'text/plain' });
  91. res.end('Bad Request: No Inquiry or Payment action found');
  92. }
  93. } else {
  94. res.writeHead(404, { 'Content-Type': 'text/plain' });
  95. res.end('Not found');
  96. }
  97. });
  98. });
  99. server.listen(3093, () => {
  100. console.log('SOAP dummy BPJS Kesehatan running at http://localhost:3016/dummy-bpjskes');
  101. });