PHP code example of netipar / szamlazzhu

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

    

netipar / szamlazzhu example snippets


use NETipar\Szamlazzhu\Client;
use NETipar\Szamlazzhu\Document\Invoice;
use NETipar\Szamlazzhu\Entity\Buyer;
use NETipar\Szamlazzhu\Enums\PaymentMethod;
use NETipar\Szamlazzhu\Item\InvoiceItem;

$client = app(Client::class);

$invoice = new Invoice();
$invoice->getHeader()->setPaymentMethod(PaymentMethod::BankTransfer);

$invoice->setBuyer(new Buyer(
    name: 'Customer Kft.',
    zipCode: '1234',
    city: 'Budapest',
    address: 'Main Street 1.',
));

$item = new InvoiceItem();
$item->setName('Product name')
    ->setNetUnitPrice(10000.0)
    ->setQuantity(2.0)
    ->setVat('27')
    ->setNetPrice(20000.0)
    ->setVatAmount(5400.0)
    ->setGrossAmount(25400.0);
$invoice->addItem($item);

$result = $client->generateInvoice($invoice);

$result->isSuccess();         // true
$result->getDocumentNumber(); // 'E-PREFIX-2026-001'
$result->getPdfFile();        // PDF binary string

use NETipar\Szamlazzhu\Client;

// Dependency injection (preferred)
public function handle(Client $client): void
{
    $result = $client->generateInvoice($invoice);
}

// Or via service container
$client = app(Client::class);

use NETipar\Szamlazzhu\Client;
use NETipar\Szamlazzhu\Document\Invoice;
use NETipar\Szamlazzhu\Entity\Buyer;
use NETipar\Szamlazzhu\Entity\Seller;
use NETipar\Szamlazzhu\Enums\Currency;
use NETipar\Szamlazzhu\Enums\Language;
use NETipar\Szamlazzhu\Enums\PaymentMethod;
use NETipar\Szamlazzhu\Item\InvoiceItem;

$invoice = new Invoice();

$header = $invoice->getHeader();
$header->setIssueDate(now()->format('Y-m-d'));
$header->setFulfillment(now()->format('Y-m-d'));
$header->setPaymentDue(now()->addDays(8)->format('Y-m-d'));
$header->setPaymentMethod(PaymentMethod::BankTransfer);
$header->setCurrency(Currency::HUF);
$header->setLanguage(Language::Hungarian);
$header->setComment('Invoice comment');

$invoice->setSeller(new Seller(
    bankName: 'OTP Bank',
    bankAccountNumber: '11111111-22222222-33333333',
));

$invoice->setBuyer(new Buyer(
    name: 'Customer Kft.',
    zipCode: '1234',
    city: 'Budapest',
    address: 'Main Street 1.',
    taxNumber: '12345678-1-42',
    email: '[email protected]',
));

$item = new InvoiceItem();
$item->setName('Product name')
    ->setNetUnitPrice(10000.0)
    ->setQuantity(2.0)
    ->setQuantityUnit('db')
    ->setVat('27')
    ->setNetPrice(20000.0)
    ->setVatAmount(5400.0)
    ->setGrossAmount(25400.0);
$invoice->addItem($item);

$result = $client->generateInvoice($invoice);

$result->isSuccess();         // bool
$result->getDocumentNumber(); // e.g. 'E-PREFIX-2026-001'
$result->getPdfFile();        // PDF binary string or null

$invoice->getHeader()->setSimpleItems(true);

use NETipar\Szamlazzhu\Document\Receipt;
use NETipar\Szamlazzhu\Entity\Buyer;
use NETipar\Szamlazzhu\Enums\Currency;
use NETipar\Szamlazzhu\Enums\PaymentMethod;
use NETipar\Szamlazzhu\Item\ReceiptItem;

$receipt = new Receipt();
$receipt->getHeader()->setPrefix('NYGTA');
$receipt->getHeader()->setPaymentMethod(PaymentMethod::Cash);
$receipt->getHeader()->setCurrency(Currency::HUF);
$receipt->getHeader()->setOrderNumber('ORD-123'); // optional

$receipt->setBuyer(new Buyer(name: 'Customer Name'));

$item = new ReceiptItem();
$item->setName('Item name')
    ->setNetUnitPrice(10000.0)
    ->setQuantity(1.0)
    ->setQuantityUnit('db')
    ->setVat('27')
    ->setNetPrice(10000.0)
    ->setVatAmount(2700.0)
    ->setGrossAmount(12700.0);
$receipt->addItem($item);

$result = $client->generateReceipt($receipt);

use NETipar\Szamlazzhu\Document\Proforma;

$proforma = new Proforma();
// Same structure as Invoice: getHeader(), setSeller(), setBuyer(), addItem()
$result = $client->generateProforma($proforma);

use NETipar\Szamlazzhu\Document\DeliveryNote;

$note = new DeliveryNote();
// Same structure as Invoice: getHeader(), setSeller(), setBuyer(), addItem()
$result = $client->generateDeliveryNote($note);

use NETipar\Szamlazzhu\Document\ReverseInvoice;

$invoice = new ReverseInvoice();
$invoice->getHeader()->setInvoiceNumber('E-PREFIX-2026-001');

$result = $client->generateReverseInvoice($invoice);

use NETipar\Szamlazzhu\Document\ReverseReceipt;

$receipt = new ReverseReceipt();
$receipt->getHeader()->setReceiptNumber('NYGTA-2026-1');

$result = $client->generateReverseReceipt($receipt);

use NETipar\Szamlazzhu\CreditNote\InvoiceCreditNote;
use NETipar\Szamlazzhu\Document\Invoice;

$invoice = new Invoice();
$invoice->getHeader()->setInvoiceNumber('E-PREFIX-2026-001');

$creditNote = new InvoiceCreditNote(
    date: now()->format('Y-m-d'),
    amount: 25400.0,
);
$invoice->addCreditNote($creditNote);

$result = $client->payInvoice($invoice);

use NETipar\Szamlazzhu\Enums\LookupType;

// By invoice number (default)
$result = $client->getInvoiceData('E-PREFIX-2026-001');

// By order number
$result = $client->getInvoiceData('ORD-123', LookupType::OrderNumber);

// By external invoice id
$result = $client->getInvoiceData('EXT-77', LookupType::ExternalId);

if ($result->isSuccess()) {
    $data = $result->toArray();
}

use Illuminate\Support\Facades\Storage;
use NETipar\Szamlazzhu\Enums\LookupType;

$result = $client->getInvoicePdf('E-PREFIX-2026-001');

// By external invoice id
$result = $client->getInvoicePdf('EXT-77', LookupType::ExternalId);

$pdf = $result->toPdf();

if ($pdf) {
    Storage::put('invoices/E-PREFIX-2026-001.pdf', $pdf);
}

use NETipar\Szamlazzhu\Enums\LookupType;

// By receipt number (default)
$result = $client->getReceiptData('NYGTA-2026-1');

// By order number
$result = $client->getReceiptData('ORD-123', LookupType::OrderNumber);

if ($result->isSuccess()) {
    $data = $result->toArray();
}

$result = $client->getReceiptPdf('NYGTA-2026-1');
$pdf = $result->toPdf();

if ($pdf) {
    Storage::put('receipts/NYGTA-2026-1.pdf', $pdf);
}

// Pass the first 8 digits of the tax number
$result = $client->getTaxPayer('12345678');

if ($result->isSuccess()) {
    $data = $result->toArray();
}

use NETipar\Szamlazzhu\Enums\LookupType;

// By proforma number (default)
$result = $client->deleteProforma('D-PREFIX-2026-001');

// By order number
$result = $client->deleteProforma('REND-2026-001', LookupType::OrderNumber);

$result->isSuccess();         // bool
$result->isFailed();          // bool
$result->getDocumentNumber(); // string|null
$result->getPdfFile();        // string|null (binary PDF)
$result->toPdf();             // string|null (alias)
$result->toArray();           // array|null
$result->toJson();            // string|null
$result->toXml();             // string|null
$result->getErrorMsg();       // string|null
$result->getErrorCode();      // int|null

use NETipar\Szamlazzhu\Exceptions\SzamlazzhuException;
use NETipar\Szamlazzhu\Exceptions\ConnectionException;
use NETipar\Szamlazzhu\Exceptions\ResponseException;
use NETipar\Szamlazzhu\Exceptions\ValidationException;
use NETipar\Szamlazzhu\Exceptions\XmlBuildException;

try {
    $result = $client->generateInvoice($invoice);
} catch (ConnectionException $e) {
    // Network / connection error
} catch (ResponseException $e) {
    // API response error
} catch (ValidationException $e) {
    // Input validation error
} catch (XmlBuildException $e) {
    // XML generation error
} catch (SzamlazzhuException $e) {
    // Base exception (catches all above)
}

$buyer = new Buyer(
    name: 'Company Name',
    zipCode: '1234',
    city: 'Budapest',
    address: 'Street 1.',
);

// Direct property access
$buyer->taxNumber = '12345678-1-42';
$buyer->email = '[email protected]';

// Or fluent setters (chainable)
$buyer->setPhoneNumber('+36201234567')->setComment('Note');
bash
php artisan vendor:publish --tag=szamlazzhu-config
bash
php artisan vendor:publish --tag=szamlazzhu
bash
php artisan vendor:publish --tag=szamlazzhu-migrations
php artisan migrate