Skip to content

Instantly share code, notes, and snippets.

@aphilippi
Last active July 29, 2020 12:19
Show Gist options
  • Save aphilippi/8d89e07b00d1457c5f6f9b21a68d528a to your computer and use it in GitHub Desktop.
Save aphilippi/8d89e07b00d1457c5f6f9b21a68d528a to your computer and use it in GitHub Desktop.
Modificarea datelor unei facturi deja create
<?php
//set BASE_URL to https://factureaza.ro/api/v1/ for production
define('BASE_URL', 'https://sandbox.factureaza.ro/api/v1/');
//replace with the api key provided in the backend
define('API_KEY', '72543f4dc00474bc40a27916d172eb93339fae894ec7a6f2dceb4751d965');
$invoice_id = 1065253794; // your invoice id here
$changes = array("invoice" =>
array(
"lower_annotation" => 'Explicații noi',
"note" => "Note interne noi",
"document_positions" => array (
1 => array (
'description' => 'cartof',
'unit' => 'kg',
'unit_count' => '4',
'input_currency_price' => '0.74',
'vat' => 10
),
2 => array (
'description' => 'varză de Bruxelles',
'unit' => 'g',
'unit_count' => '250',
'input_currency_price' => '51',
'vat' => 19
)
)
)
);
$url = BASE_URL . 'invoices/' . $invoice_id . '.xml' ;
$ch = curl_init();
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERPWD, API_KEY . ":x");
curl_setopt($ch, CURLOPT_URL, $url );
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($changes));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$result = curl_exec($ch);
$header = curl_getinfo($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($httpCode == 200) {
echo 'Updated successfully';
} else {
echo '<pre> Error occured: ' . $httpCode . ':' . $result . '</pre>';
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment