Created
September 17, 2019 20:07
-
-
Save joelgarciajr84/00f2f81f5120a497fdc37549ea4a6f67 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
exports.go = function(req, res){ | |
let js2xmlparser = require("js2xmlparser"); | |
let parser = require('xml2json'); | |
let request = require('request'); | |
let codfat = req.body.codfat; //Codigo da fatura | |
console.log("BUSCANDO LINHA DIGITAVEL PARA FATURA ->> " + codfat); | |
let options = { | |
object: true, | |
reversible: false, | |
coerce: false, | |
sanitize: true, | |
trim: true, | |
arrayNotation: false, | |
alternateTextNode: false | |
}; | |
let _xmlRequest = '<?xml version="1.0"?>' | |
_xmlRequest += '<methodCall>' | |
_xmlRequest += '<methodName>datasource.linhaDigitavel</methodName>' | |
_xmlRequest += '<params>' | |
_xmlRequest += '<param name="_user">' | |
_xmlRequest += '<value><string></string></value>' | |
_xmlRequest += '</param>' | |
_xmlRequest += '<param name="_passwd">' | |
_xmlRequest += '<value><string></string></value>' | |
_xmlRequest += '</param>' | |
_xmlRequest += '<param name="codfat">' | |
_xmlRequest += '<value><string>'+codfat+'</string></value>' | |
_xmlRequest += '</param>' | |
_xmlRequest += '<param name="retornaCodBarras">' | |
_xmlRequest += '<value><string>S</string></value>' | |
_xmlRequest += '</param>' | |
_xmlRequest += '</params>' | |
_xmlRequest += '</methodCall>'; | |
request({ | |
url: "http://sistema.wkve.com.br/server.php", | |
method: "POST", | |
headers: { | |
"content-type": "application/xml", // <--Very important!!! | |
}, | |
body: _xmlRequest | |
}, function (error, response, body){ | |
if(error){ | |
console.error("Ocorreu um erro", error) | |
return res.json({ | |
"status":"error", | |
"error": error | |
}) | |
}else{ | |
console.log("LINHA DIGITAVEL RETORNADA COM SUCESSO!"); | |
let ldJson = parser.toJson(body, options); | |
return res.json({ | |
"status":"success", | |
"codfat":codfat, | |
"linhaDigitavel":ldJson | |
}) | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment