dummyBPJSTK.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. const regeXbillkey1 = /<NS1:billkey1>(.*?)<\/NS1:billkey1>/;
  13. const regeXbillkey2 = /<NS1:billkey2>(.*?)<\/NS1:billkey2>/;
  14. const regeXbillkey3 = /<NS1:billkey3>(.*?)<\/NS1:billkey3>/;
  15. const regeXbillkey4 = /<NS1:billkey4>(.*?)<\/NS1:billkey4>/;
  16. const regeXbillkey5 = /<NS1:billkey5>(.*?)<\/NS1:billkey5>/;
  17. const regeXbillkey6 = /<NS1:billkey6>(.*?)<\/NS1:billkey6>/;
  18. const regeXbillkey7 = /<NS1:billkey7>(.*?)<\/NS1:billkey7>/;
  19. const regeXbillkey8 = /<NS1:billkey8>(.*?)<\/NS1:billkey8>/;
  20. const regeXbillkey9 = /<NS1:billkey9>(.*?)<\/NS1:billkey9>/;
  21. const regeXbillkey10 = /<NS1:billkey10>(.*?)<\/NS1:billkey10>/;
  22. const regeXterminalID = /<NS1:terminalID>(.*?)<\/NS1:terminalID>/;
  23. const regeXidTransaksi = /<NS1:idTransaksi>(.*?)<\/NS1:idTransaksi>/;
  24. const regeXtransDateTime = /<NS1:transDateTime>(.*?)<\/NS1:transDateTime>/;
  25. const matcHbillkey1 = body.match(regeXbillkey1);
  26. const matcHbillkey2 = body.match(regeXbillkey2);
  27. const matcHbillkey3 = body.match(regeXbillkey3);
  28. const matcHbillkey4 = body.match(regeXbillkey4);
  29. const matcHbillkey5 = body.match(regeXbillkey5);
  30. const matcHbillkey6 = body.match(regeXbillkey6);
  31. const matcHbillkey7 = body.match(regeXbillkey7);
  32. const matcHbillkey8 = body.match(regeXbillkey8);
  33. const matcHbillkey9 = body.match(regeXbillkey9);
  34. const matcHbillkey10 = body.match(regeXbillkey10);
  35. const matcHterminalID = body.match(regeXterminalID);
  36. const matcHidTransaksi = body.match(regeXidTransaksi);
  37. const matcHtransDateTime = body.match(regeXtransDateTime);
  38. const billkey1 = matcHbillkey1 ? matcHbillkey1[1] : null;
  39. const billkey2 = matcHbillkey2 ? matcHbillkey2[1] : null;
  40. const billkey3 = matcHbillkey3 ? matcHbillkey3[1] : null;
  41. const billkey4 = matcHbillkey4 ? matcHbillkey4[1] : null;
  42. const billkey5 = matcHbillkey5 ? matcHbillkey5[1] : null;
  43. const billkey6 = matcHbillkey6 ? matcHbillkey6[1] : null;
  44. const billkey7 = matcHbillkey7 ? matcHbillkey7[1] : null;
  45. const billkey8 = matcHbillkey8 ? matcHbillkey8[1] : null;
  46. const billkey9 = matcHbillkey9 ? matcHbillkey9[1] : null;
  47. const billkey10 = matcHbillkey10 ? matcHbillkey10[1] : null;
  48. const terminalID = matcHterminalID ? matcHterminalID[1] : null;
  49. const idTransaksi = matcHidTransaksi ? matcHidTransaksi[1] : null;
  50. const transDateTime = matcHtransDateTime ? matcHtransDateTime[1] : null;
  51. let errCode = `<errorCode>00</errorCode>`
  52. let errMessage = `<errorDescription>success</errorDescription>`
  53. if (billkey3 == '88888888') {
  54. errCode = `<errorCode>01</errorCode>`
  55. errMessage = `<errorDescription>Invalid virtual account number.</errorDescription>`
  56. }
  57. if (req.url === '/dummy-bpjstk' && req.method === 'POST') {
  58. const xmlInquiryResponse = `<?xml version="1.0" encoding="utf-8"?>
  59. <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
  60. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  61. xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  62. <soap:Body>
  63. <InquiryResponse xmlns="http://BTN-BPJSTK/">
  64. <InquiryResult>
  65. <billinfo1>`+billkey1+`</billinfo1>
  66. <billinfo2>`+billkey2+`</billinfo2>
  67. <billinfo3>`+billkey3+`</billinfo3>
  68. <billinfo4>`+billkey4+`</billinfo4>
  69. <billinfo5/>
  70. <billinfo6>UIN SYARIF HIDAYATULLAH JAKARTA - PKWT</billinfo6>
  71. <billinfo7>00012/2025</billinfo7>
  72. <billinfo8>23199061</billinfo8>
  73. <billinfo9>0</billinfo9>
  74. <billinfo10>931206</billinfo10>
  75. <billinfo11>JHT0751756#JKK0751756#JKM0751756</billinfo11>
  76. <billinfo12> CMS11756120496159990751756</billinfo12>
  77. <addvalues>{"KODE_IURAN":"423199061000"}</addvalues>
  78. <totalAmount>931206</totalAmount>
  79. <billDetails>
  80. <billName>JHTJKKJKMJPKJPN</billName>
  81. <billAmount>850620 35815 44771 0 0 </billAmount>
  82. </billDetails>
  83. <status>
  84. <Status>
  85. <isError>false</isError>
  86. <errorCode>00</errorCode>
  87. <errorDescription>Sukses</errorDescription>
  88. </Status>
  89. </status>
  90. </InquiryResult>
  91. </InquiryResponse>
  92. </soap:Body>
  93. </soap:Envelope>`;
  94. const xmlPaymentResponse = `<?xml version="1.0" encoding="utf-8"?>
  95. <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
  96. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  97. xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  98. <soap:Body>
  99. <PaymentResponse xmlns="http://BTN-BPJSTK/">
  100. <PaymentResult>
  101. <billinfo1/>
  102. <billinfo2/>
  103. <status>
  104. <Status>
  105. <isError>false</isError>`+
  106. errCode+
  107. errMessage+`
  108. </Status>
  109. </status>
  110. </PaymentResult>
  111. </PaymentResponse>
  112. </soap:Body>
  113. </soap:Envelope>`;
  114. if (hasInquiry) {
  115. res.writeHead(200, { 'Content-Type': 'text/xml; charset=utf-8' });
  116. res.end(xmlInquiryResponse);
  117. } else if (hasPayment) {
  118. res.writeHead(200, { 'Content-Type': 'text/xml; charset=utf-8' });
  119. res.end(xmlPaymentResponse);
  120. } else {
  121. res.writeHead(400, { 'Content-Type': 'text/plain' });
  122. res.end('Bad Request: No Inquiry or Payment action found');
  123. }
  124. } else {
  125. res.writeHead(404, { 'Content-Type': 'text/plain' });
  126. res.end('Not found');
  127. }
  128. });
  129. });
  130. server.listen(3094, () => {
  131. console.log('SOAP dummy BPJS Ketenagakerjaan running at http://localhost:3017/dummy-bpjstk');
  132. });