PHP code example of jahudka / fakturoid-sdk

1. Go to this page and download the library: Download jahudka/fakturoid-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/ */

    

jahudka / fakturoid-sdk example snippets






$api = Jahudka\FakturoidSDK\Client::create($email, $apiToken, $slug, $userAgent);

// or construct the instance yourself:
$httpClient = new GuzzleHttp\Client();
$api = new Jahudka\FakturoidSDK\Client($httpClient, $email, $apiToken, $slug, $userAgent);



foreach ($api->invoices as $invoice) {
    // $invoice is an instance of Jahudka\FakturoidSDK\Entity\Invoice
    
    // Data can be accessed either through properties...
    echo $invoice->number;
    $invoice->number = '2016-123';
    
    // ... or through getters and setters.
    echo $invoice->getNumber();
    $invoice->setNumber('2016-123');
    
}



$invoices = $api->invoices
    ->setOption('status', 'open');

foreach ($invoices as $invoice) {
    echo $invoice->number . "\n";
    // ...
}

// limiting can be done by calling the getIterator() method manually
// and supplying the optional $offset and $limit arguments like this:
foreach ($api->invoices->getIterator(100, 100) as $invoice) {
    // do something with invoices #100 - #199
}



// Getting entries is simple:
$invoice = $api->invoices->get(981);
echo $invoice->getNumber();

// Creating new entries can be done
// using the endpoint's create() method:
$data = [
    'name' => 'Josef Novak',
    'street' => 'Dlouha 123',
    'city' => 'Nove Mesto',
    'zip' => '123 45',
    'country' => 'CZ',
    'registration_no' => '123456789',
];

$subject = $api->subjects->create($data);
echo $subject->getId();

// Or you can manually create the entity
// and use the endpoint's save() method:
$subject = new Jahudka\FakturoidSDK\Entity\Subject();

$subject->setName('Josef Novak');
// ...

$api->subjects->save($subject);

// The entity object is updated by the data returned
// from the server, so this still works:
echo $subject->getId();

// The save() method is useful for updating existing
// entries, either entities you previously loaded from
// the API somehow or even entities you constructed by hand:
$pepa = new Jahudka\FakturoidSDK\Entity\Subject();
$pepa->setId(3042);
$pepa->setPhone('+420 123 456 789');

$api->subjects->save($pepa);

// Same as before, the entity object is not only
// saved, but also updated using the data
// returned from the server:
echo $pepa->getBankAccount();

// Deleting entries can be done using the delete() method:
$api->subjects->delete($pepa);

// You can pass in just the ID:
$api->subjects->delete(123);