const http = require('http');
const server = http.createServer((req, res) => {
let body = '';
let hasInquiry = false;
let hasPayment = true
req.on('data', (chunk) => {
body += chunk;
});
req.on('end', () => {
hasInquiry = /<(\w+:)?Inquiry\b/.test(body);
hasPayment = /<(\w+:)?Payment\b/.test(body);
if (req.url === '/dummy-ws-mp-7727' && req.method === 'POST') {
const xmlInquiryResponse = `
52000030128
MUHAMMAD FAUZIANNOOR
Tagihan POLITEKNIK NEGERI BANJARMASIN
2900000
1500
00
Sukses
false
`;
const xmlPaymentResponse = `
52000030128
MUHAMMAD FAUZIANNOOR
Tagihan POLITEKNIK NEGERI BANJARMASIN
2900000
1500
26080600000610008252
00
Sukses
false
`;
if(hasInquiry) {
res.writeHead(200, { 'Content-Type': 'text/xml; charset=ISO-8859-1' });
res.end(xmlInquiryResponse);
} else if (hasPayment) {
res.writeHead(200, { 'Content-Type': 'text/xml; charset=ISO-8859-1' });
res.end(xmlPaymentResponse);
} else {
console.log('nohasinqorpay');
res.writeHead(404, { 'Content-Type': 'text/plain' });
res.end('Not found');
}
} else {
console.log(req)
console.log('nopost');
res.writeHead(404, { 'Content-Type': 'text/plain' });
res.end('Not found');
}
});
});
server.listen(3133, () => {
console.log('SOAP dummy running at http://localhost:3133/dummy-ws-mpp-7727');
});