obliosoftware / oblio-api
Oblio.eu API implementation for PHP
Installs: 9 877
Dependents: 0
Suggesters: 0
Security: 0
Stars: 9
Watchers: 2
Forks: 0
Open Issues: 1
Requires
- guzzlehttp/guzzle: ^6.0|^7.0
Requires (Dev)
- phpunit/phpunit: ^10.0
- symfony/var-dumper: *
README
Oblio.eu API implementation for PHP
Install using composer
composer require obliosoftware/oblio-api
Create invoice
$defaultData = array( 'cif' => '', 'client' => [ 'cif' => '', 'name' => '', 'rc' => '', 'code' => '', 'address' => '', 'state' => '', 'city' => '', 'country' => '', 'iban' => '', 'bank' => '', 'email' => '', 'phone' => '', 'contact' => '', 'vatPayer' => '', ], 'issueDate' => 'yyyy-mm-dd', 'dueDate' => '', 'deliveryDate' => '', 'collectDate' => '', 'seriesName' => '', 'collect' => [], 'referenceDocument' => [], 'language' => 'RO', 'precision' => 2, 'currency' => 'RON', 'products' => [ [ 'name' => 'Abonament', 'code' => '', 'description' => '', 'price' => '100', 'measuringUnit' => 'buc', 'currency' => 'RON', 'vatName' => 'Normala', 'vatPercentage' => 19, 'vatIncluded' => true, 'quantity' => 2, 'productType' => 'Serviciu', ] ], 'issuerName' => '', 'issuerId' => '', 'noticeNumber' => '', 'internalNote' => '', 'deputyName' => '', 'deputyIdentityCard' => '', 'deputyAuto' => '', 'selesAgent' => '', 'mentions' => '', 'value' => 0, 'workStation' => 'Sediu', 'useStock' => 0, ); try { $api = new OblioSoftware\Api($email, $secret); // create invoice: $result = $api->createInvoice($defaultData); } catch (Exception $e) { // error handle }
Cancel invoice
try { $issuerCif = ''; // your company CIF $api = new OblioSoftware\Api($email, $secret); // cancel/restore document: $api->setCif($issuerCif); $result = $api->cancel('invoice', $seriesName, $number, true/false); } catch (Exception $e) { // error handle }
Nomenclature
try { $issuerCif = ''; // your company CIF $type = 'products'; // companies, vat_rates, products, clients, series, languages, management $name = ''; $filters = [ 'workStation' => '', 'management' => '', 'limitPerPage' => 250, 'offset' => 0, ]; $api = new OblioSoftware\Api($email, $secret); $api->setCif($issuerCif); $result = $api->nomenclature($type, $name, $filters); } catch (Exception $e) { // error handle }
Collect invoice
try { $issuerCif = ''; // your company CIF $seriesName = ''; $number = ''; $collect = [ 'type' => 'Ordin de plata', 'documentNumber' => 'OP 7001', ]; $api = new OblioSoftware\Api($email, $secret); $api->setCif($issuerCif); $result = $api->collect($seriesName, $number, $collect); } catch (Exception $e) { // error handle }
Create custom AccessTokenHandler example
use OblioSoftware\AccessToken; use OblioSoftware\AccessTokenHandlerInterface; class CustomAccessTokenHandler implements AccessTokenHandlerInterface { private $cacheKey = 'oblio_access_token'; public function get(): ?AccessToken { $data = Cache::get($this->cacheKey); if ($data !== null) { $accessToken = new AccessToken($data); if ($accessToken && $accessToken->request_time + $accessToken->expires_in > time()) { return $accessToken; } } return null; } public function set(AccessToken $accessToken): void { Cache::set($this->cacheKey, $accessToken->toArray()); } }
Create webhook
use OblioSoftware\Request\WebhookCreate; try { $issuerCif = ''; // your company CIF $endpoint = ''; // a valid webhook endpoint $api = new OblioSoftware\Api($email, $secret); $response = $api->createRequest( new WebhookCreate([ 'cif' => $issuerCif, 'topic' => 'stock', 'endpoint' => $endpoint, ]) ); $result = json_decode($response->getBody()->getContents(), true); } catch (Exception $e) { // error handle }