const http = require('http'); const server = http.createServer((req, res) => { let body = ''; let hasInquiry = false; let hasPayment = false; req.on('data', (chunk) => { body += chunk; }); req.on('end', () => { hasInquiry = /<(\w+:)?Inquiry\b/.test(body); hasPayment = /<(\w+:)?Payment\b/.test(body); const regeXbillkey1 = /(.*?)<\/NS1:billkey1>/; const regeXbillkey2 = /(.*?)<\/NS1:billkey2>/; const regeXbillkey3 = /(.*?)<\/NS1:billkey3>/; const regeXbillkey4 = /(.*?)<\/NS1:billkey4>/; const regeXbillkey9 = /(.*?)<\/NS1:billkey9>/; const regeXbillkey10 = /(.*?)<\/NS1:billkey10>/; const regeXterminalID = /(.*?)<\/NS1:terminalID>/; const regeXidTransaksi = /(.*?)<\/NS1:idTransaksi>/; const regeXtransDateTime = /(.*?)<\/NS1:transDateTime>/; const regeXbillkey5 = /(.*?)<\/NS1:billkey5>/; const matcHbillkey1 = body.match(regeXbillkey1); const matcHbillkey2 = body.match(regeXbillkey2); const matcHbillkey3 = body.match(regeXbillkey3); const matcHbillkey4 = body.match(regeXbillkey4); const matcHbillkey9 = body.match(regeXbillkey9); const matcHbillkey10 = body.match(regeXbillkey10); const matcHterminalID = body.match(regeXterminalID); const matcHidTransaksi = body.match(regeXidTransaksi); const matcHtransDateTime = body.match(regeXtransDateTime); const matcHbillkey5 = body.match(regeXbillkey5); const billkey1 = matcHbillkey1 ? matcHbillkey1[1] : null; const billkey2 = matcHbillkey2 ? matcHbillkey2[1] : null; const billkey3 = matcHbillkey3 ? matcHbillkey3[1] : null; const billkey4 = matcHbillkey4 ? matcHbillkey4[1] : null; const billkey9 = matcHbillkey9 ? matcHbillkey9[1] : null; const billkey10 = matcHbillkey10 ? matcHbillkey10[1] : null; const terminalID = matcHterminalID ? matcHterminalID[1] : null; const idTransaksi = matcHidTransaksi ? matcHidTransaksi[1] : null; const transDateTime = matcHtransDateTime ? matcHtransDateTime[1] : null; const billkey5 = matcHbillkey5 ? matcHbillkey5[1] : null; console.log("billkey3 Value:", billkey3); let errCode = `00` let errMessage = `success` if (billkey3 == '88888888') { errCode = `01` errMessage = `Invalid virtual account number.` } if (req.url === '/dummy-bpjskes' && req.method === 'POST') { const xmlInquiryResponse = ` `+billkey1+` `+billkey2+` `+billkey3+` `+billkey4+` `+billkey5+` 1-H A AZIZ MACHMUD FA PANGKAL PINANG 4C1E89221DDC2017 `+billkey9+` `+billkey10+` 0602 13023415 `+terminalID+` `+idTransaksi+` `+transDateTime+` false 00 success `; const xmlPaymentResponse = ` 0 false`+ errCode+ errMessage+` `; if (hasInquiry) { res.writeHead(200, { 'Content-Type': 'text/xml; charset=utf-8' }); res.end(xmlInquiryResponse); } else if (hasPayment) { res.writeHead(200, { 'Content-Type': 'text/xml; charset=utf-8' }); res.end(xmlPaymentResponse); } else { res.writeHead(400, { 'Content-Type': 'text/plain' }); res.end('Bad Request: No Inquiry or Payment action found'); } } else { res.writeHead(404, { 'Content-Type': 'text/plain' }); res.end('Not found'); } }); }); server.listen(3093, () => { console.log('SOAP dummy BPJS Kesehatan running at http://localhost:3016/dummy-bpjskes'); });