dummyPemko4006.js 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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-4006' && 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-PEMKOSEMARANG/">
  16. <nama_wp>RALIN MS GUMAY</nama_wp>
  17. <total_bayar>484416</total_bayar>
  18. <tahun_terakhir>2025</tahun_terakhir>
  19. <alamat_op>JL MERAWAN</alamat_op>
  20. <kelurahan_op>SAWAH LEBAR BARU</kelurahan_op>
  21. <jumlah_pokok>484416</jumlah_pokok>
  22. <status>
  23. <errorCode>000</errorCode>
  24. <statusDescription>Request Data Berhasil</statusDescription>
  25. </status>
  26. </InquiryResponse>
  27. </SOAP-ENV:Body>
  28. </SOAP-ENV:Envelope>`;
  29. 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">
  30. <SOAP-ENV:Body>
  31. <Payment_response xmlns="http://BTN-PEMKOSEMARANG/">
  32. <bankID>603</bankID>
  33. <kecamatan_op>MIJEN</kecamatan_op>
  34. <nama_wp>PT. SARANA PRIMA PERKASA</nama_wp>
  35. <nop>337415001100804310</nop>
  36. <status>
  37. <error>true</error>
  38. <errorCode>00</errorCode>
  39. <statusDescription>Sukses</statusDescription>
  40. </status>
  41. <totalPaymentAmount>154401</totalPaymentAmount>
  42. <transactionID>ESB453602505</transactionID>
  43. <trxDateTime>15-01-2026 15:52:27</trxDateTime>
  44. </Payment_response>
  45. </SOAP-ENV:Body>
  46. </SOAP-ENV:Envelope>`;
  47. if(hasInquiry) {
  48. res.writeHead(200, { 'Content-Type': 'text/xml; charset=ISO-8859-1' });
  49. res.end(xmlInquiryResponse);
  50. } else if (hasPayment) {
  51. res.writeHead(200, { 'Content-Type': 'text/xml; charset=ISO-8859-1' });
  52. res.end(xmlPaymentResponse);
  53. } else {
  54. res.writeHead(404, { 'Content-Type': 'text/plain' });
  55. res.end('Not found');
  56. }
  57. } else {
  58. res.writeHead(404, { 'Content-Type': 'text/plain' });
  59. res.end('Not found');
  60. }
  61. });
  62. });
  63. server.listen(3006, () => {
  64. console.log('SOAP dummy running at http://localhost:3006/dummy-pemko-4006');
  65. });