Skip to content
This repository was archived by the owner on Oct 4, 2022. It is now read-only.

Commit 07c8485

Browse files
catch VIES exception in validation rule as that service is down an awful lot lately
1 parent e0e7535 commit 07c8485

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/VatServiceProvider.php

+16-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Illuminate\Support\ServiceProvider;
77
use Illuminate\Support\Facades\Validator as RequestValidator;
88

9+
use DvK\Laravel\Vat\Vies\ViesException;
910
use DvK\Laravel\Vat\Facades\Validator as ValidatorFacade;
1011

1112

@@ -18,8 +19,22 @@ class VatServiceProvider extends ServiceProvider
1819
*/
1920
public function boot()
2021
{
22+
23+
/**
24+
* Register the "vat_number" validation rule.
25+
*
26+
* When the VIES VAT validation fails, this will just look at the number format.
27+
* This can result in invalid VAT numbers being marked as true.
28+
* With the VIES VAT number API being down an awful lot lately, we feel it is more important to get the purchase through.
29+
*/
2130
RequestValidator::extend('vat_number', function($attribute, $value, $parameters, $validator ) {
22-
return ValidatorFacade::validate( $value );
31+
try {
32+
$valid = ValidatorFacade::validate( $value );
33+
} catch( ViesException $e ) {
34+
return true;
35+
}
36+
37+
return $valid;
2338
});
2439
}
2540

0 commit comments

Comments
 (0)