https:
$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",
];
$myFile = generateQrInvoice($myConfiguration);
if($myFile != null) {
}
function generateQrInvoice($myRequestConfiguration) {
$myEndpointUrl = "http://qrbillservice.livingtech.ch";
$myEndpointPath = "/api/qrinvoice/create/";
$myApiKey = "mySecretApiKey";
$myGetParams = http_build_query($myRequestConfiguration);
$myCurl = curl_init();
curl_setopt($myCurl, CURLOPT_URL, $myEndpointUrl . $myEndpointPath . "?" . $myGetParams);
curl_setopt($myCurl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($myCurl, CURLOPT_HTTPHEADER, array(
"APIKEY: " . $myApiKey,
"Accept: application/json"
));
curl_setopt($myCurl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($myCurl, CURLOPT_SSL_VERIFYPEER, false);
try {
$myResponse = curl_exec($myCurl);
if (!curl_errno($myCurl)) {
if(curl_getinfo($myCurl, CURLINFO_HTTP_CODE) == 200) {
$myJsonObject = json_decode($myResponse, true);
if($myJsonObject['isSuccessed'] == "true") {
if(isset($myJsonObject['base64Image']) && !empty($myJsonObject['base64Image'])) {
file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/output/" . uniqid("", true) . ".pdf", base64_decode($myJsonObject['base64Image']));
return base64_decode($myJsonObject['base64Image']);
} else {
throw new Exception("no data provided");
}
} else {
throw new Exception($myJsonObject["Message"]);
}
} else {
throw new Exception("status code " . curl_getinfo($myCurl, CURLINFO_HTTP_CODE));
}
} else {
throw new Exception(curl_error($myCurl));
}
curl_close($myCurl);
} catch(Exception $e) {
echo "Error: " . $e->getMessage();
return null;
}
}