我来自哪里,我不需要缴纳增值税(增值税)。但我正在做的一个项目需要其输入才能合法地完成交易。
在哪里可以找到API,我可以从增值税税号中获取相关信息(地址,公司名称等)?我想用它来自动填充表单,因为没有更好的方法来吓跑客户而不是让他工作。
答案 0 :(得分:2)
评论中提到的VIES有一个API。而且我已经实现了你所要求的,主要是出于同样的原因。和它的'PHP。你走了:
class VatValidator {
const validVatId = 'valid';
const invalidVatId = 'invalid';
/**
*
* The european commission (ec) provides a validation database for VAT Id's, which can be accessed via WSDL.
* We check the given VAT against that Database.
*
* Actually that is more reliable than any captcha !!!
*
* * only companies have one
* * the code can not be "brute forced"
* * simple mass requests can be cut off easily
*
* @param String $requestedVatId entire VAT Id including country code
* @param string $company optional Company Name
* @param string $city optional company city
* @return Multiple false on error, String self::validVatId or String self::invalidVatId according to state.
*/
public static function validateVATID($requestedVatId, $company=null, $city=null)
{
$ret = false;
$ecUrl = "http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl";
$vatid = str_replace(array(' ', '.', '-', ',', ', '), '', trim($requestedVatId));
$cc = substr($vatid, 0, 2);
$vn = substr($vatid, 2);
$client = new SoapClient($ecUrl);
if($client)
{
$params = array('countryCode' => $cc,
'vatNumber' => $vn,
);
/*
* simple request only since we do not get any further information anyway.
*
* with $r = $client->checkVatApprox($params);
* we could:
*
'requesterCountryCode' => 'XXX',
'requesterVatNumber' => 'XXX' // Own ID!!
if ( !empty($company) )
$params['traderName'] = $company;
if ( !empty($city) )
$params['traderCity'] = $city;
$params["traderCompanyType"] = 1;
$params["traderStreet"] = 'xyz';
$params["traderPostcode"] = '1234';
*/
try
{
//$r = $client->checkVatApprox($params);
$r = $client->checkVat($params);
if($r->valid == true)
{
logMessage(Constants::$debug, 'valid: ' . $vatid);
$ret = self::validVatId;
}
else
{
logMessage(Constants::$debug, 'invalid: ' . $vatid);
$ret = self::invalidVatId;
}
// This foreach shows every single line of the returned information
// foreach($r as $k=>$prop)
// {
// logMessage(Constants::$debug, $k.': '.$prop);
// }
//logMessage(Constants::$debug, print_r($r, true));
} catch(SoapFault $e) {
logMessage(Constants::$debug, 'Error, see message: '.$e->faultstring);
$ret = $e->faultstring;
}
}
else
{
logMessage(Constants::$debug, 'cannot connect to ' . $ecUrl);
$ret = 'CONNECTERROR';
}
return $ret;
}
}
代码中的“XXX”可能是您自己的增值税ID,以便通过输入您自己的ID来防止有点欺诈......