dummyMP7788.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 = false
  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. console.log(hasInquiry);
  13. console.log(hasPayment);
  14. console.log(req.url);
  15. console.log(req.method);
  16. if (req.url === '/dummy-ws-mp-7788' && req.method === 'POST') {
  17. const xmlInquiryResponse = `<?xml version="1.0" encoding="utf-8"?>
  18. <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">
  19. <SOAP-ENV:Body>
  20. <InquiryResponse xmlns="http://tempuri.org/">
  21. <InquiryResult>
  22. <BillDetail>
  23. <BillKey>977887746180906001</BillKey>
  24. <BillName>Rachmat Sumantri, SH.</BillName>
  25. <BillAmount>501000</BillAmount>
  26. <BillStatus>0</BillStatus>
  27. <BillExpired>2018-09-07 17:18:32</BillExpired>
  28. </BillDetail>
  29. <StatusInquiry>0</StatusInquiry>
  30. <Currency>IDR</Currency>
  31. <Info1>PAYMENT OPEN</Info1>
  32. <Info2>Panjar Biaya Perkara</Info2>
  33. <Info3>PN Jakarta Utara</Info3>
  34. </InquiryResult>
  35. </InquiryResponse>
  36. </SOAP-ENV:Body>
  37. </SOAP-ENV:Envelope>`;
  38. const xmlPaymentResponse = `<?xml version="1.0" encoding="utf-8"?>
  39. <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">
  40. <SOAP-ENV:Body>
  41. <PaymentResponse xmlns="http://tempuri.org/">
  42. <PaymentResult>
  43. <StatusPayment>
  44. <IsError>N</IsError>
  45. <ErrorCode>00</ErrorCode>
  46. <ErrorDesc>Sukses</ErrorDesc>
  47. </StatusPayment>
  48. <Info1>PAYMENT</Info1>
  49. <Info2>Mochamad Tabhanie, S.H.</Info2>
  50. <Info3>PN Surabaya</Info3>
  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(3134, () => {
  72. console.log('SOAP dummy running at http://localhost:3134/dummy-ws-mpp-778');
  73. });