dummyPemko5464.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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-5464' && 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://tempuri.org/">
  16. <rsp>000</rsp>
  17. <rspdesc>Request Data Berhasil</rspdesc>
  18. <data>
  19. <total_tagihan>500000</total_tagihan>
  20. <nama_wp>RALIN MS GUMAY</nama_wp>
  21. <tagihan>450000</tagihan>
  22. <denda>10000</denda>
  23. </data>
  24. </InquiryResponse>
  25. </SOAP-ENV:Body>
  26. </SOAP-ENV:Envelope>`;
  27. 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">
  28. <SOAP-ENV:Body>
  29. <PaymentResponse xmlns="http://tempuri.org/">
  30. <rsp>000</rsp>
  31. <rspdesc>Request Data Berhasil</rspdesc>
  32. </PaymentResponse>
  33. </SOAP-ENV:Body>
  34. </SOAP-ENV:Envelope>`;
  35. if(hasInquiry) {
  36. res.writeHead(200, { 'Content-Type': 'text/xml; charset=ISO-8859-1' });
  37. res.end(xmlInquiryResponse);
  38. } else if (hasPayment) {
  39. res.writeHead(200, { 'Content-Type': 'text/xml; charset=ISO-8859-1' });
  40. res.end(xmlPaymentResponse);
  41. } else {
  42. res.writeHead(404, { 'Content-Type': 'text/plain' });
  43. res.end('Not found');
  44. }
  45. } else {
  46. res.writeHead(404, { 'Content-Type': 'text/plain' });
  47. res.end('Not found');
  48. }
  49. });
  50. });
  51. server.listen(3007, () => {
  52. console.log('SOAP dummy running at http://localhost:3007/dummy-pemko-5464');
  53. });