Download the PHP package vimatech/laravel-einvoicing without Composer
On this page you can find all versions of the php package vimatech/laravel-einvoicing. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download vimatech/laravel-einvoicing
More information about vimatech/laravel-einvoicing
Files in vimatech/laravel-einvoicing
Package laravel-einvoicing
Short Description Native Peppol BIS 3.0 (UBL) and EN 16931 (CII) e-invoice generation and dispatch for Laravel. Zero third-party runtime dependencies.
License MIT
Homepage https://github.com/vimatech-io/laravel-einvoicing
Informations about the package laravel-einvoicing
Structured e-invoices for Laravel, generated natively
Generate structured e-invoices natively (Peppol BIS Billing 3.0 UBL and EN 16931 CII) for Laravel 11, 12 and 13, and dispatch them through pluggable networks (Peppol access points, French PDPs), with per-country routing.
Zero third-party runtime dependencies. Every document is built with PHP's own
ext-dom; every network call uses Laravel's own HTTP client. Nohorstoeko/zugferd, no UBL libraries, no PDF libraries. This is a deliberate security & maintenance policy.
Features
- Native generators: Peppol BIS Billing 3.0 (UBL invoice + credit note) and EN 16931 CII,
emitted directly with
DOMDocument. Factur-X (PDF/A-3) is stubbed for a later isolated module. - Neutral domain model: a single
CanonicalInvoiceDTO; no format or vendor concept ever leaks into your application. - Pluggable networks:
PeppolDriver,FrPdpDriver,NullDriver,FakeDriver, plus your own. - Per-country routing: map destination countries to networks, with a fallback and a per-tenant override hook.
- Profile-scoped validation: mandatory-field and arithmetic checks fail fast with actionable messages before anything is rendered or transmitted. The EN 16931 core applies to every document; the extra rules of a CIUS apply only when that profile is the one being emitted. Arithmetic checks run at the currency's scale and allow two of its smallest units (0.02 at two decimals) to absorb per-line rounding.
- No silent rounding: a value that its XML field cannot carry is refused with an
InvalidInvoicenaming the business term, never rounded into one that fits. - Lifecycle events:
EInvoiceGenerated,EInvoiceDispatched,EInvoiceDelivered,EInvoiceRejected,EInvoiceReceived.
Requirements
- PHP 8.3+
- Laravel 11, 12 or 13
- Extensions:
ext-dom,ext-mbstring
Installation
Publish the config (optional):
Quick start
1. Build a canonical invoice
The CanonicalInvoice is the only model you ever construct. It is format- and network-agnostic.
Document totals (line extension, tax exclusive/inclusive, payable) are derived from the lines and the VAT breakdown: you do not pass them in.
Precision and currency scale
Values are rendered at the precision they carry, and refused rather than rounded when a field cannot hold them:
| Field | Rendered as | Refused when |
|---|---|---|
| Amounts (BT-106 to BT-117, BT-131) | exactly 2 decimals | the value has a third decimal (EN 16931 BR-DEC) |
| Unit price (BT-146) | 2 to 6 decimals, trailing zeros trimmed | the value has a seventh decimal |
| VAT rate (BT-119, BT-152) | 2 to 4 decimals, trailing zeros trimmed | the value has a fifth decimal |
Floats built from exact decimals are accepted as those decimals: 0.1 + 0.2 renders as 0.30.
The derived totals and the arithmetic checks are rounded at two decimals by default. Pass
amountDecimals, the ISO 4217 minor unit of the currency as you fixed it when issuing, to use
another scale:
This governs the model, not the XML: a UBL or CII document still refuses an amount with a real third
decimal, so a TND invoice of 1.235 cannot be emitted, while a JPY invoice renders its whole amounts
as 1000.00.
2. Generate a UBL (Peppol BIS 3.0) document
A credit note is the same call with typeCode: CanonicalInvoice::TYPE_CREDIT_NOTE: the
generator switches to the CreditNote root and CreditedQuantity automatically. Generate CII
with Format::Cii.
Name the invoice a credit note corrects with precedingInvoiceReference (EN 16931 group BG-3):
It becomes cac:BillingReference/cac:InvoiceDocumentReference in UBL and
ram:InvoiceReferencedDocument in CII. EN 16931 leaves the group optional, so the package does not
require it, but a credit note that names no preceding invoice is rejected by the profiles that do,
including the French PDP rules. The same field is valid on a 380 invoice, where it points at the
partial or pre-payment invoices a final invoice completes.
If a mandatory field is missing or the arithmetic does not balance, generation throws
InvalidInvoice, which carries the full list of violations:
Which rules run depends on what is being emitted. Format::Cii carries the plain EN 16931 guideline
identifier and is validated against the core alone; Format::Ubl carries the Peppol BIS Billing 3.0
customization identifier and additionally enforces the Peppol rules: electronic addresses for both
parties, and PEPPOL-EN16931-R003, which requires a buyer reference (BT-10) or a purchase order
reference (BT-13). Both terms are optional in the core standard, so neither is required of a CII
document.
Validate against a profile without generating anything:
Reach for ValidationProfile::PeppolBis on a CII document when you transmit it through Peppol, or
to a CIUS that carries the same requirement: XRechnung enforces the buyer reference through
BR-DE-15, and Chorus Pro requires a service code or an engagement number for the public entities
whose directory entry demands one.
3. Send through a network
send() renders the document, routes it by the buyer's country, transmits it, and fires the
lifecycle events:
Force a format or a specific network:
Resolve a network yourself:
Transmit the stored document
send() renders the invoice again before transmitting it. To transmit the exact file you stored
when the invoice was issued, rebuild the GeneratedDocument from it and pass it to transmit():
fromStored() sets the MIME type, profile and file name generate() would have set, and refuses
contents that are not a document of that format carrying that invoice number. transmit() routes
with the CanonicalInvoice, refuses a document issued for another invoice number, and fires the
same events as send(); EInvoiceGenerated is not fired, since nothing is generated.
send() and transmit() always fire EInvoiceDispatched. EInvoiceDelivered fires only for Delivered and
Accepted, EInvoiceRejected only for Rejected and Failed. A queued submission, a document
still in transit, or a status your status_map does not cover fires neither: poll fetchStatus()
rather than treating the absence of a delivery as a refusal.
4. Receive inbound documents
Bodies arrive base64-encoded. A body that is absent, that is not valid base64, or that decodes to
nothing raises NetworkException naming the offending message id, and the whole batch stops: the
package will not hand your application a document it could not decode. If your partner returns
unencoded bodies, extend the driver and override decodeInbound(); do not make it accept both,
since the two cannot be told apart and the wrong guess silently yields a corrupt invoice.
Each InboundDocument carries a format. A format the partner declares that is a value of Format
is used as declared. Otherwise it is read from the decoded contents, never assumed: a body starting
with %PDF- is Format::FacturX; an XML document whose root is CrossIndustryInvoice in the CII
namespace is Format::Cii; a root Invoice or CreditNote in its UBL namespace is Format::Ubl.
A root with the right name but no namespace, or another namespace, is not taken for either. If you
branch on $inbound->format, handle Format::FacturX.
A document whose format can be neither read from the declaration nor recognised in its contents is not
returned. It is reported to your exception handler as Vimatech\EInvoicing\Exceptions\UnrecognisedInboundDocument
(properties network, messageId, declaredFormat and raw, the provider's entry with its body still
encoded), and the other documents of the batch are returned as usual. To keep or alert on them:
This applies to peppol, fr_pdp, and an AbstractHttpDriver subclass referenced by class, provided
its constructor, if it defines one, accepts the fourth argument (an ExceptionHandler) and passes it
to parent::__construct(). A driver left without an exception handler (built by hand, in an
extend() factory, or by a constructor that drops the argument) throws the exception instead, which
stops the batch.
Configuration
config/einvoicing.php declares the available networks, the country → network routing
table, and the default format. Credentials come from the environment.
HTTP drivers read base_url, token, auth, timeout, headers, verify, paths and
status_map. A setting that is present but cannot be read as the type it needs raises
InvalidDriverConfig rather than being ignored, and environment strings such as "120" and
"false" are understood: a value you set is either applied or reported, never dropped.
Adapting a built-in driver to your partner
PeppolDriver and FrPdpDriver speak a small, neutral REST shape. Point them at your access
point / PDP by overriding paths and, where the vocabulary differs, status_map, no code change needed:
A missing or empty token is refused: an unauthenticated request to an accredited platform is
rejected without a reason you can act on. When your partner authenticates another way (mutual
TLS, a signed header), declare it, and configure no token:
Adding a country
Add a row to the routing map pointing at any configured network key:
Unmatched countries throw UnsupportedCountry unless a fallback network is set.
Per-tenant routing override
Register a resolver in a service provider to override routing per tenant or per invoice.
Returning a network key wins over the static map; returning null defers to it. The router is a
singleton, so the resolver lives for the whole process: under Octane, registering it inside a
request leaks it to every later request on that worker. Resolve the tenant inside the closure, as
below, rather than closing over one:
Adding a driver
Implement EInvoiceNetwork (or extend AbstractHttpDriver for a REST partner), keeping every
vendor concept inside the driver:
Reference it by class in config (it is resolved from the container):
Or register a factory for a driver alias at runtime. extend() is keyed by the driver name,
so the network entry must name that alias:
Testing with the FakeDriver
A dependency-free FakeDriver is shipped for your test suite. Swap any network for it and
assert against what was sent, no HTTP, no credentials:
FakeDriver also supports pushInbound() for receive() flows, the inspection API
(sent(), sentCount(), hasSent(), lastSent()) and the assert* helpers.
Conformance & testing notes
- Profiles emitted: Peppol BIS Billing 3.0,
CustomizationIDurn:cen.eu:en16931:2017#compliant#urn:fdc:peppol.eu:2017:poacc:billing:3.0,ProfileIDurn:fdc:peppol.eu:2017:poacc:billing:01:1.0. CII carries the EN 16931 guidelineurn:cen.eu:en16931:2017. - Scope: only the subset of business terms required for the supported fields is emitted, in the UBL 2.1 / CII sequence order. Document-level allowances/charges and multi-currency VAT accounting are intentionally out of scope for this release.
- Golden files: UBL output is asserted byte-for-byte against committed golden samples
(
tests/fixtures/peppol/) shaped after the official Peppol BIS 3.0 examples, plus structural XPath assertions for identifiers and balancing totals. - Recommended external validation: before production, run generated XML through the official Peppol BIS / EN 16931 validator or the CEN Schematron. Native validation here is a fast pre-flight, not a substitute for the Schematron.
Run the suite:
Architecture
Dtos/: readonly value objects (the neutral model).Formats/: nativeDOMDocumentgenerators + validation.Networks/: drivers + the config-drivenNetworkManager.Routing/:EInvoiceRouter(country map + fallback + override hook).Events/,Exceptions/,Facades/: the glue.
Contributing
Contributions are welcome.
Please ensure:
- Tests pass (
composer test) - PHPStan passes (
composer analyse) - Code style is formatted with Pint (
composer format)
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our Security Policy for reporting vulnerabilities.
License
The MIT License (MIT). Please see License File for more information.
Credits
Built and maintained by Vimatech. Created by Adel Zemzemi, Laravel SaaS architect.
All versions of laravel-einvoicing with dependencies
ext-dom Version *
ext-mbstring Version *
illuminate/support Version ^11.0 || ^12.0 || ^13.0
illuminate/contracts Version ^11.0 || ^12.0 || ^13.0
illuminate/http Version ^11.0 || ^12.0 || ^13.0