Last active
July 21, 2020 12:50
-
-
Save mbaersch/353e951118e4b8f79c379dcad6f5191f to your computer and use it in GitHub Desktop.
Prüfung einer USTID / VAT mittels VIES der EU (http://ec.europa.eu/taxation_customs/vies/technicalInformation.html) und nuSOAP (https://sourceforge.net/projects/nusoap/) statt SOAP
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 | |
/* Pruefung einer VAT mittels nuSOAP (https://sourceforge.net/projects/nusoap/) statt SOAP | |
Version 1.0.0.1 vom 30.09.2016 | |
M. Baersch, gandke marketing & software gmbh - www.gandke.de | |
*/ | |
function isValidVat($nr) { | |
require_once('lib/nusoap.php'); | |
$vatid = str_replace(array(' ', '.', '-', ',', ', '), '', trim($nr)); | |
$cc = substr($vatid, 0, 2); | |
$vn = substr($vatid, 2); | |
$client = new nusoap_client("http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl", true); | |
$client->soap_defencoding = 'UTF-8'; | |
if($client){ | |
$params = array('countryCode' => $cc, 'vatNumber' => $vn); | |
$res = $client->call('checkVat', $params); | |
if ($client->fault) { | |
return 'FAULT: '.serialize($res); | |
} else { | |
$err = $client->getError(); | |
if ($err) { | |
return 'ERROR: '.serialize($err); | |
} else { | |
if ($res[valid] === 'false') return "ERR"; else return "OK"; | |
} | |
} | |
} else { | |
return "Verbindungsfehler"; | |
} | |
} | |
//Beispielaufrufe | |
echo "<p>ATU12345678: ".isValidVat('ATU12345678')."</p>"; //Ergibt "ERR" | |
echo "<p>DE169710782: ".isValidVat('DE169710782')."</p>"; //Ergibt "OK" | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Wer die Schnittstelle zu VIES bzw. dem MIAS der EU per PHP nutzen will, aber kein SOAP auf seinem Server nutzen kann, ist mit NuSOAP gut bedient. Dazu dient die o. a. Funktion. Wer SOAP nutzen kann, kann sich NoSOAP sparen und den folgenden Beispielcode nutzen.