Overview
TheInvoice class is the heart of PHP FacturaE. It provides a fluent API for building compliant FacturaE XML documents with automatic validation, tax calculation, and digital signing capabilities.
Creating an Invoice
Every invoice starts withInvoice::create() which accepts the invoice number as a required parameter:
->date() method.
The invoice number is immutable after creation. Series prefixes should be set using
->series() rather than including them in the number.Core Configuration
Series and Dates
Invoice Series
Group related invoices with a series prefix:Series are optional but recommended for organizing invoices by type, client, or accounting period.
Schema and Type
Specify the FacturaE schema version and invoice type:Schema Versions:
Schema::V3_2- Original FacturaE 3.2Schema::V3_2_1- Updated schema with minor changesSchema::V3_2_2- Latest version (recommended)
Invoice Types:
InvoiceType::Full(FC) - Complete invoice with all detailsInvoiceType::Simplified(FA) - Simplified invoice (tickets)InvoiceType::SimplifiedRectified(AF) - Corrective simplified invoice
Currency and Description
Parties
Every invoice requires a seller and buyer:Lines and Taxes
Add invoice lines with automatic tax calculation:Payments
Define payment terms and methods:General Discounts and Charges
Apply invoice-level discounts or charges:Corrective Invoices
Create corrective invoices that reference original invoices:Attachments
Attach supporting documents to the invoice:Exporting to XML
Generate the FacturaE XML document:InvoiceValidationException is thrown with detailed error messages.
Digital Signing
Sign invoices with XAdES-EPES signatures:Validation
Validation happens automatically when calling->toXml() or ->export(). The validator checks:
- Required fields (seller, buyer, at least one line)
- Tax number formats (Spanish NIFs/CIFs)
- Postal code validation
- Date consistency
- Payment amounts
- Schema-specific requirements
Method Reference
Invoice Configuration
| Method | Parameters | Returns | Description |
|---|---|---|---|
create() | string $number | Invoice | Static constructor |
series() | string $series | self | Set invoice series |
date() | string|DateTimeImmutable $date | self | Set issue date |
operationDate() | string|DateTimeImmutable $date | self | Set operation date |
billingPeriod() | string|DateTimeImmutable $from, $to | self | Set billing period |
schema() | Schema $schema | self | Set FacturaE version |
type() | InvoiceType $type | self | Set invoice type |
currency() | string $currency | self | Set currency (ISO 4217) |
description() | string $description | self | Set description |
Parties and Lines
| Method | Parameters | Returns | Description |
|---|---|---|---|
seller() | Party $seller | self | Set seller party |
buyer() | Party $buyer | self | Set buyer party |
line() | See Lines and Taxes | self | Add invoice line |
exemptLine() | See Lines and Taxes | self | Add exempt line |
customLine() | See Lines and Taxes | self | Add line with custom taxes |
Payments
| Method | Parameters | Returns | Description |
|---|---|---|---|
transferPayment() | string $iban, ?string $dueDate, ?float $amount | self | Add bank transfer payment |
cashPayment() | ?string $dueDate, ?float $amount | self | Add cash payment |
cardPayment() | ?string $dueDate, ?float $amount | self | Add card payment |
directDebitPayment() | string $iban, ?string $dueDate, ?float $amount | self | Add direct debit payment |
splitPayments() | See Payments | self | Split into installments |
Export and Signing
| Method | Parameters | Returns | Description |
|---|---|---|---|
sign() | InvoiceSigner $signer | self | Set digital signer |
toXml() | None | string | Generate XML string |
export() | string $path | self | Export to file |
Source Reference
The complete Invoice class implementation can be found at:src/Invoice.php:25-602- Main Invoice classsrc/Enums/Schema.php:7-31- Schema enumerationsrc/Enums/InvoiceType.php:7-18- Invoice type enumeration