dummyBPJSTK.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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-bpjstk' && 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-BPJSTK/">
  19. <InquiryResult>
  20. <billinfo1>BPJSTK</billinfo1>
  21. <billinfo2>BPJSTK</billinfo2>
  22. <billinfo3>423199061000</billinfo3>
  23. <billinfo4>N</billinfo4>
  24. <billinfo5/>
  25. <billinfo6>UIN SYARIF HIDAYATULLAH JAKARTA - PKWT</billinfo6>
  26. <billinfo7>00012/2025</billinfo7>
  27. <billinfo8>23199061</billinfo8>
  28. <billinfo9>0</billinfo9>
  29. <billinfo10>931206</billinfo10>
  30. <billinfo11>JHT0751756#JKK0751756#JKM0751756</billinfo11>
  31. <billinfo12> CMS11756120496159990751756</billinfo12>
  32. <addvalues>{"KODE_IURAN":"423199061000"}</addvalues>
  33. <totalAmount>931206</totalAmount>
  34. <billDetails>
  35. <billName>JHTJKKJKMJPKJPN</billName>
  36. <billAmount>850620 35815 44771 0 0 </billAmount>
  37. </billDetails>
  38. <status>
  39. <Status>
  40. <isError>false</isError>
  41. <errorCode>00</errorCode>
  42. <errorDescription>Sukses</errorDescription>
  43. </Status>
  44. </status>
  45. </InquiryResult>
  46. </InquiryResponse>
  47. </soap:Body>
  48. </soap:Envelope>`;
  49. const xmlPaymentResponse = `<?xml version="1.0" encoding="utf-8"?>
  50. <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
  51. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  52. xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  53. <soap:Body>
  54. <PaymentResponse xmlns="http://BTN-BPJSTK/">
  55. <PaymentResult>
  56. <billinfo1/>
  57. <billinfo2/>
  58. <status>
  59. <Status>
  60. <isError>false</isError>
  61. <errorCode>00</errorCode>
  62. <errorDescription>Sukses</errorDescription>
  63. </Status>
  64. </status>
  65. </PaymentResult>
  66. </PaymentResponse>
  67. </soap:Body>
  68. </soap:Envelope>`;
  69. if (hasInquiry) {
  70. res.writeHead(200, { 'Content-Type': 'text/xml; charset=utf-8' });
  71. res.end(xmlInquiryResponse);
  72. } else if (hasPayment) {
  73. res.writeHead(200, { 'Content-Type': 'text/xml; charset=utf-8' });
  74. res.end(xmlPaymentResponse);
  75. } else {
  76. res.writeHead(400, { 'Content-Type': 'text/plain' });
  77. res.end('Bad Request: No Inquiry or Payment action found');
  78. }
  79. } else {
  80. res.writeHead(404, { 'Content-Type': 'text/plain' });
  81. res.end('Not found');
  82. }
  83. });
  84. });
  85. server.listen(3094, () => {
  86. console.log('SOAP dummy BPJS Ketenagakerjaan running at http://localhost:3017/dummy-bpjstk');
  87. });