dummyBPJSKes.js 5.7 KB

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