Last active
August 22, 2019 21:20
-
-
Save ArthurHNL/81acfc854fa7d1ae5b038b8d2fe640b6 to your computer and use it in GitHub Desktop.
EU VIES VAT Verification
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
<?php | |
// (c) Arthur Heidt, 2019. Licensed under MIT. | |
// There is no guarantee that this code works, I have not tested it. | |
// But it should at least point you in the right direction. | |
// You must enable the SOAP extension to allow this extension to work. | |
/** | |
* Verifies a VAT number using the EU VIES API. | |
* | |
* @param string $countryCode The country code for the company of which the VAT number must be | |
* verified. | |
* @param string $vatNumber The VAT number of the company of which the VAT number must be | |
* verified. | |
* | |
* @return bool True when the VAT number of the company is valid. | |
*/ | |
function verifyVatNumber( | |
$countryCode, | |
$vatNumber | |
) | |
{ | |
// By default this function uses the test soap service. To use the actual soap service, | |
// comment line 26 and uncomment line 27. | |
// The test service will return valid for VAT number 100 and invalid for 200. | |
/// For the test service, the countrycode needs to be valid but not specific so just use 'NL'. | |
$viesApiEntrypoint = "http://ec.europa.eu/taxation_customs/vies/checkVatTestService.wsdl"; | |
// $viesApiEntrypoint = "http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl"; | |
$req = [ | |
'countryCode' => $countryCode, | |
'vatNumber' => $vatNumber | |
]; | |
$viesClient = new \SoapClient($viesApiEntrypoint); | |
$viesCallResult = $viesClient->checkVat($req); | |
return $viesCallResult->valid; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment