https:
let myConfiguration = {
"Account" : "CH4431999123000889012",
"CreditorName" : "Muster AG",
"CreditorAddress1" : "Hauptstrasse 1",
"CreditorAddress2" : "8000 Zürich",
"CreditorCountryCode" : "CH",
"DebtorName" : "LivingTech GmbH",
"DebtorAddress1" : "Dörflistrasse 10",
"DebtorAddress2" : "8057 Zürich",
"DebtorCountryCode" : "CH",
"Amount" : "1.50",
"ReferenceNr" : "21000000000313947143000901",
"UnstructuredMessage" : "Mitteilung zur Rechnung",
"Currency" : "CHF",
"IsQrOnly" : "false",
"Format" : "PDF",
"Language" : "DE"
}
let myFile = generateQrInvoice(myConfiguration);
if(myFile != null) {
}
function generateQrInvoice(myRequestConfiguration) {
let myEndpointUrl = "http://qrbillservice.livingtech.ch";
let myEndpointPath = "/api/qrinvoice/create/";
let myApiKey = "mySecretApiKey";
let myGetParams = new URLSearchParams(myRequestConfiguration);
fetch(myEndpointUrl + myEndpointPath + "?" + myGetParams, {
method: "GET",
mode: "cors",
cache: "no-cache",
headers: {
"APIKEY": myApiKey,
"Accept": "application/json"
}
}).then(function (myResponse) {
try {
if(myResponse.status == 200) {
let myJsonObject = JSON.parse(myResponse);
if(myJsonObject["isSuccessed"] == "true") {
if("base64Image" in myJsonObject && myJsonObject["base64Image"].trim() != "") {
let myBlob = new Blob(atob(myJsonObject["base64Image"]), {type: "application/pdf"});
let myBlobUrl = URL.createObjectURL(myBlob);
window.open(myBlobUrl);
return atob(myJsonObject["base64Image"]);
} else {
throw "no data provided";
}
} else {
throw myJsonObject["Message"];
}
} else {
throw "status code " . myResponse.status;
}
}
catch(e) {
console.warn("Error: " + e.message, e);
return null;
}
}).catch(function (err) {
console.warn("Error: " + err.message, err);
return null;
});
}