PHP code example of abb / fakturownia

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

    

abb / fakturownia example snippets


$fakturownia = new \Abb\Fakturownia\Fakturownia('fakturownia_api_token');
$response = $fakturownia->getInvoices();
if ($response->isSuccess()) { // check response status before you retrieve data
    $invoices = $response->getData();
} else {
    $errors = $response->getData();
}

$fakturownia = new \Abb\Fakturownia\Fakturownia('fakturownia_api_token');
$params = [
    'period' => 'this_month',
    'page' => '1',
];
$invoices = $fakturownia->getInvoices($params)->getData();

$fakturownia = new \Abb\Fakturownia\Fakturownia('fakturownia_api_token');
$invoiceId = 123456;
$invoice = $fakturownia->getInvoice($invoiceId)->getData();

$fakturownia = new \Abb\Fakturownia\Fakturownia('fakturownia_api_token');
$invoiceId = 123456;
$printOption = 'duplicate';
$pdfContent = $fakturownia->getInvoicePdf($invoiceId, $printOption)->getData()['content'];
file_put_contents('/path/to/invoice.pdf', $pdfContent);

$fakturownia = new \Abb\Fakturownia\Fakturownia('fakturownia_api_token');
$invoiceData = [
    'kind' => 'vat',
    'number' => null,
    'sell_date' => '2013-01-16',
    'issue_date' => '2013-01-16',
    'payment_to' => '2013-01-23',
    'seller_name' => 'Wystawca Sp. z o.o.',
    'seller_tax_no' => '5252445767',
    'buyer_name' => 'Klient1 Sp. z o.o.',
    'buyer_email' => '[email protected]',
    'buyer_tax_no' => '5252445767',
    'positions' => [
        [
            'name' => 'Produkt A1',
            'tax' => 23,
            'total_price_gross' => 10.23,
            'quantity' => 1,
        ],
        [
            'name' => 'Produkt A2',
            'tax' => 0,
            'total_price_gross' => 50,
            'quantity' => 3,
        ],
    ],
];
$createdInvoice = $fakturownia->createInvoice($invoiceData)->getData();

$fakturownia = new \Abb\Fakturownia\Fakturownia('fakturownia_api_token');
$invoiceData = [
    'buyer_email' => '[email protected]',
    // ...
];
$response = $fakturownia->createInvoice($invoiceData);
if ($response->isSuccess()) {
    $createdInvoice = $response->getData();
    $fakturownia->sendInvoice($createdInvoice['id']); // Invoice will be sent to buyer_email
}

$fakturownia = new \Abb\Fakturownia\Fakturownia('fakturownia_api_token');
$invoiceId = 123456;
$invoiceData = [
    'buyer_name' => 'Nowa nazwa klienta Sp. z o.o.',
    'positions' =>  [
        [
            'id' => 32649087,
            'name' => 'Nowa nazwa pozycji na fakturze',
        ],
    ],
];
$updatedInvoice = $fakturownia->updateInvoice($invoiceId, $invoiceData)->getData();

$fakturownia = new \Abb\Fakturownia\Fakturownia('fakturownia_api_token');
$invoiceId = 123456;
$result = $fakturownia->deleteInvoice($invoiceId)->getData();