Skip to content

Instantly share code, notes, and snippets.

@aphilippi
Last active February 23, 2019 14:20
Show Gist options
  • Save aphilippi/9601294 to your computer and use it in GitHub Desktop.
Save aphilippi/9601294 to your computer and use it in GitHub Desktop.
Factureaza.ro API: add invoice example
<?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');
/* adapt there variables to your needs*/
$client_id = 1064116434;
$currency_id = 183;// 183 -> RON
$invoice_series_id = 1061104069; // IDul seriei - NU PREFIXUL !!!!!
$document_series_counter = rand(1000,10000);
$url = BASE_URL . 'invoices.xml';
$ch = curl_init();
$data = array("invoice" =>
array(
"client_id" => $client_id,
"currency_id" => $currency_id,
"document_date" => '2014-05-20',
"document_series_id" => $invoice_series_id,
"document_series_counter" => $document_series_counter,
"vat_type" => 1,
"delegate_id" => 525664463,
"display_transport_data" => 1,
"document_positions" => array (
1 => array (
'description' => 'ABONAMENT BASIC',
'unit' => 'luni',
'unit_count' => '12',
'price' => '12',
'product_code' => '66XXH663496H',
'vat' => 19
),
2 => array (
'type' => 'DiscountPosition',
'description' => 'Reducere pentru plata in avans',
'discount_rate' => '12'
)
)
)
);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERPWD, API_KEY . ":x");
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt($ch, CURLOPT_URL, $url );
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 == 201) {
// transform the invoice data from xml to a array
$invoice_data = json_decode(json_encode(simplexml_load_string($result)), TRUE);
echo 'Invoice created successfully. Invoice id: ' . $invoice_data['id'];
} else {
echo '<pre> Error occured: ' . $httpCode . ':' . $result . '</pre>';
}
?>
//alternative for XML-lovers:
<?php
//set BASE_URL to https://factureaza.ro/api/ for production
define('BASE_URL', 'https://sandbox.factureaza.ro/api/');
//replace with the api key provided in the backend
define('API_KEY', '72543f4dc00474bc40a27916d172eb93339fae894ec7a6f2dceb4751d965');
/* adapt there variables to your needs*/
$client_id = 1064116434;
$currency_id = 183;// 183 -> RON
$invoice_series_id = 1061104069; // IDul seriei - NU PREFIXUL !!!!!
$document_series_counter = rand(1000,10000);
$url = BASE_URL . 'invoices.xml';
$ch = curl_init();
$postdata = '<?xml version="1.0" encoding="UTF-8"?>
<invoice>
<client_id>' . $client_id . '</client_id>
<currency_id>' . $currency_id . '</currency_id>
<document_date>2014-05-20</document_date>
<document_series_id>' . $invoice_series_id . '</document_series_id>
<document_series_counter>' . $document_series_counter . '</document_series_counter>
<vat_type>1</vat_type>
<delegate_id>525664463</delegate_id>
<display_transport_data>1</display_transport_data>
<document_positions>
<document_position>
<description>ABONAMENT BASIC</description>
<unit>luni</unit>
<unit_count>12</unit_count>
<price>12</price>
<product_code>66XXH663496H</product_code>
<vat>24</vat>
</document_position>
<document_position>
<type>DiscountPosition</type>
<description>Reducere pentru plata in avans</description>
<discount_rate>10</discount_rate>
</document_position>
</document_positions>
</invoice>';
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERPWD, API_KEY . ":x");
curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
curl_setopt($ch, CURLOPT_URL, $url );
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/xml'));
$result = curl_exec($ch);
$header = curl_getinfo($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($httpCode == 201) {
// transform the invoice data from xml to a array
$invoice_data = json_decode(json_encode(simplexml_load_string($result)), TRUE);
echo 'Invoice created successfully. Invoice id: ' . $invoice_data['id'];
} else {
echo '<pre> Error occured: ' . $httpCode . ':' . $result . '</pre>';
}
?>
<?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');
/* adapt there variables to your needs*/
$client_id = 1064116436;
$currency_id = 183;// 183 -> RON
$invoice_series_id = 1061104069; // IDul seriei - NU PREFIXUL !!!!!
$document_series_counter = rand(1000,10000);
$url = BASE_URL . 'invoices.xml';
$ch = curl_init();
$data = array("invoice" =>
array(
"client_id" => $client_id,
"currency_id" => $currency_id,
"document_date" => '2014-10-20',
"document_series_id" => $invoice_series_id,
"document_series_counter" => $document_series_counter,
"vat_type" => 1,
"delegate_id" => 525664463,
"display_transport_data" => 1,
"source_document_id" => 1065253810,
"reversed_document_id" => 1065253810,
'input_currency_reversing' => 100,
"document_positions" => array (
1 => array (
'description' => 'STORNARE partiala alta factura',
'unit' => 'luni',
'unit_count' => '12',
'price' => '-12',
'product_code' => '66XXH663496H',
'vat' => 19
),
)
)
);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERPWD, API_KEY . ":x");
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt($ch, CURLOPT_URL, $url );
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 == 201) {
// transform the invoice data from xml to a array
$invoice_data = json_decode(json_encode(simplexml_load_string($result)), TRUE);
echo 'Invoice created successfully. Invoice id: ' . $invoice_data['id'];
} else {
echo '<pre> Error occured: ' . $httpCode . ':' . $result . '</pre>';
}
?>
<?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 = 1065253795; // your invoice id here
$url = BASE_URL . 'invoices/' . $invoice_id . '.xml' ;
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERPWD, API_KEY . ":x");
curl_setopt($ch, CURLOPT_URL, $url );
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$result = curl_exec($ch);
curl_close($ch);
echo '<pre>' . htmlentities($result) . '</pre>';
?>
<?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');
$url = BASE_URL . 'invoices.xml';
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERPWD, API_KEY . ":x");
curl_setopt($ch, CURLOPT_URL, $url );
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$result = curl_exec($ch);
curl_close($ch);
echo '<pre>' . htmlentities($result) . '</pre>';
?>
<?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
$url = BASE_URL . 'invoices/' . $invoice_id . '/mark_closed.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_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query([]));
$result = curl_exec($ch);
curl_close($ch);
echo '<pre>' . htmlentities($result) . '</pre>';
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment