adruvo / einvoice-sk
Slovak e-invoices (eFaktúra 2027) in PHP: create, validate, import and send Peppol BIS Billing 3.0.
Requires
- php: ^8.2
- ext-dom: *
- ext-libxml: *
- ext-xmlreader: *
- brick/math: ^0.12 || ^0.13 || ^0.14 || ^0.15 || ^0.16 || ^0.17 || ^0.18 || ^0.19 || ^0.20 || ^1.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.64
- phpstan/phpstan: ^2.0
- phpstan/phpstan-strict-rules: ^2.0
- phpunit/phpunit: ^10.5 || ^11.0 || ^12.0
Suggests
- intragile/php-einvoicing: Complete official Peppol validation in pure PHP (PHP 8.3+)
Provides
None
Conflicts
- intragile/php-einvoicing: <1.3 || >=1.4
Replaces
None
README
Slovenská verzia | Try the online validator
Slovak e-invoices (eFaktúra 2027) in PHP. Create, check, import and send Peppol BIS Billing 3.0 invoices without reading XML specifications.
composer require adruvo/einvoice-sk
Status: 0.4. The API may change before 1.0.
use Adruvo\EInvoice\EInvoice; use Adruvo\EInvoice\Model\{Address, Party, Vat}; $supplier = new Party('Dodávateľ s.r.o.', new Address('Hlavná 1', 'Košice', '04001'), dic: '2020000004', ico: '12345678', icDph: 'SK2020000004'); $customer = new Party('Odberateľ a.s.', new Address('Dlhá 5', 'Žilina', '01001'), dic: '2020000015', ico: '87654321', icDph: 'SK2020000015'); $invoice = EInvoice::make() ->number('20270001') ->supplier($supplier) ->customer($customer) ->orderReference('OBJ-42') ->addItem('Web development', 1, 500, Vat::rate(23)) ->dueDate('2027-01-30'); // Every method returns a new builder, so a half-filled one is a safe template. $invoice->validate()->messages('en'); // readable errors, in Slovak or English $xml = $invoice->toXml();
What it does
- Invoices, credit notes, corrected, prepayment and self-billed invoices with exact decimal totals.
- Readable errors in Slovak and English, with the official rule number and the place of the problem.
- Every Peppol field. The common ones have methods, all others work by their official path:
->field('ContractDocumentReference/ID', 'Z-12'). For an item useaddItem(..., fields: ['Item/SellersItemIdentification/ID' => 'SKU-1']). - XML import without losses.
EInvoice::fromXml($xml)->differenceslists totals that do not match and anything outside Peppol. - Readable invoice for print or PDF:
toHtml(). - JSON.
toJson()andEInvoice::fromJson(). - Sending and receiving through any provider (digitálny poštár) that supports SAPI-SK.
- Attachments.
->attach(Attachment::fromFile('report.pdf')). - Recipient check.
(new ParticipantLookup())->canReceive($customer)asks the Peppol network, no account needed. - Slovak units.
ks,hodorm2become the official codes. - Tests without a provider.
FakeProvideranswers like a real one, in memory. - Laravel and Symfony packages.
Requires PHP 8.2+ with ext-dom and ext-xmlreader. The only dependency is brick/math.
Sending
$sapi = new SapiClient('https://your-provider.example/sapi', $clientId, $clientSecret); $sapi->send($invoice->build()); foreach ($sapi->inbox('0245:2020000004') as $document) { $xml = $sapi->download('0245:2020000004', $document->id); // store it, then: $sapi->acknowledge('0245:2020000004', $document->id); }
For more companies use one client and switch the account: $sapi->withAccount($clientId, $clientSecret)->send($invoice). It works the same in Laravel and Symfony.
In your tests replace the provider:
$sapi = new SapiClient('https://fake.test', 'id', 'secret', $provider = new FakeProvider()); $sapi->send($invoice->build()); $provider->sent[0]; // XML // Laravel: $this->app->instance(Transport::class, $provider);
When there is no response, or the provider marks an error as retryable, the client repeats the request with the same idempotency key. Sending the same invoice again within 24 hours is safe too: you get the original identifier and it is not delivered twice.
During a longer outage new OutageGuard($transport, $sharedStore) fails quickly instead of waiting for every request. Pass it to SapiClient as the transport.
Delivery status
SAPI-SK only confirms that the provider took the document. The delivery status comes from the interface of each provider:
$id = $sapi->send($invoice->build()); $check = new EfakturaStatus($apiKey, $organizationId); // eFaktúra.sk $check = new EpostakStatus($sapi, 'https://dev.epostak.sk/api/v1'); // ePošťák $check = new EfakturujStatus($sapi, '0245:2020000004'); // eFakturuj $check->check($id)->state; // Pending, Delivered or Failed
For another provider implement StatusCheck.
At ePošťák the customer can also answer: $check->respond($id, InvoiceStatus::Rejected, 'Wrong price'). The supplier reads it with $check->responses($id).
eFaktúra.sk and ePošťák can also call you: $check->registerWebhook($url, $events) returns the secret and Webhook::isValid($body, $signature, $timestamp, $secret) checks that the call is really theirs.
Companies of your customers
When you send for other companies, you can add them from your application:
$accounts = new EfakturaAccounts($partnerKey); // eFaktúra.sk $id = $accounts->add($party); $accounts->register($id, $codeFromFinancialAdministration); $accounts = new EpostakAccounts($sapi, 'https://dev.epostak.sk/api/v1'); // ePošťák $link = $accounts->invite('2020000004', youPay: false); // the owner confirms there $accounts->all(); // both
Official validation without Java
OfficialValidator runs the official Peppol rules, release 3.1.0 with the Slovak rules, in pure PHP (8.3+):
composer require intragile/php-einvoicing:~1.3.0
vendor/bin/einvoice-rules var/peppol-rules
$validator = new OfficialValidator('var/peppol-rules'); $validator->validate($invoice->build()); $validator->validateXml($xml); // any UBL invoice
Errors are in Slovak too, except the national rules of other countries.
On every change, CI checks that it reports the same rules as the reference processor (Saxon) for a set of correct and wrong invoices.
Laravel and Symfony
composer require adruvo/einvoice-sk-laravel
composer require adruvo/einvoice-sk-bundle # Symfony
The Laravel package is discovered automatically. Set EINVOICE_SAPI_URL, EINVOICE_SAPI_CLIENT_ID and EINVOICE_SAPI_CLIENT_SECRET.
The Symfony bundle is configured in config/packages/einvoice.yaml:
einvoice: sapi: {url: '%env(SAPI_URL)%', client_id: '%env(SAPI_ID)%', client_secret: '%env(SAPI_SECRET)%'}
Both add the command einvoice:validate invoice.xml and let you inject SapiClient and Validator.
Limits
- The built-in check runs everywhere without setup and explains errors in plain Slovak or English. It covers the most common rules. For all official rules add the optional
OfficialValidator, which runs both. - The SAPI-SK client follows the published specification. Sending and receiving were tested in the sandboxes of eFaktúra.sk and ePošťák, not in production. The delivery status at eFakturuj and webhook registration at eFaktúra.sk follow their documentation and were not yet tried live.
- This is not tax advice.
Recipes for common cases (in Slovak): docs/navod.md. Design decisions: docs/architecture.md. Licence: MIT.