dummyPemko4004.js 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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-4004' && 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_BEKASI/">
  16. <InquiryResult>
  17. <Response>00</Response>
  18. <Message>Sukses</Message>
  19. <transaction_id>201709191606131622</transaction_id>
  20. <NamaWP>NENENG KURNIASIH</NamaWP>
  21. <Jumlah_pokok>28793</Jumlah_pokok>
  22. <Jumlah_denda>576</Jumlah_denda>
  23. <JumlahBayar>29369</JumlahBayar>
  24. <TanggalBooking></TanggalBooking>
  25. <TanggalExpired></TanggalExpired>
  26. </InquiryResult>
  27. </InquiryResponse>
  28. </SOAP-ENV:Body>
  29. </SOAP-ENV:Envelope>`;
  30. 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">
  31. <SOAP-ENV:Body>
  32. <PaymentResponse xmlns="http://H2HPEMKOT_BEKASI/">
  33. <PaymentResult>
  34. <Response>00</Response>
  35. <Message>Sukses</Message>
  36. <transaction_id>201709191607298865</transaction_id>
  37. <ntpd>15058084499314</ntpd>
  38. </PaymentResult>
  39. </PaymentResponse>
  40. </SOAP-ENV:Body>
  41. </SOAP-ENV:Envelope>`;
  42. if(hasInquiry) {
  43. res.writeHead(200, { 'Content-Type': 'text/xml; charset=ISO-8859-1' });
  44. res.end(xmlInquiryResponse);
  45. } else if (hasPayment) {
  46. res.writeHead(200, { 'Content-Type': 'text/xml; charset=ISO-8859-1' });
  47. res.end(xmlPaymentResponse);
  48. } else {
  49. res.writeHead(404, { 'Content-Type': 'text/plain' });
  50. res.end('Not found');
  51. }
  52. } else {
  53. res.writeHead(404, { 'Content-Type': 'text/plain' });
  54. res.end('Not found');
  55. }
  56. });
  57. });
  58. server.listen(3003, () => {
  59. console.log('SOAP dummy running at http://localhost:3003/dummy-pemko-4004');
  60. });