Skip to content

Instantly share code, notes, and snippets.

@fschell
Created March 4, 2014 09:51
Show Gist options
  • Save fschell/9343430 to your computer and use it in GitHub Desktop.
Save fschell/9343430 to your computer and use it in GitHub Desktop.
check UstId
<?php
function checkUstId($ustId) {
$serviceUrl = 'http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl';
$vatNumber = substr($ustId,2);
$countryCode = substr($ustId,0,2);
$soap = new SoapClient($serviceUrl);
$result = $soap->checkVat(array("countryCode" => $countryCode, "vatNumber" => $vatNumber));
//print_r($result);
return $result->valid;
}
// test
$ustIds = array("DE275249807", "DE075249807");
foreach ($ustIds as $ustId){
echo 'UstId ' . $ustId . ' is ' . (checkUstId($ustId) ? 'valid' : 'invalid') . ".\n";
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment