Search
 
SCRIPT & CODE EXAMPLE
 

PHP

PHP Create Swiss QR-Bill API

//service and docs
https://qr.livingtech.ch

// Configuration
$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",
];

// Call function to create invoice
$myFile = generateQrInvoice($myConfiguration);

// Work with binary data
if($myFile != null) {
    // ...
}

function generateQrInvoice($myRequestConfiguration) {
    // Main configuration
    $myEndpointUrl = "http://qrbillservice.livingtech.ch";
    $myEndpointPath = "/api/qrinvoice/create/";
    $myApiKey = "mySecretApiKey";

    // GET parameters
    $myGetParams = http_build_query($myRequestConfiguration);

    // CURL
    $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"
    ));

    // Debug only
    curl_setopt($myCurl, CURLOPT_SSL_VERIFYHOST, false);
    curl_setopt($myCurl, CURLOPT_SSL_VERIFYPEER, false);

    try {
        // Perform request
        $myResponse = curl_exec($myCurl);

        // Check status
        if (!curl_errno($myCurl)) {
            if(curl_getinfo($myCurl, CURLINFO_HTTP_CODE) == 200) {
                // Read and parse JSON
                $myJsonObject  = json_decode($myResponse, true);

                // Check if error
                if($myJsonObject['isSuccessed'] == "true") {
                    if(isset($myJsonObject['base64Image']) && !empty($myJsonObject['base64Image'])) {
                        // E.g. save file
                        file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/output/" . uniqid("", true) . ".pdf", base64_decode($myJsonObject['base64Image']));

                        // Return data
                        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));
        }

        // Close curl
        curl_close($myCurl);
    } catch(Exception $e) {
        // Handle exception
        echo "Error: " . $e->getMessage();
        return null;
    }
}
Comment

PREVIOUS NEXT
Code Example
Php :: how to check if a url has a certain word in laravel 
Php :: Set Countries To Appear At The Top Of The Caldera Forms Phone Field List 
Php :: doctrine remove element from arraycollection 
Php :: php The function is a conversion from a key to a value 
Php :: how to rrestart brew php 
Php :: wp table with hostname setup 
Php :: sort array by date php 
Php :: show all errors in php 
Php :: PHP strpos — Find the position of the first occurrence of a substring in a string 
Php :: register widget in wordpress 
Php :: replace key name in associative array 
Php :: how to export and import database in phpmyadmin 
Php :: cURL error 60 : SSL certificate in Larvel in pusher or facebook authentication 
Php :: yii relations 
Php :: laravel DomPDF live preview 
Php :: Class PHPUnit_Util_Log_TeamCity does not exist 
Php :: symfony how to respond in-memory file 
Php :: connexion sql php/html 
Php :: php header x-powered-by 
Php :: add reviews from code site reviews wp 
Php :: nl_langinfo — Query language and locale information 
Php :: Array and string offset access syntax with curly braces is no longer supported in /home/southsah/public_html/wp-content/install.php on line 259 
Php :: laravel validateexception no error description 
Php :: Laravel eloquent mass assignments 
Php :: set modes magento 2 
Php :: register column types octobercms 
Php :: install wget downloader php 
Php :: $usr= $_POST["user"]; $pswd= $_POST["pass"]; 
Php :: export csv file in laravel 
Php :: How to Create a Transient PHP wordpress 
ADD CONTENT
Topic
Content
Source link
Name
5+8 =