PHP code example of konekt / factureaza-sdk

1. Go to this page and download the library: Download konekt/factureaza-sdk library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

konekt / factureaza-sdk example snippets


$live = Factureaza::connect('api key here');
$live->myAccount();
// => Konekt\Factureaza\Models\MyAccount
//     id: "555000444",
//     name: "yourcompany",
//     companyName: "Your Company SRL",
//     createdAt: "2019-06-06T16:23:34+03:00",
//     updatedAt: "2022-09-13T08:03:29+03:00"
//     ...

$sandbox = Factureaza::sandbox();
$sandbox->myAccount();
// => Konekt\Factureaza\Models\MyAccount
//     id: "340138083",
//     name: "sandbox",
//     companyName: "Test Services SRL",
//     createdAt: "2014-06-06T16:23:34+03:00",
//     updatedAt: "2022-09-13T08:03:29+03:00"
//     ...

$factureaza = Factureaza::connect('api key');
$factureaza->myAccount()->createdAt->toIso8601String();
// 2014-06-06T16:23:34+03:00

$factureaza->useUtcTime();
$factureaza->myAccount()->createdAt->toIsoString();
// 2014-06-06T13:23:34+00:00

$request = CreateInvoice::inSeries('1061104148')
    ->forClient('1064116434')
    ->withEmissionDate('2021-09-17')
    ->addItem(['description' => 'Service', 'price' => 19, 'unit' => 'luna', 'productCode' => '']);

$invoice = Factureaza::sandbox()->createInvoice($request);
//=> Konekt\Factureaza\Models\Invoice {#2760
//     +documentDate: Carbon\CarbonImmutable @1631826000 {#2773
//       date: 2021-09-17 00:00:00.0 Europe/Bucharest (+03:00),
//     },
//     +clientId: "1064116434",
//     +items: [
//       Konekt\Factureaza\Models\InvoiceItem {#2765
//         +description: "Service",
//         +price: 19.0,
//         +unit: "luna",
//         +quantity: 1.0,
//         +productCode: "",
//         +id: "1056077322",
//       },
//     ],
//     +id: "1065254080",
//     +createdAt: Carbon\CarbonImmutable @1665076996 {#2772
//       date: 2022-10-06 20:23:16.0 Europe/Bucharest (+03:00),
//     },
//     +updatedAt: Carbon\CarbonImmutable @1665076996 {#2771
//       date: 2022-10-06 20:23:16.0 Europe/Bucharest (+03:00),
//     },
//   }

$request = CreateInvoice::inSeries('1061104148')->asDraft();
//...
Factureaza::sandbox()->createInvoice($request);

$request = CreateInvoice::inSeries('1061104148')->asClosed();
//...
Factureaza::sandbox()->createInvoice($request);

$invoiceId = '1234567';
$pdf = Factureaza::connect('your-api-key')->invoiceAsPdfBase64($invoiceId);

// Mind decoding it when you want to save it:

file_put_contents('invoice.pdf', base64_decode($pdf));

$invoiceId = '1065254039';
$invoice = Factureaza::connect('your-api-key')->invoice($invoiceId);
//=> Konekt\Factureaza\Models\Invoice {#2760

$client = Factureaza::sandbox()->client('1064116434');
//=> Konekt\Factureaza\Models\Client {#2691
//     +name: "CUBUS ARTS S.R.L.",
//     +isCompany: true,
//     +address: "BLD. MIHAI VITEAZU Nr. 7,Ap. 18",
//     +address2: "",
//     +zip: "550350",
//     +city: "SIBIU",
//     +province: "Sibiu",
//     +country: "RO",
//     +email: "[email protected]",
//     +regNo: "J32 /508 /2000",
//     +taxNo: "13548146",
//     +taxNoPrefix: "RO",
//     +id: "1064116434",
//     +createdAt: Carbon\CarbonImmutable @1402061592 {#2708
//       date: 2014-06-06 16:33:12.0 Europe/Bucharest (+03:00),
//     },
//     +updatedAt: Carbon\CarbonImmutable @1402061592 {#2696
//       date: 2014-06-06 16:33:12.0 Europe/Bucharest (+03:00),
//     },
//   }

$client = Factureaza::sandbox()->clientByTaxNo('13548146');

$client = Factureaza::sandbox()->clientByEmail('[email protected]');

$client = Factureaza::sandbox()->clientByName('Client SRL');

$client = Factureaza::sandbox()->createClient([
    'name' => 'Giovanni Gatto',
    'isCompany' => false,
    'city' => 'Pokyo',
    'address' => 'Mishiaza Vue 72',
]);
//=> Konekt\Factureaza\Models\Client {#2701
//     +name: "Giovanni Gatto",
//     +isCompany: false,
//     +address: "Mishiaza Vue 72",
//     +address2: null,
//     +zip: null,
//     +city: "Pokyo",
//     +province: null,
//     +country: "RO",
//     +email: null,
//     +phone: null,
//     +regNo: null,
//     +taxNo: "",
//     +taxNoPrefix: null,
//     +id: "1064116440",
//     +createdAt: Carbon\CarbonImmutable @1665343572 {#2692
//       date: 2022-10-09 22:26:12.0 Europe/Bucharest (+03:00),
//     },
//     +updatedAt: Carbon\CarbonImmutable @1665343572 {#2722
//       date: 2022-10-09 22:26:12.0 Europe/Bucharest (+03:00),
//     },
//   }