dummyPemko4001.js 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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-pemko-4001' && req.method === 'POST') {
  13. const xmlInquiryResponse = `<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">
  14. <SOAP-ENV:Body>
  15. <InquiryResponse xmlns="http://H2HPEMKOT_BATAM/">
  16. <Response>00</Response>
  17. <Message>Sukses</Message>
  18. <transaction_id>201806211148204973</transaction_id>
  19. <NamaWP>PT GRIYA HIJAU LESTARI</NamaWP>
  20. <Jumlah_pokok>302818</Jumlah_pokok>
  21. <Jumlah_denda>0</Jumlah_denda>
  22. <JumlahBayar>302818</JumlahBayar>
  23. <TanggalBooking></TanggalBooking>
  24. <TanggalExpired></TanggalExpired>
  25. </InquiryResponse>
  26. </SOAP-ENV:Body>
  27. </SOAP-ENV:Envelope>`;
  28. const xmlPaymentResponse = `<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">
  29. <SOAP-ENV:Body>
  30. <PaymentResponse xmlns="http://H2HPEMKOT_BATAM/">
  31. <rsp>000</rsp>
  32. <resdesc>Request Data Berhasil</resdesc>
  33. <dataRes>
  34. <additionalInfo>
  35. <ntpd>15058084499314</ntpd>
  36. </additionalInfo>
  37. </dataRes>
  38. </PaymentResponse>
  39. </SOAP-ENV:Body>
  40. </SOAP-ENV:Envelope>`;
  41. if(hasInquiry) {
  42. res.writeHead(200, { 'Content-Type': 'text/xml; charset=ISO-8859-1' });
  43. res.end(xmlInquiryResponse);
  44. } else if (hasPayment) {
  45. res.writeHead(200, { 'Content-Type': 'text/xml; charset=ISO-8859-1' });
  46. res.end(xmlPaymentResponse);
  47. } else {
  48. res.writeHead(404, { 'Content-Type': 'text/plain' });
  49. res.end('Not found');
  50. }
  51. } else {
  52. res.writeHead(404, { 'Content-Type': 'text/plain' });
  53. res.end('Not found');
  54. }
  55. });
  56. });
  57. server.listen(3005, () => {
  58. console.log('SOAP dummy running at http://localhost:3005/dummy-pemko-4001');
  59. });