Skip to content

Commit

Permalink
Merge branch 'master' of github.com:ibericode/vat-bundle
Browse files Browse the repository at this point in the history
  • Loading branch information
dannyvankooten committed Nov 30, 2023
2 parents 632b7ef + 32ab252 commit 55dcad5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
2 changes: 2 additions & 0 deletions src/Validator/Constraints/VatNumber.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ class VatNumber extends Constraint
public const INVALID_ERROR_CODE = '59421d43-d474-489c-b18c-7701329d51a0';

public string $message = '"{{ string }}" does not look like a valid VAT number.';

public bool $checkExistence = true;
}
18 changes: 11 additions & 7 deletions src/Validator/Constraints/VatNumberValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,17 @@ public function validate(mixed $value, Constraint $constraint) : void
}

$validator = new Validator();
try {
$valid = $validator->validateVatNumber($value);
} catch (ViesException $e) {
// ignore VIES VAT exceptions (when the service is down)
// this could mean that an unexisting VAT number passes validation,
// but it's (probably) better than a hard-error
$valid = true;
if ($constraint->checkExistence) {
try {
$valid = $validator->validateVatNumber($value);
} catch (ViesException $e) {
// ignore VIES VAT exceptions (when the service is down)
// this could mean that an unexisting VAT number passes validation,
// but it's (probably) better than a hard-error
$valid = true;
}
} else {
$valid = $validator->validateVatNumberFormat($value);
}

if (false === $valid) {
Expand Down

0 comments on commit 55dcad5

Please sign in to comment.