dummyBPJSTKINDV.js 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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-bpjstkindv' && 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-BPJSTKINDV/">
  64. <InquiryResult>
  65. <billinfo1>`+billkey3+`</billinfo1>
  66. <billinfo2>`+billkey4+`</billinfo2>
  67. <billinfo3>MARLON PORSISA</billinfo3>
  68. <billinfo4>26-08-2020</billinfo4>
  69. <billinfo5>02-01-2026</billinfo5>
  70. <billinfo6/>
  71. <billinfo7>36800</billinfo7>
  72. <billinfo8>0.00</billinfo8>
  73. <billinfo9>0.00</billinfo9>
  74. <billinfo10>20000</billinfo10>
  75. <billinfo11>6800</billinfo11>
  76. <billinfo12>10000</billinfo12>
  77. <billinfo13>0</billinfo13>
  78. <billinfo14>7172021211910002#TLR260120000150</billinfo14>
  79. <billinfo15>00136900000087</billinfo15>
  80. <billinfo16>N</billinfo16>
  81. <billinfo17>20260120133155</billinfo17>
  82. <billinfo18>T00#JKK,JKM,JHT</billinfo18>
  83. <billinfo19/>
  84. <billinfo20/>
  85. <totalAmount>36800</totalAmount>
  86. <billDetails/>
  87. <status>
  88. <Status>
  89. <isError>false</isError>
  90. <errorCode>00</errorCode>
  91. <errorDescription>Sukses</errorDescription>
  92. </Status>
  93. </status>
  94. </InquiryResult>
  95. </InquiryResponse>
  96. </soap:Body>
  97. </soap:Envelope>`;
  98. const xmlPaymentResponse = `<?xml version="1.0" encoding="utf-8"?>
  99. <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
  100. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  101. xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  102. <soap:Body>
  103. <PaymentResponse xmlns="http://BTN-BPJSTKINDV/">
  104. <PaymentResult>
  105. <billinfo1>3275121503750001</billinfo1>
  106. <billinfo2>1</billinfo2>
  107. <billinfo3/>
  108. <billinfo4/>
  109. <billinfo5/>
  110. <billinfo6>925126557881</billinfo6>
  111. <billinfo7>0</billinfo7>
  112. <billinfo8>0</billinfo8>
  113. <billinfo9>0</billinfo9>
  114. <billinfo10>0</billinfo10>
  115. <billinfo11>0</billinfo11>
  116. <billinfo12>0</billinfo12>
  117. <billinfo13>0</billinfo13>
  118. <billinfo14>3275121503750001#3275121503750001#MBK251204000152</billinfo14>
  119. <billinfo15>30000100392680</billinfo15>
  120. <billinfo16>N051120250401202620251204110059</billinfo16>
  121. <billinfo17>20251204110109</billinfo17>
  122. <billinfo18>#</billinfo18>
  123. <billinfo19/>
  124. <billinfo20/>
  125. <totalAmount>0</totalAmount>
  126. <billDetails/>
  127. <status>
  128. <Status>
  129. <isError>false</isError>`+
  130. errCode+
  131. errMessage+`
  132. </Status>
  133. </status>
  134. </PaymentResult>
  135. </PaymentResponse>
  136. </soap:Body>
  137. </soap:Envelope>`;
  138. if (hasInquiry) {
  139. res.writeHead(200, { 'Content-Type': 'text/xml; charset=utf-8' });
  140. res.end(xmlInquiryResponse);
  141. } else if (hasPayment) {
  142. res.writeHead(200, { 'Content-Type': 'text/xml; charset=utf-8' });
  143. res.end(xmlPaymentResponse);
  144. } else {
  145. res.writeHead(400, { 'Content-Type': 'text/plain' });
  146. res.end('Bad Request: No Inquiry or Payment action found');
  147. }
  148. } else {
  149. res.writeHead(404, { 'Content-Type': 'text/plain' });
  150. res.end('Not found');
  151. }
  152. });
  153. });
  154. server.listen(3095, () => {
  155. console.log('SOAP dummy BPJS TK Individual running at http://localhost:3095/dummy-bpjstkindv');
  156. });