Overview
This guide walks you through creating a complete, working invoice from start to finish. You’ll learn how to:- Set up seller and buyer information
- Add invoice lines with VAT
- Configure payment methods
- Export the invoice to a file
Full Working Example
Here’s a complete invoice ready to copy and use:The invoice will be automatically validated before export. If there are any errors (missing seller, buyer, or lines), an
InvoiceValidationException will be thrown.Step-by-Step Breakdown
Let’s break down each component of the invoice:Create Invoice Base
Start by creating the invoice with a unique number and optional series:
- Number: Unique identifier for the invoice (required)
- Series: Optional grouping (e.g., ‘A’, ‘B’, or ‘R’ for rectificative)
- Date: Issue date in
YYYY-MM-DDformat orDateTimeImmutableobject
Define the Seller
Add your company information as the seller:
Use
Party::company() for legal entities (B2B) or Party::person() for individuals (B2C).Define the Buyer
Add the customer information:For a person, provide:
- Tax number (NIF/NIE)
- First name
- First surname
- Second surname (optional)
Add Invoice Lines
Add one or more invoice lines with description, price, and VAT:The line method accepts:
- description: Service or product description
- price: Unit price (excluding VAT)
- quantity: Units (defaults to 1)
- vat: VAT percentage (21%, 10%, 4%, etc.)
Set Payment Method
Configure how the invoice will be paid:Available payment methods:
transferPayment()- Bank transfercashPayment()- Cash paymentcardPayment()- Card paymentdirectDebitPayment()- Direct debit (domiciliación)
Multiple Lines Example
Most invoices have multiple lines. Here’s how to add several items:Line Discounts
You can apply discounts at the line level:VAT-Only XML Output
If you need the XML as a string instead of exporting to a file:Validation Errors
The library validates your invoice before export. Common validation errors:Next Steps
Canary Islands IGIC
Learn how to use IGIC tax instead of VAT
Split Payments
Configure multiple payment installments
Public Administration
Invoice with DIR3 codes for FACe
Payment Methods
Explore all 19 payment methods