Documentation Index
Fetch the complete documentation index at: https://mintlify.com/Eseperio/verifactu-php/llms.txt
Use this file to discover all available pages before exploring further.
What is Verifactu?
Verifactu (VERI*FACTU) is Spain’s mandatory digital invoice control system operated by the Agencia Estatal de Administración Tributaria (AEAT). It requires businesses using invoicing software to submit every invoice record to AEAT in near-real time, producing an auditable, tamper-evident chain of electronic invoices. Each invoice submitted to AEAT receives a CSV (Código Seguro de Verificación) — a unique reference code that proves the invoice was registered with the Spanish tax authority. Invoices must also display a QR code linking to AEAT’s verification portal so recipients can confirm authenticity. The system enforces:- Cryptographic chaining — every invoice hash references the previous record’s hash, creating an immutable sequence
- XML digital signatures — documents are signed with an accredited certificate (XAdES Enveloped)
- SOAP communication — submissions use AEAT’s official SOAP/WSDL endpoints
- Strict schema validation — all fields are validated against AEAT’s published XSD schemas
What this library does
eseperio/verifactu-php is a complete, object-oriented PHP 8.1+ integration layer for the VERI*FACTU system. It handles the entire technical workflow described in AEAT’s regulatory specification:
- Build strongly-typed invoice models that map directly to AEAT’s XSD schema
- Auto-generate the SHA-256 hash (“huella”) for each invoice record
- Serialize models to AEAT-compliant XML
- Digitally sign the XML block (XAdES Enveloped) using your PKCS#12 certificate
- Transmit the signed XML to AEAT’s SOAP endpoint (production or sandbox)
- Parse the SOAP response into typed PHP objects with human-readable error messages
- Generate AEAT-compliant QR codes for printing on invoices
What this library does NOT do
This is not an invoicing or accounting system. It does not create, store, or manage invoices. It is purely an integration layer — you bring your own invoice data and this library handles the AEAT communication protocol.
- Render PDF invoices or generate invoice documents
- Store invoice data in a database
- Manage invoice numbering or series
- Handle VAT calculations — you compute amounts and pass them in
- Replace your existing ERP or billing system
Key features
Invoice Registration (Alta)
Submit new invoices to AEAT with full hash chaining. Supports all invoice types: standard (F1), simplified (F2), replacement (F3), and rectification (R1–R5).
Invoice Cancellation (Anulación)
Cancel previously submitted invoices via the AEAT SOAP endpoint, with full chaining support for cancellations linked to the previous record hash.
Invoice Querying
Query previously submitted invoices by period, series, date, or counterparty, with paginated results parsed into typed
QueryResponse objects.Auto Hash Generation
SHA-256 hash (“huella”) is automatically computed from the required AEAT field ordering — you never need to implement this yourself.
XML Digital Signing
Built-in XAdES Enveloped XML signature using
robrichards/xmlseclibs. Supports both personal/company certificates (TYPE_CERTIFICATE) and seal certificates (TYPE_SEAL).QR Code Generation
Generate AEAT-compliant QR codes in PNG (via GD or Imagick) or SVG format at any resolution. Output as raw string, base64, or file, using
bacon/bacon-qr-code.Strongly Typed Models
All AEAT schema entities are modelled as PHP classes with full PHPDoc, PHP 8.1 enums for type-safe constants, and a built-in
validate() method with detailed error messages.Dual Environment Support
Toggle between
ENVIRONMENT_PRODUCTION and ENVIRONMENT_SANDBOX with a single config parameter. The library automatically selects the correct SOAP endpoint and QR verification URL.Official Error Translation
All AEAT error codes are mapped to human-readable descriptions using the official AEAT code dictionary bundled in
src/dictionaries/ErrorRegistry.php.Event Notifications
Submit system-level events (
EventRecord) to AEAT as required by the regulation, via the dedicated EventDispatcherService.Requirements
PHP version
This library requires PHP 8.1 or higher. It makes use of PHP 8.1 features including backed enums,readonly properties, and never return types.
Required PHP extensions
The following PHP extensions must be enabled:| Extension | Purpose |
|---|---|
ext-soap | SOAP client for communicating with AEAT endpoints |
ext-libxml | XML document parsing and generation |
ext-openssl | Certificate loading and cryptographic operations |
ext-dom | DOM manipulation for XML signing |
Composer dependencies
These packages are automatically installed when you runcomposer require eseperio/verifactu-php:
| Package | Version | Purpose |
|---|---|---|
bacon/bacon-qr-code | ^3 | QR code generation (PNG, SVG, Imagick) |
robrichards/xmlseclibs | ^3.0 | XAdES XML digital signature |
vlucas/phpdotenv | ^5.5 | .env file loading for certificate config |
Dev dependencies
| Package | Purpose |
|---|---|
phpunit/phpunit ^10.0 | Unit and integration test suite |
phpstan/phpstan 2.1.x-dev | Static analysis |
What you need from AEAT
To submit invoices to production you need:- A valid digital certificate (
.pfx/.p12) issued by an accredited Spanish certification authority, or an AEAT seal certificate - Your company’s NIF registered in AEAT’s census (Mis datos censales) — the issuer NIF and name must match exactly
prewww1.aeat.es / prewww10.aeat.es.
PSR-4 namespace
All classes live under theeseperio\verifactu\ namespace:
Next steps
Installation
Install via Composer, enable PHP extensions, and verify your setup
Quickstart
Submit your first invoice to the AEAT sandbox in under 10 minutes