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

Commit

Permalink
catch VIES exception in validation rule as that service is down an aw…
Browse files Browse the repository at this point in the history
…ful lot lately
  • Loading branch information
dannyvankooten committed Jan 26, 2017
1 parent e0e7535 commit 07c8485
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/VatServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Validator as RequestValidator;

use DvK\Laravel\Vat\Vies\ViesException;
use DvK\Laravel\Vat\Facades\Validator as ValidatorFacade;


Expand All @@ -18,8 +19,22 @@ class VatServiceProvider extends ServiceProvider
*/
public function boot()
{

/**
* Register the "vat_number" validation rule.
*
* When the VIES VAT validation fails, this will just look at the number format.
* This can result in invalid VAT numbers being marked as true.
* With the VIES VAT number API being down an awful lot lately, we feel it is more important to get the purchase through.
*/
RequestValidator::extend('vat_number', function($attribute, $value, $parameters, $validator ) {
return ValidatorFacade::validate( $value );
try {
$valid = ValidatorFacade::validate( $value );
} catch( ViesException $e ) {
return true;
}

return $valid;
});
}

Expand Down

0 comments on commit 07c8485

Please sign in to comment.