diff --git a/Service/Validate/Vatlayer.php b/Service/Validate/Vatlayer.php index 3537e07..474dc39 100644 --- a/Service/Validate/Vatlayer.php +++ b/Service/Validate/Vatlayer.php @@ -96,10 +96,18 @@ public function validateVATNumber(string $vatNumber, string $countryIso2): bool throw new ValidationFailedException('Vatlayer could not be queried ' . $result['error']['info']); } - if (! isset($result['valid'])) { + if ((! isset($result['valid'])) || (! isset($result['database']))) { throw new ValidationIgnoredException('Vatlayer did not return validation'); } + if ($result['database'] === 'failure') { + throw new ValidationFailedException('Vatlayer returns: database failure (could not connect to member state)'); + } + + if ($result['database'] !== 'ok') { + throw new ValidationFailedException('Vatlayer database not ok'); + } + return (bool)$result['valid']; } }