dummyspp0037.js 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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-0037' && 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://unmul/">
  17. <InquiryResult>
  18. <billInfo1>2205106012</billInfo1>
  19. <billInfo2>Syabana Norhayana Istiqomah</billInfo2>
  20. <billInfo3>PENDIDIKAN JASMANI</billInfo3>
  21. <billInfo4>KEGURUAN DAN ILMU PENDIDIKAN</billInfo4>
  22. <billInfo5></billInfo5>
  23. <billdetail>
  24. <billDetails>
  25. <billAmount>2000000</billAmount>
  26. <billCode></billCode>
  27. <billName>SPP/Uang Kuliah</billName>
  28. <billShortName>SPP/Uang Kuliah</billShortName>
  29. <reference1></reference1>
  30. <reference2></reference2>
  31. </billDetails>
  32. </billdetail>
  33. <ErrorCode>00</ErrorCode>
  34. <ErrorDesc>Sukses</ErrorDesc>
  35. </InquiryResult>
  36. </InquiryResponse>
  37. </SOAP-ENV:Body>
  38. </SOAP-ENV:Envelope>`;
  39. const xmlPaymentResponse = `<?xml version="1.0" encoding="utf-8"?>
  40. <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">
  41. <SOAP-ENV:Body>
  42. <PaymentResponse xmlns="http://unmul/">
  43. <PaymentResult>
  44. <billInfo1></billInfo1>
  45. <billInfo2></billInfo2>
  46. <billInfo3></billInfo3>
  47. <billInfo4></billInfo4>
  48. <ErrorCode>01</ErrorCode>
  49. <ErrorDesc>TestFail</ErrorDesc>
  50. <tes>0</tes>
  51. </PaymentResult>
  52. </PaymentResponse>
  53. </SOAP-ENV:Body>
  54. </SOAP-ENV:Envelope>`;
  55. if(hasInquiry) {
  56. res.writeHead(200, { 'Content-Type': 'text/xml; charset=ISO-8859-1' });
  57. res.end(xmlInquiryResponse);
  58. } else if (hasPayment) {
  59. res.writeHead(200, { 'Content-Type': 'text/xml; charset=ISO-8859-1' });
  60. res.end(xmlPaymentResponse);
  61. } else {
  62. res.writeHead(404, { 'Content-Type': 'text/plain' });
  63. res.end('Not found');
  64. }
  65. } else {
  66. res.writeHead(404, { 'Content-Type': 'text/plain' });
  67. res.end('Not found');
  68. }
  69. });
  70. });
  71. server.listen(3019, () => {
  72. console.log('SOAP dummy running at http://localhost:3019/dummy-ws-spp-0037');
  73. });