enabled = Horde_Util::loadExtension('soap');
$this->_name = _("EU VAT identification");
}
/**
*/
protected function _title()
{
return _("VAT id number verification");
}
/**
*/
protected function _content()
{
global $page_output;
$name = strval(new Horde_Support_Randomid());
$page_output->addScriptFile('vatid.js', 'horde');
$page_output->addInlineScript(array(
'$("' . $name . '").observe("submit", HordeBlockVatid.onSubmit.bindAsEventListener(HordeBlockVatid))'
), true);
return '
';
}
/**
*/
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 '
' . $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 .= ''
. _("This VAT identification number is valid.")
. '
';
} else {
$html .= $this->_error(_("This VAT identification number is invalid.")) . '
';
}
$html .= '' . _("Country") . ': '
. $result->countryCode . '
'
. _("VAT number") . ': ' . $result->vatNumber
. '
' . _("Date") . ': '
. strftime($GLOBALS['prefs']->getValue('date_format'), strtotime($result->requestDate))
. '
';
if (!empty($result->name)) {
$html .= '' . _("Name") . ': ' . $result->name . '
';
}
if (!empty($result->address)) {
$html .= '' . _("Address") . ': ' . $result->address . '
';
}
} 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;
}
/**
*/
private function _error($text)
{
return '' . $text . '';
}
}