From f63fea2f835f428cd9243e8fe61cb784e15b8bfc Mon Sep 17 00:00:00 2001 From: Justin van Elst Date: Thu, 14 Dec 2023 09:47:07 +0100 Subject: [PATCH] Check Vatlayer database return for failure. --- Service/Validate/Vatlayer.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) 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']; } }