# Introduction

PHP FacturaE is a modern, typed library to generate, validate and sign electronic invoices in the FacturaE format — the official electronic invoicing standard in Spain.

What is FacturaE?

FacturaE is the XML-based electronic invoice format required by the Spanish Public Administrations (AAPP) and widely adopted in the private sector. It is managed by the Spanish tax agency (AEAT) and guarantees tax compliance and interoperability.

Why PHP FacturaE?

PHP FacturaE provides a fluent, typed API that makes building compliant invoices intuitive and error-free:

Invoice::create('FAC-001')
->series('A')
->date('2025-03-01')
->seller(Party::company('B12345678', 'My Company S.L.')
->address('C/ Mayor 10', '28013', 'Madrid', 'Madrid'))
->buyer(Party::person('12345678Z', 'Laura', 'Gómez', 'Ruiz')
->address('C/ Sol 3', '28012', 'Madrid', 'Madrid'))
->line('Logo design', price: 450.00, vat: 21)
->transferPayment(iban: 'ES91 2100 0418 4502 0005 1332', dueDate: '2025-03-31')
->export('invoice.xml');

Key features

  • Fluent API with Enums — No associative arrays or loose constants — everything typed with PHP 8.2+ enums and readonly properties
  • XAdES-EPES digital signature — Native support for PKCS#12 (.pfx) and PEM certificates with optional TSA time-stamping
  • XSD validation — Automatic validation against the official FacturaE 3.2, 3.2.1 and 3.2.2 schemas
  • Zero dependencies — Only standard PHP extensions: ext-openssl, ext-dom — no external packages

Full tax support

  • 29 tax types including VAT, IRPF, IGIC, equivalence surcharge and excise duties
  • 19 payment methods from wire transfer to card and direct debit
  • 36 units of measure from units to kWh and hours
  • 22 correction reasons for corrective invoices

Performance

  • ~0.2 ms per simple invoice
  • ~22 ms for 100 invoices
  • Efficient XML generation with minimal memory footprint

Use cases

  • SaaS platforms generating invoices for Spanish customers
  • E-commerce needing FacturaE format for B2B sales
  • Accounting software with FACe/FACeB2B integration
  • Freelancers and agencies invoicing the Public Administration

Architecture

The library is organized in focused namespaces:

  • Invoice — Main entry point with fluent API
  • Party — Seller/buyer entities (companies and individuals)
  • Entities/ — Lines, payments, attachments, tax breakdown, addresses
  • Enums/ — Tax types, payment methods, invoice types, correction reasons
  • Exporter/ — XML generation
  • Signer/XAdES-EPES digital signature
  • Validation/Schema validation

Every class uses readonly properties and strict types (PHP 8.2+) for maximum safety and IDE autocompletion support.