dummySPP0001.js 3.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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-0001' && 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="H2HUGM/btn/">
  17. <InquiryResult>
  18. <currency>360</currency>
  19. <billInfo1>25/561563/EK/25744</billInfo1>
  20. <billInfo2>Axel Hernanda</billInfo2>
  21. <billInfo3>S1 AKUNTANSI</billInfo3>
  22. <billInfo4>SPP:9200</billInfo4>
  23. <billInfo5>Periode GENAP 2025</billInfo5>
  24. <billInfo6>3276061605070002</billInfo6>
  25. <billReff>UKT :Rp. 9,200,000.00</billReff>
  26. <totalBill>9200000</totalBill>
  27. <billDetails>
  28. <billDetails>
  29. <billCode>01</billCode>
  30. <billName>UKT</billName>
  31. <billShortName>UKT</billShortName>
  32. <billAmount>9200000</billAmount>
  33. <reference1></reference1>
  34. <reference2></reference2>
  35. <reference3></reference3>
  36. </billDetails>
  37. </billDetails>
  38. <status>
  39. <Status>
  40. <isError>False</isError>
  41. <errorCode>00</errorCode>
  42. <statusDescription>Sukses</statusDescription>
  43. </Status>
  44. </status>
  45. </InquiryResult>
  46. </InquiryResponse>
  47. </SOAP-ENV:Body>
  48. </SOAP-ENV:Envelope>`;
  49. const xmlPaymentResponse = `<?xml version="1.0" encoding="utf-8"?>
  50. <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">
  51. <SOAP-ENV:Body>
  52. <PaymentResponse xmlns="H2HUGM/btn/">
  53. <PaymentResult>
  54. <billInfo1>25/561563/EK/25744</billInfo1>
  55. <billInfo2>Axel Hernanda</billInfo2>
  56. <billInfo3>S1 AKUNTANSI</billInfo3>
  57. <billInfo4>SPP:9200</billInfo4>
  58. <billInfo5>Periode GENAP 2025</billInfo5>
  59. <status>
  60. <Status>
  61. <isError>False</isError>
  62. <errorCode>01</errorCode>
  63. <statusDescription>Invalid Data</statusDescription>
  64. </Status>
  65. </status>
  66. </PaymentResult>
  67. </PaymentResponse>
  68. </SOAP-ENV:Body>
  69. </SOAP-ENV:Envelope>`;
  70. if(hasInquiry) {
  71. res.writeHead(200, { 'Content-Type': 'text/xml; charset=ISO-8859-1' });
  72. res.end(xmlInquiryResponse);
  73. } else if (hasPayment) {
  74. res.writeHead(200, { 'Content-Type': 'text/xml; charset=ISO-8859-1' });
  75. res.end(xmlPaymentResponse);
  76. } else {
  77. res.writeHead(404, { 'Content-Type': 'text/plain' });
  78. res.end('Not found');
  79. }
  80. } else {
  81. res.writeHead(404, { 'Content-Type': 'text/plain' });
  82. res.end('Not found');
  83. }
  84. });
  85. });
  86. server.listen(3008, () => {
  87. console.log('SOAP dummy running at http://localhost:3008/dummy-ws-spp-0001');
  88. });