Last active
December 14, 2023 11:00
Revisions
-
wqweto revised this gist
May 10, 2013 . 1 changed file with 43 additions and 21 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,41 +1,63 @@ <?php header('Content-type: application/json; charset=utf8'); $vatno = str_replace(array(' ', '.', '-', ',', '"'), '', $_GET['vatno']); echo serviceCheckVat($vatno, &$name, &$address, &$error); /* include "connect.php"; mysql_query("SET NAMES utf8"); $vatno = mysql_real_escape_string($_GET['vatno']); $name = mysql_real_escape_string($name); $address = mysql_real_escape_string(strlen($address) != 0 ? $address : $error); @mysql_query("REPLACE INTO ppl_dreem_cg (TaxNo, Name, Address) SELECT '$vatno', '$name', '$address'"); mysql_close(); */ function serviceCheckVat($vatno, $name, $address, $error) { if (strlen($vatno) <= 2) { $error = "Incorrect VAT number"; goto QH; } $client = new SoapClient("http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl"); if(!$client) { $error = "web service at ec.europa.eu unavailable"; goto QH; } try { $response = $client->checkVat(array( 'countryCode' => substr($vatno, 0, 2), 'vatNumber' => substr($vatno, 2) )); } catch (SoapFault $e) { $faults = array ( 'INVALID_INPUT' => 'The provided CountryCode is invalid or the VAT number is empty', 'SERVICE_UNAVAILABLE' => 'The SOAP service is unavailable, try again later', 'MS_UNAVAILABLE' => 'The Member State service is unavailable, try again later or with another Member State', 'TIMEOUT' => 'The Member State service could not be reached in time, try again later or with another Member State', 'SERVER_BUSY' => 'The service cannot process your request. Try again later.' ); $error = $faults[$e->faultstring]; if (!is_set($error)) $error = $e->faultstring; goto QH; } if (!$response->valid) { $error = "Not a valid VAT number"; goto QH; } $retval = "{\n \"success\": 1"; foreach ($response as $key => $prop) { $retval .= ",\n \"" . $key . "\": \"" . str_replace('"', '\"', $prop) . "\""; if ($key == 'name') $name = $prop; else if ($key == 'address') $address = $prop; } $retval .= "\n}"; return $retval; QH: return '{ "success": 0, "error": "' . $error . '" }'; } ?> -
wqweto revised this gist
May 10, 2013 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -6,7 +6,7 @@ function serviceCheckVat($vatno) { if (strlen($vatno) <= 2) return '{ "success": 0, "error": "invalid argument: vatno="' . $vatno . '" }'; $client = new SoapClient("http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl"); if(!$client) -
wqweto created this gist
May 10, 2013 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,41 @@ <?php header('Content-type: application/json; charset=utf8'); $vatno = str_replace(array(' ', '.', '-', ',', ', ', '"'), '', $_GET['vatno']); echo serviceCheckVat($vatno); function serviceCheckVat($vatno) { if (strlen($vatno) <= 2) return '{ "success": 0, "error": "invalid argument: vatno=" . $vatno }'; $client = new SoapClient("http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl"); if(!$client) return '{ "success": 0, "error": "web service at ec.europa.eu unavailable" }'; try { $response = $client->checkVat(array( 'countryCode' => substr($vatno, 0, 2), 'vatNumber' => substr($vatno, 2) )); } catch (SoapFault $e) { $faults = array ( 'INVALID_INPUT' => 'The provided CountryCode is invalid or the VAT number is empty', 'SERVICE_UNAVAILABLE' => 'The SOAP service is unavailable, try again later', 'MS_UNAVAILABLE' => 'The Member State service is unavailable, try again later or with another Member State', 'TIMEOUT' => 'The Member State service could not be reached in time, try again later or with another Member State', 'SERVER_BUSY' => 'The service cannot process your request. Try again later.' ); return '{ "success": 0, "error": "' . $faults[$e->faultstring] . '" }'; } if (!$response->valid) return '{ "success": 0, "error": "vat number " . $vatno . " is invalid" }'; $retval = "{\n \"success\": 1"; foreach ($response as $key => $prop) { $retval .= ",\n \"" . $key . "\": \"" . $prop . "\""; } $retval .= "\n}"; return $retval; } ?>