PHP SDK · Beta on Packagist · v1.0 1 Dec

PHP local e-invoice SDK (wsystem/einvoice)

Build XRechnung 3.0, EN 16931 UBL/CII and ZUGFeRD / Factur-X PDF/A-3b invoices directly in PHP 8.1+ using the exact same JSON/array input shape as POST /einvoice/create.

Status: wsystem/einvoice is available as a beta on Packagist (v0.9.0-beta.2, Apache-2.0); v1.0 is planned for 1 Dec 2026. Need the hosted W System API from PHP today? Use wsystem/wsystem-php (MIT, live on Packagist).

Quickstart

Requires PHP ≥ 8.1 with ext-dom, ext-libxml, ext-mbstring, ext-zlib and setasign/fpdf (MIT). Decimal totals use bcmath / explicit decimal rounding so line sums match the API.

composer
composer require wsystem/einvoice:^0.9@beta
# Optional: also install the hosted API client for VIES VAT checks & Peppol routing
composer require wsystem/wsystem-php
create-zugferd.php
<?php
use WSystem\EInvoice\EInvoice;
use WSystem\EInvoice\Validator\CoreRulesValidator; // pre-check only; use SaxonC/Command/Http for full conformance

$einvoice = new EInvoice(new CoreRulesValidator());

$result = $einvoice->create([
    'format' => 'zugferd',           // en16931 | xrechnung | cii | xrechnung-cii | zugferd | factur-x | zugferd-xrechnung
    'invoice_number' => 'INV-2026-001',
    'issue_date' => '2026-11-25',
    'currency' => 'EUR',
    'seller' => ['name' => 'Example GmbH', 'country' => 'DE', 'vat_id' => 'DE123456789'],
    'buyer'  => ['name' => 'Kunde AG', 'country' => 'DE', 'buyer_reference' => '04011000-12345-03'],
    'lines'  => [['name' => 'Consulting', 'quantity' => 1, 'unit_price' => '100.00', 'vat_rate' => '19']],
]);

file_put_contents($result['pdf_filename'], $result['pdf']);
file_put_contents('invoice.xml', $result['xml']);

Supported formats

Format keySyntaxOutput
en16931UBL 2.1EN 16931 Invoice / CreditNote (type_code: 381)
xrechnungUBL 2.1XRechnung 3.0 UBL
cii / xrechnung-ciiUN/CEFACT CII D16BEN 16931 or XRechnung 3.0 CII
zugferd / factur-xPDF/A-3b + CIIHybrid PDF/A-3b with embedded factur-x.xml (EN 16931 COMFORT)
zugferd-xrechnungPDF/A-3b + CIIHybrid PDF/A-3b with embedded xrechnung.xml (XRECHNUNG)
peppol-bis3UBL 2.1Peppol BIS Billing 3.0 structure (checked on EN 16931 only; Peppol rules not run)

Validation backends & rules matrix

Important conformance rule: by default, when no Schematron backend is installed or configured, wsystem/einvoice runs native XML Schema (Xsd) plus pure-PHP CoreRules and reports checked.EN16931 = "core-subset". CoreRules is a fast pre-check only and makes no claim of full EN 16931 or XRechnung conformance. Full official EN 16931 / XRechnung conformance requires an XSLT 2.0 / Schematron backend: optional SaxonC (ext-saxon), the self-hosted W System validator (Command / local Http), or the hosted W System API (Http).

BackendWhat it runsOfflineExact = officialDefault
Xsd (libxml, ext-dom)UBL 2.1 / CII D16B XSDYesYes (XSD syntax)Always on
SaxonC (SaxonC-HE 12/13 PHP extension, MPL-2.0, optional)Official compiled KoSIT / CEN EN 16931 XSLTs (same files as W System API)YesYes, identical to API / KoSITAuto when saxon ext is loaded
Command (local process: self-hosted W System validator Docker/CLI or KoSIT Java jar)Official EN 16931 + KoSIT XRechnung rulesYesYesOpt-in
Http (self-hosted W System validator container on localhost, or hosted api.wsystem.dev)Official EN 16931 + KoSIT XRechnung rulesContainer: yes / Hosted: noYesOpt-in, never silent
CoreRules (pure PHP)Hand-ported core EN 16931 rules: mandatory BTs, BR-CO totals arithmetic, VAT breakdown + category rules S/Z/E/AE/K/G/O, key BR-DE (XRechnung)YesNo: fast pre-check only; reports checked.EN16931 = "core-subset"Fallback when no Schematron backend

Relationship to wsystem/wsystem-php

wsystem/einvoice is a standalone Apache-2.0 package with the pinned KoSIT/CEN rule artefacts; the existing wsystem/wsystem-php HTTP client stays zero-dependency MIT. Use both together when you want local invoice generation plus hosted VIES VAT checks, sanctions screening and Peppol routing.

Licences, third-party notices and scope

  • W System toolkit code: wsystem/einvoice (PHP SDK) and wsystemdev/einvoice-validator (free CLI and container) are licensed under Apache-2.0. wsystemdev/einvoice-validate-action v1 is MIT-licensed.
  • CEN/TC 434 EN 16931 artefacts (v1.3.16): included unmodified under the European Union Public Licence (EUPL-1.2) with upstream CEN notices preserved (ConnectingEurope/eInvoicing-EN16931).
  • KoSIT XRechnung configuration (3.0.2 / 2026-08-31) and Schematron (2.4.0): included unmodified under Apache-2.0 with KoSIT NOTICE pass-through (itplr-kosit/validator-configuration-xrechnung).
  • Saxon-HE (saxonche / SaxonC-HE): Mozilla Public License 2.0 (MPL-2.0).
  • Peppol BIS Billing 3.0 rules: PEPPOL-EN16931-* rules are not shipped (pending OpenPeppol IPR clearance). Output marks PeppolBIS3: false.

Disclaimer: technical validation and document generation against the official EN 16931 and XRechnung rule sets. A technically valid file is not tax or legal advice.