@@ -51,7 +51,7 @@ class Vies
51
51
const VIES_PORT = 443 ;
52
52
const VIES_WSDL = '/taxation_customs/vies/checkVatService.wsdl ' ;
53
53
const VIES_TEST_WSDL = '/taxation_customs/vies/checkVatTestService.wsdl ' ;
54
- const VIES_EU_COUNTRY_TOTAL = 29 ;
54
+ const VIES_EU_COUNTRY_TOTAL = 28 ;
55
55
const VIES_TEST_VAT_NRS = [100 , 200 , 201 , 202 , 300 , 301 , 302 , 400 , 401 , 500 , 501 , 600 , 601 ];
56
56
57
57
protected const VIES_EU_COUNTRY_LIST = [
@@ -294,7 +294,7 @@ public function validateVat(
294
294
string $ traderCity = ''
295
295
): CheckVatResponse {
296
296
297
- if (! isset ( self :: VIES_EU_COUNTRY_LIST [ $ countryCode]) ) {
297
+ if ($ this -> validateCountryCode ( $ countryCode, true ) === false ) {
298
298
throw new ViesException (sprintf ('Invalid country code "%s" provided ' , $ countryCode ));
299
299
}
300
300
@@ -336,7 +336,7 @@ public function validateVat(
336
336
$ this ->addOptionalArguments ($ requestParams , 'traderCity ' , $ traderCity );
337
337
338
338
if ($ requesterCountryCode && $ requesterVatNumber ) {
339
- if (! isset ( self :: VIES_EU_COUNTRY_LIST [ $ requesterCountryCode]) ) {
339
+ if ($ this -> validateCountryCode ( $ requesterCountryCode) === false ) {
340
340
throw new ViesException (sprintf ('Invalid requestor country code "%s" provided ' , $ requesterCountryCode ));
341
341
}
342
342
$ requesterVatNumber = self ::filterVat ($ requesterVatNumber );
@@ -378,7 +378,7 @@ public function validateVat(
378
378
*/
379
379
public function validateVatSum (string $ countryCode , string $ vatNumber ): bool
380
380
{
381
- if (! isset ( self :: VIES_EU_COUNTRY_LIST [ $ countryCode]) ) {
381
+ if ($ this -> validateCountryCode ( $ countryCode, true ) === false ) {
382
382
throw new ViesException (sprintf ('Invalid country code "%s" provided ' , $ countryCode ));
383
383
}
384
384
$ className = self ::VIES_EU_COUNTRY_LIST [$ countryCode ]['validator ' ];
@@ -427,6 +427,9 @@ public static function listEuropeanCountries(): array
427
427
array_column (self ::VIES_EU_COUNTRY_LIST , 'name ' )
428
428
);
429
429
unset($ list ['EU ' ]);
430
+ foreach (array_keys (self ::VIES_EXCLUDED_COUNTRY_CODES ) as $ excludedCountryCode ) {
431
+ unset($ list [$ excludedCountryCode ]);
432
+ }
430
433
}
431
434
432
435
return $ list ;
@@ -484,7 +487,14 @@ private function validateArgument(string $argumentValue): bool
484
487
return true ;
485
488
}
486
489
487
- private function validateTestVat ($ countryCode , $ testVatNumber ): CheckVatResponse
490
+ /**
491
+ * @param string $countryCode
492
+ * @param string $testVatNumber
493
+ *
494
+ * @return CheckVatResponse
495
+ * @throws ViesServiceException
496
+ */
497
+ private function validateTestVat (string $ countryCode , string $ testVatNumber ): CheckVatResponse
488
498
{
489
499
$ wsdlUri = sprintf ('%s://%s%s ' , self ::VIES_PROTO , self ::VIES_DOMAIN , self ::VIES_TEST_WSDL );
490
500
$ this ->setWsdl ($ wsdlUri );
@@ -509,4 +519,22 @@ private function validateTestVat($countryCode, $testVatNumber): CheckVatResponse
509
519
throw new ViesServiceException ($ message , 0 , $ e );
510
520
}
511
521
}
522
+
523
+ /**
524
+ * @param string $countryCode
525
+ * @param bool $useExcludedCountries
526
+ *
527
+ * @return bool
528
+ */
529
+ private function validateCountryCode (string $ countryCode , bool $ useExcludedCountries = false ): bool
530
+ {
531
+ if (! isset (self ::VIES_EU_COUNTRY_LIST [$ countryCode ])) {
532
+ return false ;
533
+ }
534
+ if ($ useExcludedCountries === false && isset (self ::VIES_EXCLUDED_COUNTRY_CODES [$ countryCode ])) {
535
+ return false ;
536
+ }
537
+
538
+ return true ;
539
+ }
512
540
}
0 commit comments