fajarsulaksono / ubl-invoice
A PHP wrapper for creating UBL 2.1 XML invoices
v1.0.0
2026-07-30 03:43 UTC
Requires
- php: ^8.1
- illuminate/support: ^10.0 || ^11.0 || ^12.0 || ^13.0
- sabre/xml: ^3.0 || ^4.0
Requires (Dev)
- greenter/ubl-validator: ^2.0
- orchestra/testbench: ^8.0 || ^9.0 || ^10.0 || ^11.0
- phpunit/phpunit: ^10.5 || ^11.0
This package is auto-updated.
Last update: 2026-08-05 02:52:20 UTC
README
A PHP wrapper for creating UBL (Universal Business Language) 2.1 invoices. This package generates valid UBL XML invoices compliant with the OASIS UBL 2.1 standard.
Features
- Generate UBL 2.1 XML invoices
- Full support for invoice lines, tax totals, monetary totals
- Supplier and customer party information (address, contact, legal entity)
- Tax schemes, categories, and subtotals
- Allowances and charges
- Additional document references (e.g., PDF attachments)
- Currency support
- Laravel auto-discovery (ServiceProvider & Facade)
- Well-tested with schema validation
Requirements
- PHP 8.1 or higher
- Laravel 10, 11, 12, or 13 (optional — the library works standalone)
Installation
composer require fajarsulaksono/ubl-invoice
Configuration (Laravel)
The service provider is auto-discovered. If you want to customise the configuration, publish the config file:
php artisan vendor:publish --tag=ubl-invoice-config
Facade
use UBLInvoice; $xml = UBLInvoice::invoice($invoice, 'EUR');
Usage
Standalone
use fajarsulaksono\UBL\Invoice\Invoice; use fajarsulaksono\UBL\Invoice\Generator; use fajarsulaksono\UBL\Invoice\LegalMonetaryTotal; use fajarsulaksono\UBL\Invoice\TaxSubTotal; use fajarsulaksono\UBL\Invoice\Address; use fajarsulaksono\UBL\Invoice\Country; use fajarsulaksono\UBL\Invoice\Party; use fajarsulaksono\UBL\Invoice\Item; use fajarsulaksono\UBL\Invoice\Price; use fajarsulaksono\UBL\Invoice\InvoiceLine; use fajarsulaksono\UBL\Invoice\TaxScheme; use fajarsulaksono\UBL\Invoice\TaxTotal; use fajarsulaksono\UBL\Invoice\TaxCategory; require_once __DIR__ . '/vendor/autoload.php'; $legalMonetaryTotal = new LegalMonetaryTotal(); // Address $address = (new Address()) ->setStreetName('Résidence du chateau') ->setBuildingNumber(5) ->setCityName('Castle Land') ->setPostalZone('38760') ->setCountry( (new Country())->setIdentificationCode('FR') ); // Supplier & customer $company = (new Party()) ->setName('Company Machin') ->setPostalAddress($address); $client = (new Party()) ->setName('My Client') ->setPostalAddress($address); // Item $item = (new Item()) ->setName('Product Name') ->setDescription('Product Description'); // Price $price = (new Price()) ->setBaseQuantity(1) ->setUnitCode('Unit') ->setPriceAmount(10); // Invoice line $invoiceLine = (new InvoiceLine()) ->setId(0) ->setItem($item) ->setPrice($price) ->setInvoicedQuantity(1); // Tax $taxScheme = (new TaxScheme())->setId(0); $taxCategory = (new TaxCategory()) ->setId(0) ->setName('TVA20') ->setPercent(20) ->setTaxScheme($taxScheme); $taxSubTotal = (new TaxSubTotal()) ->setTaxableAmount(10) ->setTaxAmount(2) ->setTaxCategory($taxCategory); $taxTotal = (new TaxTotal()) ->addTaxSubTotal($taxSubTotal) ->setTaxAmount(2); // Invoice $invoice = (new Invoice()) ->setId(3) ->setIssueDate(new \DateTime()) ->setInvoiceTypeCode('invoiceTypeCode') ->setAccountingSupplierParty($company) ->setAccountingCustomerParty($client) ->setInvoiceLines([$invoiceLine]) ->setLegalMonetaryTotal( (new LegalMonetaryTotal()) ->setPayableAmount(12) ->setAllowanceTotalAmount(0) ) ->setTaxTotal($taxTotal); // Generate XML header('Content-type: text/xml'); echo Generator::invoice($invoice);
Laravel
use fajarsulaksono\UBL\Invoice\Invoice; use fajarsulaksono\UBL\Invoice\Generator; $invoice = new Invoice(); // ... build your invoice ... // Using the Generator directly $xml = Generator::invoice($invoice, 'EUR'); // Or using the Facade $xml = \UBLInvoice::invoice($invoice, 'EUR');
Available Classes
| Class | Description |
|---|---|
Invoice |
Top-level invoice document |
InvoiceLine |
A single invoice line item |
Party |
Accounting supplier or customer party |
Address |
Postal address (street, city, country) |
Contact |
Contact information (phone, email) |
Country |
Country with identification code |
LegalEntity |
Legal entity registration name and ID |
TaxTotal |
Tax total with subtotals |
TaxSubTotal |
A single tax subtotal entry |
TaxCategory |
Tax category (ID, name, percent, scheme) |
TaxScheme |
Tax scheme (e.g., VAT) |
Item |
Product or service item |
Price |
Price amount, base quantity, unit code |
AllowanceCharge |
Allowance or charge entry |
AdditionalDocumentReference |
Reference to additional documents |
LegalMonetaryTotal |
Monetary totals |
Generator |
Entry point for XML generation |
Running Tests
composer install vendor/bin/phpunit
License
This package is open-source software licensed under the MIT license.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.