sorciulus/check-partita-iva
Laravel package to validate Italian VAT numbers (Partita IVA). Provides quick checks (format and checksum) to detect invalid P.IVA values, useful for signup forms, invoicing, and customer data imports.
Validator facade) or custom validation rules.CheckPartitaIVA::validate($vatNumber)), which can be wrapped in Laravel’s service layer or used directly in controllers/validators.OrderCreated) to validate VAT IDs during order processing, aligning with Laravel’s event system.app/Rules/ValidItalianVat.php) using Laravel’s extends Rule or Validator::extend().VatValidationService) to abstract dependencies and add caching (e.g., Redis).Creating: Order).json_decode behavior).Cache::remember()).laravel-shift/dependency-plugin to detect conflicts.composer.json for transitive dependencies (e.g., old versions of Guzzle, Symfony HTTP client).composer.json overrides or aliases.vat_validations table).Request validation, Form Requests).use Sorciulus\CheckPartitaIVA\CheckPartitaIVA;
Validator::extend('italian_vat', function ($attribute, $value, $parameters, $validator) {
return CheckPartitaIVA::validate($value);
});
class VatValidationService {
public function validate(string $vatNumber): bool {
return Cache::remember("vat_{$vatNumber}", now()->addHours(1), function() {
return CheckPartitaIVA::validate($vatNumber);
});
}
}
order.created).event(new OrderCreated($order));
// Listener:
public function handle(OrderCreated $event) {
$service = app(VatValidationService::class);
if (!$service->validate($event->order->vat_number)) {
throw new \Exception("Invalid VAT number");
}
}
| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Package API fails (e.g., HTTP 500) | Validation blocked | Fallback to regex or manual checks. |
| Italian VAT API changes | False positives/negatives | Monitor official sources for updates. |
| Caching stale data | Invalid VATs pass validation | Short TTL (e.g., 1 hour) + manual review. |
| PHP/Laravel version incompatibility | Integration breaks | Fork or use compatibility layers. |
| High false-positive rate | User frustration | Whitelist known-valid VATs. |
How can I help you explore Laravel packages today?