#!/usr/bin/env php
<?php


/**
* In acest exemplu se face o cerere POST catre API-ul IceFact pentru a crea o factura.
* In cazul in care comanda s-a executat cu succes, raspunsul va fi de forma:
*
* {
*     "status": "OK",
*     "invoice_id": 1
* }
* 
*/


$url = 'https://api.icefact.ro:10777/v1/invoice/create';

$data = [
    "cumparator" => [
        "denumire"   => "Test SRL",
        "localitate" => "Navodari",
        "judet"      => "RO-CT",
        "tara"       => "RO"
    ],
    "articole" => [
        [
            "denumire"              => "Produs",
            "um"                    => "H87",
            "cantitate"             => 1,
            "pret_unitar_fara_tva"  => 100,
            "cota_tva"              => "21%"
        ]
    ]
];

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    'Content-Type: application/json'
]);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));

curl_setopt($ch, CURLOPT_SSLCERT, 'demo-api.icefact.ro.crt');
curl_setopt($ch, CURLOPT_SSLKEY, 'demo-api.icefact.ro.key');

$response = curl_exec($ch);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);

echo "Status code: $http_code\n";
echo "Response text: $response\n";
