本文整理汇总了PHP中SoapClient::checkVat方法的典型用法代码示例。如果您正苦于以下问题:PHP SoapClient::checkVat方法的具体用法?PHP SoapClient::checkVat怎么用?PHP SoapClient::checkVat使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SoapClient
的用法示例。
在下文中一共展示了SoapClient::checkVat方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: check
/**
* @param string $countryCode
* @param string $vatNumber
* @return bool
*/
public function check($countryCode, $vatNumber)
{
$this->initClient();
$vatNumber = preg_replace("/[ .]/", "", $vatNumber);
try {
$rs = $this->_client->checkVat(array('countryCode' => $countryCode, 'vatNumber' => $vatNumber));
} catch (\SoapFault $e) {
if ($e->getMessage() === 'INVALID_INPUT') {
return false;
}
throw $e;
}
if ($rs->valid) {
$this->_valid = true;
list($denomination, $name) = strpos($rs->name, ' ') !== false ? explode(" ", $rs->name, 2) : array('', '');
list($streetline, $cityline) = strpos($rs->address, "\n" !== false) ? explode("\n", $rs->address) : array('', '');
preg_match('/(.+) ([^ ]*[0-9]+[^ ]*)/', $this->cleanUpString($streetline), $parts);
if (count($parts) === 0) {
$street = $this->cleanUpString($streetline);
$number = "";
} else {
$street = $parts[1];
$number = $parts[2];
}
list($zip, $city) = $cityline !== '' ? explode(' ', $this->cleanUpString($cityline), 2) : array('', '');
$this->_data = array('denomination' => $denomination, 'name' => $this->cleanUpString($name), 'address' => $this->cleanUpString($rs->address), 'street' => $street, 'number' => $number, 'zip' => $zip, 'city' => $city, 'country' => $countryCode);
return true;
} else {
$this->_valid = false;
$this->_data = array();
return false;
}
}
示例2: eu_check
private function eu_check()
{
$isp = Shineisp_Registry::get('ISP');
$VIES = new SoapClient($this->vies_soap_url);
if ($VIES) {
try {
$r = $VIES->checkVat(array('countryCode' => $this->countryCode, 'vatNumber' => $this->vat));
foreach ($r as $chiave => $valore) {
$this->viesOutput[$chiave] = $valore;
}
return $r->valid;
} catch (SoapFault $e) {
$ret = $e->faultstring;
$regex = '/\\{ \'([A-Z_]*)\' \\}/';
$n = preg_match($regex, $ret, $matches);
$ret = !empty($matches[1]) ? $matches[1] : $ret;
$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.');
$ret = $faults[$ret];
// adding a log message
Shineisp_Commons_Utilities::log("Response from VIES: " . $ret);
$subject = 'Invalid VAT code';
$body = "Response from VIES: " . $ret;
Shineisp_Commons_Utilities::SendEmail($isp->email, $isp->email, null, $subject, $body);
return false;
}
} else {
$subject = 'Connect to VIES';
$body = "Impossible to connect with VIES";
Shineisp_Commons_Utilities::SendEmail($isp->email, $isp->email, null, $subject, $body);
// adding a log message
Shineisp_Commons_Utilities::log("Response from VIES: " . $ret);
return false;
}
return true;
}
示例3: isValidVat
/**
* Check if this is a valid VIES VAT
*
* Code credits: Nicholas from AkeebaBackup.com
*/
public function isValidVat($country, $vat)
{
$vat = trim(strtoupper($vat));
$country = trim(strtoupper($country));
// cache
$data = json_decode($this->app->session->get('zoocart_vat_cache'), true);
if ($data && array_key_exists($country . $vat, $data)) {
return $data[$country . $vat];
}
if (!class_exists('SoapClient')) {
$ret = false;
} else {
// Using the SOAP API
// Code credits: Angel Melguiz / KMELWEBDESIGN SLNE (www.kmelwebdesign.com)
try {
$sClient = new SoapClient('http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl');
$params = array('countryCode' => $country, 'vatNumber' => $vat);
$response = $sClient->checkVat($params);
if ($response->valid) {
$ret = true;
} else {
$ret = false;
}
} catch (SoapFault $e) {
$ret = false;
}
}
$data[$country . $vat] = $ret;
$this->app->session->set('zoocart_vat_cache', json_encode($data));
// Return the result
return $ret;
}
示例4: check_vat
/**
* Check a given VAT number with the europe VIES check
*
* @param string $country The country code to check with the VAT number.
* @param string $vat_nr The VAT number to check.
*
* @return bool|null
*/
private function check_vat($country, $vat_nr)
{
$country = trim($country);
$vat_nr = trim($vat_nr);
// Strip all spaces from the VAT number to improve usability of the VAT field.
$vat_nr = str_replace(' ', '', $vat_nr);
if (0 === strpos($vat_nr, $country)) {
$vat_nr = trim(substr($vat_nr, strlen($country)));
}
try {
// Do the remote request.
$client = new \SoapClient('http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl');
$returnVat = $client->checkVat(array('countryCode' => $country, 'vatNumber' => $vat_nr));
} catch (\Exception $e) {
error_log('VIES API Error for ' . $country . ' - ' . $vat_nr . ': ' . $e->getMessage());
return 2;
}
// Return the response.
if (isset($returnVat)) {
if (true == $returnVat->valid) {
return 1;
} else {
return 0;
}
}
// Return null if the service is down.
return 2;
}
示例5: checkWithVIES
protected function checkWithVIES($countryCode, $vatNumber)
{
try {
ini_set("soap.wsdl_cache_enabled", 0);
$client = new \SoapClient(__DIR__ . '/../Resources/wsdl/checkVatService.wsdl', array('soap_version' => SOAP_1_1, 'style' => SOAP_DOCUMENT, 'encoding' => SOAP_LITERAL, 'location' => 'http://ec.europa.eu/taxation_customs/vies/services/checkVatService', 'trace' => 1));
$result = $client->checkVat(array('countryCode' => $countryCode, 'vatNumber' => $vatNumber));
return $result->valid ? true : false;
} catch (\SoapFault $exception) {
throw new VATException('SOAP fault', 0, $exception);
}
}
示例6: getRequest
private function getRequest()
{
try {
$opts = array('http' => array('user_agent' => 'PHPSoapClient'));
$context = stream_context_create($opts);
$client = new \SoapClient('http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl', array('stream_context' => $context, 'cache_wsdl' => WSDL_CACHE_NONE));
$result = $client->checkVat(array('countryCode' => $this->_codiceComunitario, 'vatNumber' => $this->_partitaIVA));
$this->_valid = $result->valid == 1 ? true : false;
return true;
} catch (\Exception $e) {
return false;
}
}
示例7: _ajaxUpdate
/**
*/
protected function _ajaxUpdate(Horde_Variables $vars)
{
$html = '';
$vatid = str_replace(' ', '', $vars->vatid);
if (empty($vatid) || !preg_match('/^([A-Z]{2})([0-9A-Za-z\\+\\*\\.]{2,12})$/', $vatid, $matches)) {
return '<br />' . $this->_error(_("Invalid VAT identification number format."));
}
if (empty($matches)) {
return;
}
try {
$client = new SoapClient('http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl', array('exceptions' => true));
$result = $client->checkVat(array('countryCode' => $matches[1], 'vatNumber' => $matches[2]));
if ($result->valid) {
$html .= '<span style="color:green;font-weight:bold">' . _("This VAT identification number is valid.") . '</span><br />';
} else {
$html .= $this->_error(_("This VAT identification number is invalid.")) . '<br />';
}
$html .= '<em>' . _("Country") . ':</em> ' . $result->countryCode . '<br /><em>' . _("VAT number") . ':</em> ' . $result->vatNumber . '<br /><em>' . _("Date") . ':</em> ' . strftime($GLOBALS['prefs']->getValue('date_format'), strtotime($result->requestDate)) . '<br />';
if (!empty($result->name)) {
$html .= '<em>' . _("Name") . ':</em> ' . $result->name . '<br />';
}
if (!empty($result->address)) {
$html .= '<em>' . _("Address") . ':</em> ' . $result->address . '<br />';
}
} catch (SoapFault $e) {
$error = $e->getMessage();
switch (true) {
case strpos($error, 'INVALID_INPUT'):
$error = _("The provided country code is invalid.");
break;
case strpos($error, 'SERVICE_UNAVAILABLE'):
$error = _("The service is currently not available. Try again later.");
break;
case strpos($error, 'MS_UNAVAILABLE'):
$error = _("The member state service is currently not available. Try again later or with a different member state.");
break;
case strpos($error, 'TIMEOUT'):
$error = _("The member state service could not be reached in time. Try again later or with a different member state.");
break;
case strpos($error, 'SERVER_BUSY'):
$error = _("The service is currently too busy. Try again later.");
break;
}
$html .= $this->_error($error);
}
return $html;
}
示例8: validateVatNumberHandler
/**
* Attempt to validate a european VAT
* ** This method is called by exec() and is designed to be HTTP accessible **
*
* @param $args ['vatNumber'=>"...", 'countryCode'=>'...']
* @return Response
* @throws \Exception
*/
public function validateVatNumberHandler($args)
{
$this->testInputs(['vatNumber' => ['string'], 'countryCode' => ['string']], $args);
$args['vatNumber'] = str_replace(' ', '', $args['vatNumber']);
$args['vatNumber'] = strtoupper($args['vatNumber']);
$this->state->vatNumber = null;
$this->state->vatNumberStatus = null;
$this->state->vatNumberCountryCode = null;
$client = new \SoapClient("http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl");
$soapResponse = null;
try {
$soapResponse = $client->checkVat(array('countryCode' => $args['countryCode'], 'vatNumber' => $args['vatNumber']));
if ($soapResponse->valid) {
// Valid
$this->state->vatNumber = $args['vatNumber'];
$this->state->vatNumberStatus = 'valid';
$this->state->vatNumberCountryCode = $args['countryCode'];
} else {
// Invalid
$this->state->vatNumber = null;
$this->state->vatNumberCountryCode = null;
$this->state->vatNumberStatus = 'invalid';
$this->setFlashError("Sorry but the VAT number or country entered was incorrect.");
}
} catch (\SoapFault $e) {
if ($e->getMessage() == "INVALID_INPUT") {
// Invalid
$this->state->vatNumber = null;
$this->state->vatNumberCountryCode = null;
$this->state->vatNumberStatus = 'invalid';
$this->setFlashError("Sorry but the VAT number or country entered was incorrect.");
} else {
// Unknown due to technical error
// We allow the vat number but flag it for manual checking
$this->state->vatNumber = $args['vatNumber'];
$this->state->vatNumberStatus = 'unknown';
$this->state->vatNumberCountryCode = $args['countryCode'];
}
}
$this->updateLineItemsAndTotal();
// Render full component
$this->updateState();
return $this->render();
}
示例9: verify_vies
/**
* verifies vies number
* @param string $vat_number
* @param string $country_code
* @return boolean
*/
public static function verify_vies($vat_number, $country_code = NULL)
{
if ($vat_number == NULL or $vat_number == '' or strlen($vat_number) < 3) {
return FALSE;
}
if ($country_code === NULL or empty($country_code)) {
$country_code = self::country_code();
}
//first check if country is part of EU
if (array_key_exists($country_code, self::get_vat_rates())) {
$client = new SoapClient("http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl");
$res = $client->checkVat(array('countryCode' => $country_code, 'vatNumber' => $vat_number));
//not valid
if (!$res->valid) {
return FALSE;
}
}
return TRUE;
}
示例10: eu_vat_hook_validate_number
/**
*
* @ WHMCS FULL DECODED & NULLED
*
* @ Version : 5.2.15
* @ Author : MTIMER
* @ Release on : 2013-12-24
* @ Website : http://www.mtimer.cn
*
* */
function eu_vat_hook_validate_number($vars)
{
$modulevars = array();
$result = select_query("tbladdonmodules", "", array("module" => "eu_vat"));
while ($data = mysql_fetch_array($result)) {
$modulevars[$data['setting']] = $data['value'];
}
if (!$modulevars['enablevalidation']) {
return false;
}
$result = select_query("tblcustomfields", "id", array("type" => "client", "fieldname" => $modulevars['vatcustomfield']));
$data = mysql_fetch_array($result);
$VAT_CUSTOM_FIELD_ID = $data['id'];
$vatnumber = $_POST['customfield'][$VAT_CUSTOM_FIELD_ID];
if ($vatnumber) {
$vatnumber = strtoupper($vatnumber);
$vatnumber = preg_replace("/[^A-Z0-9]/", "", $vatnumber);
$vat_prefix = substr($vatnumber, 0, 2);
$vat_num = substr($vatnumber, 2);
$errorcheck = false;
try {
$taxCheck = new SoapClient("http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl");
$taxValid = $taxCheck->checkVat(array("countryCode" => "" . $vat_prefix, "vatNumber" => "" . $vat_num));
} catch (Exception $e) {
$errorcheck = true;
}
if ($taxValid->valid != 1 || $errorcheck) {
global $errormessage;
global $_LANG;
if (!$_LANG['vatnumberinvalid']) {
$_LANG['vatnumberinvalid'] = "The supplied VAT Number is not valid";
}
$errormessage .= "<li>" . $_LANG['vatnumberinvalid'];
}
}
}
示例11: _checkOnline
/**
* Checks online if USt.ID number is valid.
* Returns true on success. On error sets error value.
*
* @param object $oCheckVat vat object
*
* @return bool
*/
protected function _checkOnline($oCheckVat)
{
if ($this->_isServiceAvailable()) {
$iTryMoreCnt = self::BUSY_RETRY_CNT;
//T2009-07-02
//how long socket should wait for server RESPONSE
ini_set('default_socket_timeout', 5);
// setting local error handler to catch possible soap errors
set_error_handler(array($this, 'catchWarning'), E_WARNING);
do {
try {
//connection_timeout = how long we should wait to CONNECT to wsdl server
$oSoapClient = new SoapClient($this->getWsdlUrl(), array("connection_timeout" => 5));
$this->setError('');
$oRes = $oSoapClient->checkVat($oCheckVat);
$iTryMoreCnt = 0;
} catch (SoapFault $e) {
$this->setError($e->faultstring);
if ($this->getError() == "SERVER_BUSY") {
usleep(self::BUSY_RETRY_WAITUSEC);
} else {
$iTryMoreCnt = 0;
}
}
} while (0 < $iTryMoreCnt--);
// restoring previous error handler
restore_error_handler();
return (bool) $oRes->valid;
} else {
$this->setError("SERVICE_UNREACHABLE");
return false;
}
}
示例12: SoapClient
function validate_VAT($country_code, $vat_number)
{
try {
$client = new SoapClient('http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl', array('exceptions' => true));
$result = $client->checkVat(array('countryCode' => $country_code, 'vatNumber' => $vat_number));
return isset($result->valid) ? $result->valid : null;
} catch (Exception $exception) {
return null;
}
}
示例13: validateEUVat
function validateEUVat($args = array())
{
if ('' != $args['vatnumber']) {
$vat_number = str_replace(array(' ', '.', '-', ',', ', '), '', $args['vatnumber']);
$countryCode = substr($vat_number, 0, 2);
$vatNumber = substr($vat_number, 2);
if (strlen($countryCode) != 2 || is_numeric(substr($countryCode, 0, 1)) || is_numeric(substr($countryCode, 1, 2))) {
return FALSE;
//format error 'message' => 'Your VAT Number syntax is not correct. You should have something like this: BE805670816B01'
}
if ($args['country'] != $countryCode) {
return FALSE;
//'message' => 'Your VAT Number is not valid for the selected country.'
}
$client = new SoapClient("http://ec.europa.eu/taxation_customs/vies/services/checkVatService.wsdl");
$params = array('countryCode' => $countryCode, 'vatNumber' => $vatNumber);
$result = $client->checkVat($params);
if (!$result->valid) {
return FALSE;
// 'message' => sprintf('Invalid VAT Number. Check the validity on the customer VAT Number via <a href="%s">Europa VAT Number validation webservice</a>', 'http://ec.europa.eu/taxation_customs/vies/lang.do?fromWhichPage=vieshome'));
} else {
return TRUE;
}
}
return FALSE;
}
示例14: isVIESValidVAT
private function isVIESValidVAT($country, $vat)
{
// Validate VAT number
$vat = trim(strtoupper($vat));
$country = $country == 'GR' ? 'EL' : $country;
// (remove the country prefix if present)
if (substr($vat, 0, 2) == $country) {
$vat = trim(substr($vat, 2));
}
// Is the validation already cached?
$key = $country . $vat;
$ret = null;
if (array_key_exists('vat', $this->_cache)) {
if (array_key_exists($key, $this->_cache['vat'])) {
$ret = $this->_cache['vat'][$key];
}
}
if (!is_null($ret)) {
return $ret;
}
if (empty($vat)) {
$ret = false;
} else {
if (!class_exists('SoapClient')) {
$ret = false;
} else {
// Using the SOAP API
// Code credits: Angel Melguiz / KMELWEBDESIGN SLNE (www.kmelwebdesign.com)
try {
$sOptions = array('user_agent' => 'PHP');
$sClient = new SoapClient('http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl', $sOptions);
$params = array('countryCode' => $country, 'vatNumber' => $vat);
$response = $sClient->checkVat($params);
if ($response->valid) {
$ret = true;
} else {
$ret = false;
}
} catch (SoapFault $e) {
$ret = false;
}
}
}
// Cache the result
if (!array_key_exists('vat', $this->_cache)) {
$this->_cache['vat'] = array();
}
$this->_cache['vat'][$key] = $ret;
$encodedCacheData = json_encode($this->_cache);
$session = JFactory::getSession();
$session->set('validation_cache_data', $encodedCacheData, 'com_akeebasubs');
// Return the result
return $ret;
}
示例15: check_vat_number
/**
* Checks if a vat number is valid
*
* @param type $vat_number VAT number to be checked
* @return bool true if valid, else false
*/
function check_vat_number($vat_number)
{
$vat = strtoupper(str_replace(array(" ", "-", ",", ".", "/", "\\"), "", $vat_number));
if (preg_match("/^(AT|BE|BG|CY|CZ|DE|DK|EE|EL|ES|FI|FR|GB|HU|IE|IT|LT|LU|LV|MT|NL|PL|PT|RO|SE|SI|SK)(.*)/i", $vat, $matches)) {
$country_code = strtoupper($matches[1]);
$vat = $matches[2];
}
if (!isset($country_code)) {
return false;
}
$regex = array('AT' => '/(U[0-9]{8})/i', 'BE' => '/(0[0-9]{9})/i', 'BG' => '/([0-9]{9,10})/i', 'CY' => '/([0-9]{8}[a-z])/i', 'CZ' => '/([0-9]{8}|[0-9]{9}|[0-9]{10})/i', 'DE' => '/([0-9]{9})/i', 'DK' => '/([0-9]{8})/i', 'EE' => '/([0-9]{9})/i', 'EL' => '/([0-9]{9})/i', 'ES' => '/([a-z][0-9]{8}|[0-9]{8}[a-z]|[a-z][0-9]{7}[a-z])/i', 'FI' => '/([0-9]{8})/i', 'FR' => '/([a-z0-9]{2}[0-9]{9})/i', 'GB' => '/([0-9]{9}|[0-9]{12}|GD[0-9]{3}|HA[0-9]{3})/i', 'HU' => '/([0-9]{8})/i', 'IE' => '/([0-9][a-z0-9\\+\\*][0-9]{5}[a-z])/i', 'IT' => '/([0-9]{11})/i', 'LT' => '/([0-9]{9}|[0-9]{12})/i', 'LU' => '/([0-9]{8})/i', 'LV' => '/([0-9]{11})/i', 'MT' => '/([0-9]{8})/i', 'NL' => '/([0-9]{9}B[0-9]{2})/i', 'PL' => '/([0-9]{10})/i', 'PT' => '/([0-9]{9})/i', 'RO' => '/([0-9]{2,10})/i', 'SE' => '/([0-9]{12})/i', 'SI' => '/([0-9]{8})/i', 'SK' => '/([0-9]{10})/i');
if (!isset($regex[$country_code])) {
return false;
}
if (!preg_match($regex[$country_code], $vat, $m)) {
return false;
}
// only ask service is syntax-check is ok
if ($m[1] == $vat) {
try {
$res = cache_get("vat_check_{$country_code}_{$vat}");
if (!$res) {
$sc = new SoapClient("http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl");
$test = $sc->checkVat(array('countryCode' => $country_code, 'vatNumber' => $vat));
if (!$test->valid) {
log_debug("VAT syntax ok, but SOAP says not", $vat_number, $country_code, $vat, $test);
}
$res = $test->valid ? "valid" : "invalid";
cache_set("vat_check_{$country_code}_{$vat}", $res);
} elseif ($res != "valid") {
log_debug("VAT syntax ok, but CACHE says not", $vat_number, $country_code, $vat);
}
return $res == "valid";
} catch (Exception $ex) {
WdfException::Log($ex);
}
return true;
// ignore service exceptions
}
return false;
}