Last active
May 20, 2017 12:04
-
-
Save ryandemmer/13c742e547bc8cba6d51 to your computer and use it in GitHub Desktop.
VIES VAT Validator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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