dummysmmptn.js 2.9 KB

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