dummysmmptn.js 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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-smmptn' && 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://BTN-SMM/">
  17. <rsp>000</rsp>
  18. <rspdesc>Transaction success</rspdesc>
  19. <trxID>45</trxID>
  20. <idTagihan>953016738727</idTagihan>
  21. <namaMhs>HADI NUR CAHAYA</namaMhs>
  22. <fakultas>UTBK SMMPTN-BARAT</fakultas>
  23. <billCode>00</billCode>
  24. <billName>BIAYA PENDAFTARAN</billName>
  25. <billShortName>SMMPTN-BARAT 2026</billShortName>
  26. <billAmount>375000</billAmount>
  27. <totalTagihan>375000</totalTagihan>
  28. <reference1>0</reference1>
  29. <reference2>0</reference2>
  30. <reference3>0</reference3>
  31. </InquiryResponse>
  32. </SOAP-ENV:Body>
  33. </SOAP-ENV:Envelope>`;
  34. const xmlPaymentResponse = `<?xml version="1.0" encoding="utf-8"?>
  35. <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">
  36. <SOAP-ENV:Body>
  37. <PaymentResponse xmlns="http://BTN-SMM/">
  38. <rsp>000</rsp>
  39. <rspdesc>Transaction success</rspdesc>
  40. <trxID>47</trxID>
  41. <idTagihan>953016738727</idTagihan>
  42. <namaMhs>HADI NUR CAHAYA</namaMhs>
  43. <fakultas>UTBK SMMPTN-BARAT</fakultas>
  44. <billName>BIAYA PENDAFTARAN</billName>
  45. <billShortName>SMMPTN-BARAT 2026</billShortName>
  46. </PaymentResponse>
  47. </SOAP-ENV:Body>
  48. </SOAP-ENV:Envelope>`;
  49. if(hasInquiry) {
  50. res.writeHead(200, { 'Content-Type': 'text/xml; charset=ISO-8859-1' });
  51. res.end(xmlInquiryResponse);
  52. } else if (hasPayment) {
  53. res.writeHead(200, { 'Content-Type': 'text/xml; charset=ISO-8859-1' });
  54. res.end(xmlPaymentResponse);
  55. } else {
  56. res.writeHead(404, { 'Content-Type': 'text/plain' });
  57. res.end('Not found');
  58. }
  59. } else {
  60. res.writeHead(404, { 'Content-Type': 'text/plain' });
  61. res.end('Not found');
  62. }
  63. });
  64. });
  65. server.listen(3070, () => {
  66. console.log('SOAP dummy running at http://localhost:3070/dummy-smmptn');
  67. });