Skip to content

Instantly share code, notes, and snippets.

@ryandemmer
Last active May 20, 2017 12:04
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryandemmer/13c742e547bc8cba6d51 to your computer and use it in GitHub Desktop.
Save ryandemmer/13c742e547bc8cba6d51 to your computer and use it in GitHub Desktop.
VIES VAT Validator
public function validateVAT($code, $vat) {
if ($code === "GR") {
$code = "EL";
}
try {
$client = @new SoapClient("http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl");
} catch (SoapFault $e) {
return -1;
}
$params = array('countryCode' => $code, 'vatNumber' => $vat);
if ($client){
try{
$r = $client->checkVat($params);
if($r->valid == true){
return 1;
} else {
return 0;
}
} catch(SoapFault $e) {
return -1;
}
} else {
// Connection to host not possible, europe.eu down?
return -1;
}
return -1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment