This guide helps solve common problems with the UBL-PEPPOL package.
Package darvis/ubl-peppol not found
Solution:
composer clear-cachedarvis/ubl-peppol requires php >=8.2
Solution:
php -vClass 'UblBeBis3Service' not found
Solution:
composer dump-autoload// config/app.php
'providers' => [
Darvis\UblPeppol\UblPeppolServiceProvider::class,
],
Class 'DOMDocument' not found
Solution:
sudo apt-get install php-xml
sudo yum install php-xml
brew install php
2. Restart web server
#### Error: "Invalid XML structure"
```bash
DOMDocument::loadXML(): Start tag expected
Solution:
createDocument() was calledvar_dump($ubl->generateXml())Fatal error: Allowed memory size of 134217728 bytes exhausted
Solution:
memory_limit = 256M
ini_set('memory_limit', '256M');
❌ RuntimeException: Document is already initialized
Cause: createDocument() is called multiple times.
Solution:
$ubl = new UblBeBis3Service();
$ubl->createDocument(); // ✅ Eén keer
// $ubl->createDocument(); // ❌ Niet opnieuw aanroepen
❌ RuntimeException: Root element is not initialized
Cause: Elements added before createDocument().
Solution:
$ubl = new UblBeBis3Service();
$ubl->createDocument(); // ✅ Eerst document initialiseren
$ubl->addInvoiceHeader('INV-001', '2024-01-15', '2024-02-14');
❌ InvalidArgumentException: Invalid date format
Cause: Date not in YYYY-MM-DD format.
Solution:
// ✅ Correct format
$ubl->addInvoiceHeader('INV-001', '2024-01-15', '2024-02-14');
// ❌ Wrong formats
$ubl->addInvoiceHeader('INV-001', '15-01-2024', '14/02/2024');
$ubl->addInvoiceHeader('INV-001', '2024/01/15', '2024.02.14');
❌ Element 'AdditionalDocumentReference' is missing
Solution:
$ubl->addAdditionalDocumentReference('PEPPOL', 'PEPPOLInvoice');
❌ Tax category name 'Standard rate' not in BTCC list
Solution:
// Use correct BTCC values
'tax_category_name' => 'Taux standard' // ✅ Correct
'tax_category_name' => 'Standard rate' // ❌ Error
'tax_category_name' => 'Standaardtarief' // ❌ Error
❌ Element 'TaxTotal' not allowed in 'InvoiceLine'
Solution:
UblNlBis3Service (no TaxTotal in InvoiceLine)UblBeBis3Service (handles ubl-BE-14 automatically)InvalidArgumentException: Invalid VAT number format
Solution:
// Belgium: BE + 10 digits
'BE0123456789' // ✅ Correct
'BE123456789' // ❌ Error (9 digits)
'123456789' // ❌ Error (no country code)
// Netherlands: NL + 9 digits + B + 2 digits
'NL123456789B01' // ✅ Correct
'NL123456789' // ❌ Error (missing B01)
'123456789B01' // ❌ Error (no country code)
❌ Endpoint scheme '0208' not valid for Netherlands
Solution:
// ✅ For Netherlands
$endpointSchemeID = '0106'; // KVK
$endpointSchemeID = '0190'; // OIN
// ❌ For Netherlands
$endpointSchemeID = '0208'; // Belgium VAT
$xml = $ubl->generateXml();
echo $xml; // Empty or minimal XML
Cause: No elements added after createDocument().
Solution:
$ubl = new UblBeBis3Service();
$ubl->createDocument();
$ubl->addInvoiceHeader('INV-001', '2024-01-15', '2024-02-14');
// Voeg meer elementen toe...
$xml = $ubl->generateXml();
❌ XML Parse Error: not well-formed
Cause: Special characters in data.
Solution:
// ✅ Escape special characters
$description = htmlspecialchars('Consultancy & Support', ENT_XML1);
// Or use CDATA for complex content
$description = '<![CDATA[Consultancy & Support <special>]]>';
❌ Invalid UTF-8 sequence
Solution:
// Ensure UTF-8 encoding
$name = mb_convert_encoding($name, 'UTF-8');
// Or validate input
if (!mb_check_encoding($name, 'UTF-8')) {
throw new InvalidArgumentException('Invalid UTF-8 encoding');
}
Cause: Large number of invoice lines.
Solution:
// Batch processing for large invoices
$lines = array_chunk($invoiceLines, 100);
foreach ($lines as $batch) {
foreach ($batch as $line) {
$ubl->addInvoiceLine($line);
}
// Optional: garbage collection
gc_collect_cycles();
}
❌ Fatal error: Allowed memory size exhausted
Solution:
// Increase memory limit
ini_set('memory_limit', '256M');
// Or use streaming for large files
$ubl = new UblBeBis3Service();
$ubl->createDocument();
// Add elements in batches
❌ GET /be/generate_invoice_be.php - No such file or directory
Solution:
# Ensure server runs in correct directory
cd /path/to/ubl-peppol
php -S localhost:8000 -t examples/
Cause: Headers already sent.
Solution:
// Ensure no output before headers
<?php
// No echo/print statements here
if (isset($_GET['download'])) {
header('Content-Type: application/xml');
header('Content-Disposition: attachment; filename="invoice.xml"');
echo $xml;
exit;
}
error_reporting(E_ALL);
ini_set('display_errors', 1);
// Validate XML structure
$dom = new DOMDocument();
$dom->loadXML($xml);
if (!$dom->schemaValidate('path/to/ubl-schema.xsd')) {
$errors = libxml_get_errors();
foreach ($errors as $error) {
echo "XML Error: " . $error->message;
}
}
// Check internal state
$reflection = new ReflectionClass($ubl);
$property = $reflection->getProperty('rootElement');
$property->setAccessible(true);
$rootElement = $property->getValue($ubl);
if (!$rootElement) {
echo "Document not initialized";
}
A: Yes, use the correct service per invoice:
// For Belgian customers
$belgianInvoice = new UblBeBis3Service();
// For Dutch customers
$dutchInvoice = new UblNlBis3Service();
A:
generateXml()A: Use the addChildElement() helper methods to add custom elements within the UBL structure.
A: Yes, the service provider is automatically registered via package discovery.
For further help:
/docs directory