1
0

dummyPemko8768.js 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. const http = require('http');
  2. const server = http.createServer((req, res) => {
  3. let body = '';
  4. let hasInquiry = false;
  5. let hasPayment = true
  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-pemko-8768' && req.method === 'POST') {
  13. const xmlInquiryResponse = `<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  14. <SOAP-ENV:Body>
  15. <InquiryResponse xmlns="http://BTN-PEMDA-MAROS/">
  16. <rsp>000</rsp>
  17. <rspdesc>Success</rspdesc>
  18. <ref>24122746</ref>
  19. <data>
  20. <nop>730801241224037</nop>
  21. <nama_wp>EZRA PAWARRANGAN</nama_wp>
  22. <alamat_op>0</alamat_op>
  23. <kelurahan_op>0</kelurahan_op>
  24. <kecamatan_op>0</kecamatan_op>
  25. <tahun>0</tahun>
  26. <denda>0</denda>
  27. <status_bayar>0</status_bayar>
  28. <no_berkas>01241224037</no_berkas>
  29. <tanggal>2024-12-24</tanggal>
  30. <tagihan>9750000</tagihan>
  31. </data>
  32. </InquiryResponse>
  33. </SOAP-ENV:Body>
  34. </SOAP-ENV:Envelope>`;
  35. const xmlPaymentResponse = `<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  36. <SOAP-ENV:Body>
  37. <PaymentResponse xmlns="http://BTN-PEMDA-MAROS/">
  38. <rsp>000</rsp>
  39. <rspdesc>Success</rspdesc>
  40. <ref>24122746</ref>
  41. </PaymentResponse>
  42. </SOAP-ENV:Body>
  43. </SOAP-ENV:Envelope>`;
  44. if(hasInquiry) {
  45. res.writeHead(200, { 'Content-Type': 'text/xml; charset=ISO-8859-1' });
  46. res.end(xmlInquiryResponse);
  47. } else if (hasPayment) {
  48. res.writeHead(200, { 'Content-Type': 'text/xml; charset=ISO-8859-1' });
  49. res.end(xmlPaymentResponse);
  50. } else {
  51. res.writeHead(404, { 'Content-Type': 'text/plain' });
  52. res.end('Not found');
  53. }
  54. } else {
  55. res.writeHead(404, { 'Content-Type': 'text/plain' });
  56. res.end('Not found');
  57. }
  58. });
  59. });
  60. server.listen(3015, () => {
  61. console.log('SOAP dummy running at http://localhost:3015/dummy-pemko-8768');
  62. });