greenter/ubl-validator
Validate OASIS UBL XML documents against the correct XSD via UBLVersionID. Provide XML content, run isValid(), and get validation errors. Supports custom XSD base directories to validate multiple UBL versions (e.g., 2.1/2.2).
/api/invoices).cbc:ID").Adopt if:
Look elsewhere if:
*"This package lets us automate UBL invoice validation—a mandatory requirement for [X compliance mandate, e.g., EU e-invoicing]—with zero custom development. For example, [Company Z] reduced their supplier onboarding time by 60% and eliminated manual invoice rejections using this validator. The MIT license avoids legal risks, and the low maintenance cost (last updated 2022) aligns with our short-term roadmap.
Proposed Investment:
Key Metrics:
*"This is a lightweight, dependency-free PHP package that validates UBL XML against OASIS schemas (v2.0/v2.1). Here’s the integration plan:
// Option 1: API Middleware (for real-time validation)
public function handle($request, Closure $next) {
$validator = new \Greenter\Ubl\UblValidator();
if (!$validator->isValid($request->xml)) {
return response()->json(['error' => $validator->getError()], 400);
}
return $next($request);
}
// Option 2: Queue Job (for batch processing)
public function handle() {
$xml = Storage::get('invoices/invoice_123.xml');
$validator = new UblValidator();
if (!$validator->isValid($xml)) {
event(new InvoiceValidationFailed($xml, $validator->getError()));
}
}
$validator->pathResolver->baseDirectory = storage_path('app/xsd/ubl-2.3');
class UblValidationError {
public function __construct(
public string $message,
public array $details,
public int $code = 400
) {}
}
| Pros | Cons |
|---|---|
| No external dependencies | No built-in async/parallel validation |
| MIT license | Last release: Dec 2022 (v2.2 unsupported) |
| Simple API | Raw XML errors (needs post-processing) |
| Laravel-friendly | PHP-based (not ideal for ultra-high throughput) |
*"This package directly addresses [X regulatory requirement] by ensuring all UBL invoices conform to OASIS v2.0/v2.1 standards. Here’s how it mitigates risk:
Automated Validation:
Audit Trails:
How can I help you explore Laravel packages today?