| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152 |
- 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>(.*?)<\/NS1:billkey1>/;
- const regeXbillkey2 = /<NS1:billkey2>(.*?)<\/NS1:billkey2>/;
- const regeXbillkey3 = /<NS1:billkey3>(.*?)<\/NS1:billkey3>/;
- const regeXbillkey4 = /<NS1:billkey4>(.*?)<\/NS1:billkey4>/;
- const regeXbillkey9 = /<NS1:billkey9>(.*?)<\/NS1:billkey9>/;
- const regeXbillkey10 = /<NS1:billkey10>(.*?)<\/NS1:billkey10>/;
- const regeXterminalID = /<NS1:terminalID>(.*?)<\/NS1:terminalID>/;
- const regeXidTransaksi = /<NS1:idTransaksi>(.*?)<\/NS1:idTransaksi>/;
- const regeXtransDateTime = /<NS1:transDateTime>(.*?)<\/NS1:transDateTime>/;
- const regeXbillkey5 = /<NS1:billkey5>(.*?)<\/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 = `<errorCode>00</errorCode>`
- let errMessage = `<errorDescription>success</errorDescription>`
- if (billkey3 == '88888888') {
- errCode = `<errorCode>01</errorCode>`
- errMessage = `<errorDescription>Invalid virtual account number.</errorDescription>`
- }
- if (req.url === '/dummy-bpjskes' && req.method === 'POST') {
- const xmlInquiryResponse = `<?xml version="1.0" encoding="utf-8"?>
- <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns:xsd="http://www.w3.org/2001/XMLSchema">
- <soap:Body>
- <InquiryResponse xmlns="http://BTN-BPJSKES/">
- <InquiryResult>
- <billinfo1>`+billkey1+`</billinfo1>
- <billinfo2>`+billkey2+`</billinfo2>
- <billinfo3>`+billkey3+`</billinfo3>
- <billinfo4>`+billkey4+`</billinfo4>
- <billinfo5>`+billkey5+`</billinfo5>
- <billinfo6>1-H A AZIZ MACHMUD FA</billinfo6>
- <billinfo7>PANGKAL PINANG</billinfo7>
- <billinfo8>4C1E89221DDC2017</billinfo8>
- <billinfo9>`+billkey9+`</billinfo9>
- <billinfo10>`+billkey10+`</billinfo10>
- <billinfo11>0602</billinfo11>
- <billinfo12/>
- <totalAmount>13023415</totalAmount>
- <terminalID>`+terminalID+`</terminalID>
- <idTransaksi>`+idTransaksi+`</idTransaksi>
- <transDateTime>`+transDateTime+`</transDateTime>
- <billDetails/>
- <status>
- <Status>
- <isError>false</isError>
- <errorCode>00</errorCode>
- <errorDescription>success</errorDescription>
- </Status>
- </status>
- </InquiryResult>
- </InquiryResponse>
- </soap:Body>
- </soap:Envelope>`;
- const xmlPaymentResponse = `<?xml version="1.0" encoding="utf-8"?>
- <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns:xsd="http://www.w3.org/2001/XMLSchema">
- <soap:Body>
- <PaymentResponse xmlns="http://BTN-BPJSKES/">
- <PaymentResult>
- <billinfo1/>
- <billinfo2/>
- <billinfo3/>
- <billinfo4/>
- <billinfo5/>
- <billinfo6/>
- <billinfo7/>
- <billinfo8/>
- <billinfo9/>
- <billinfo10/>
- <billinfo11/>
- <billinfo12/>
- <totalAmount>0</totalAmount>
- <terminalID/>
- <idTransaksi/>
- <transDateTime/>
- <billDetails/>
- <status>
- <Status>
- <isError>false</isError>`+
- errCode+
- errMessage+`
- </Status>
- </status>
- </PaymentResult>
- </PaymentResponse>
- </soap:Body>
- </soap:Envelope>`;
- 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');
- });
|