Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save aphilippi/015a3d28a27180c02f2da3f2270a14cf to your computer and use it in GitHub Desktop.
Save aphilippi/015a3d28a27180c02f2da3f2270a14cf to your computer and use it in GitHub Desktop.
Update client record and update invoice for client to reflect changes
<?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');
$client_id = 1064116434; // your client id here
$changes = array("client" => array("name" => 'Nume client schimbat', "city" => "Nume oras nou"));
$url = BASE_URL . 'clients/' . $client_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 'Client updated successfully<br/>';
} else {
echo '<pre> Error occured: ' . $httpCode . ':' . $result . '</pre>';
}
$invoice_id = 1065253795; // a invoice for the above client
$changes = array("invoice" =>
array(
"update_client_data" => "1",
"note" => "client data updated"
)
);
$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 'Invoice 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