dummyspp0263.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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-ws-spp-0263' && req.method === 'POST') {
  13. const xmlInquiryResponse = `<?xml version="1.0" encoding="utf-8"?>
  14. <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">
  15. <SOAP-ENV:Body>
  16. <InquiryResponse xmlns="http://H2H-UNSRI/">
  17. <InquiryResult>
  18. <billinfo3>218230003345</billinfo3>
  19. <billinfo6>IMAM LAZIO RIANDA</billinfo6>
  20. <billinfo8>Pendidikan Sejarah</billinfo8>
  21. <billinfo9>2018 / Ganjil</billinfo9>
  22. <totalAmount>2500000</totalAmount>
  23. <billDetails>nama periode: 2018 / Ganjiltotal tagihan: 2500000\n\n</billDetails>
  24. <status>
  25. <Status>
  26. <errorCode>00</errorCode>
  27. <errorDescription>sukses</errorDescription>
  28. <isError>false</isError>
  29. </Status>
  30. </status>
  31. </InquiryResult>
  32. </InquiryResponse>
  33. </SOAP-ENV:Body>
  34. </SOAP-ENV:Envelope>`;
  35. const xmlPaymentResponse = `<?xml version="1.0" encoding="utf-8"?>
  36. <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">
  37. <SOAP-ENV:Body>
  38. <PaymentResponse xmlns="http://H2H-UNSRI/">
  39. <PaymentResult>
  40. <status>
  41. <Status>
  42. <errorCode>00</errorCode>
  43. <errorDescription>sukses</errorDescription>
  44. <isError>false</isError>
  45. </Status>
  46. </status>
  47. </PaymentResult>
  48. </PaymentResponse>
  49. </SOAP-ENV:Body>
  50. </SOAP-ENV:Envelope>`;
  51. if(hasInquiry) {
  52. res.writeHead(200, { 'Content-Type': 'text/xml; charset=ISO-8859-1' });
  53. res.end(xmlInquiryResponse);
  54. } else if (hasPayment) {
  55. res.writeHead(200, { 'Content-Type': 'text/xml; charset=ISO-8859-1' });
  56. res.end(xmlPaymentResponse);
  57. } else {
  58. res.writeHead(404, { 'Content-Type': 'text/plain' });
  59. res.end('Not found');
  60. }
  61. } else {
  62. res.writeHead(404, { 'Content-Type': 'text/plain' });
  63. res.end('Not found');
  64. }
  65. });
  66. });
  67. server.listen(3059, () => {
  68. console.log('SOAP dummy running at http://localhost:3059/dummy-ws-spp-0263');
  69. });