Jump to content

[SOLVED] VAT number validation service unavailable


Recommended Posts

 

Hi steptravel,

In line 119 of your /modules/vatnumber/vatnumber.php file, please increase the value here:

 

@ini_set('default_socket_timeout', 2);

 

 

 

Thank you Mike, but can you write me the code more accurately, cause in line 119 I have different things. Maybe you can write what's above this line as well?

Link to comment
Share on other sites

Hi steptravel,

That full string, @ini_set('default_socket_timeout', 2), should only be found once in your vatnumber.php file in v1.4.4.1. And all you need to do to increase the value is change "2" to a larger number, such as 5, and then be sure to save it via FTP.

 

I hope this helps.

 

-Mike

Link to comment
Share on other sites

  • 1 year later...
  • 1 month later...

I have realized that the problem only occurs online and not on my local server.

On my local server, I have php 5.3.8, and online 5.3.4, do we have to use php 5.3.8 for that module to work?

I have compared the php.ini, and I can't see any major differences.

Does somebody have an idea?

Link to comment
Share on other sites

  • 3 months later...
  • 2 months later...
  • 3 months later...
Creating a stream context with a User-Agent did the trick for me:
 
	public static function WebServiceCheck($vatNumber)
	{
		if (empty($vatNumber))
			return array();
		$vatNumber = str_replace(' ', '', $vatNumber);
		$prefix = substr($vatNumber, 0, 2);
		if (array_search($prefix, self::getPrefixIntracomVAT()) === false)
			return array(Tools::displayError('Invalid VAT number'));
		// EDK addition. Seems the site requires a user agent
		$options = array(
		  'http'=>array(
		    'method'=>"GET",
		    'header'=>"User-Agent: Mozilla/5.0 (Windows NT 6.2; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1667.0 Safari/537.36\r\n" // i.e. An iPad 
		  )
		);

		$context = stream_context_create($options);
		// EDK end

		$vat = substr($vatNumber, 2);
		$url = 'http://ec.europa.eu/taxation_customs/vies/viesquer.do?ms='.urlencode($prefix).'&iso='.urlencode($prefix).'&vat='.urlencode($vat);
		@ini_set('default_socket_timeout', 2);
		for ($i = 0; $i < 3; $i++)
		{
			// if ($pageRes = file_get_contents($url))
			if ($pageRes = file_get_contents($url, false, $context)) // EDK
			{
				if (preg_match('/invalid VAT number/i', $pageRes))
				{
					@ini_restore('default_socket_timeout');
					return array(Tools::displayError('VAT number not found'));
				}
				else if (preg_match('/valid VAT number/i', $pageRes))
				{
					@ini_restore('default_socket_timeout');
					return array();
				}
				else
					++$i;
			}
			else
				sleep(1);
		}
		@ini_restore('default_socket_timeout');
		return array(Tools::displayError('VAT number validation service unavailable'));
	}

Changing the socket time out had no effect.

 

Prestashop 1.5.6.1, VAT module European VAT number 1.2

 

<edit> Update was not such a big success so now I'm back on 1.5.6.0. Problem and solution are the same. </edit>

Edited by Etienne Doek (see edit history)
  • Like 1
Link to comment
Share on other sites

  • 1 month later...

 

Creating a stream context with a User-Agent did the trick for me:
 
	public static function WebServiceCheck($vatNumber)
	{
		if (empty($vatNumber))
			return array();
		$vatNumber = str_replace(' ', '', $vatNumber);
		$prefix = substr($vatNumber, 0, 2);
		if (array_search($prefix, self::getPrefixIntracomVAT()) === false)
			return array(Tools::displayError('Invalid VAT number'));
		// EDK addition. Seems the site requires a user agent
		$options = array(
		  'http'=>array(
		    'method'=>"GET",
		    'header'=>"User-Agent: Mozilla/5.0 (Windows NT 6.2; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1667.0 Safari/537.36\r\n" // i.e. An iPad 
		  )
		);

		$context = stream_context_create($options);
		// EDK end

		$vat = substr($vatNumber, 2);
		$url = 'http://ec.europa.eu/taxation_customs/vies/viesquer.do?ms='.urlencode($prefix).'&iso='.urlencode($prefix).'&vat='.urlencode($vat);
		@ini_set('default_socket_timeout', 2);
		for ($i = 0; $i < 3; $i++)
		{
			// if ($pageRes = file_get_contents($url))
			if ($pageRes = file_get_contents($url, false, $context)) // EDK
			{
				if (preg_match('/invalid VAT number/i', $pageRes))
				{
					@ini_restore('default_socket_timeout');
					return array(Tools::displayError('VAT number not found'));
				}
				else if (preg_match('/valid VAT number/i', $pageRes))
				{
					@ini_restore('default_socket_timeout');
					return array();
				}
				else
					++$i;
			}
			else
				sleep(1);
		}
		@ini_restore('default_socket_timeout');
		return array(Tools::displayError('VAT number validation service unavailable'));
	}

Changing the socket time out had no effect.

 

Prestashop 1.5.6.1, VAT module European VAT number 1.2

 

<edit> Update was not such a big success so now I'm back on 1.5.6.0. Problem and solution are the same. </edit>

 

 

I had the same issue.

The solution above works on PrestaShop 1.5.6.2 and European VAT number 1.2.

 

But why they do not issue European VAT number update?

Link to comment
Share on other sites

  • 9 months later...

I am having the same issue on PS 1.6 with vat module version 1.7.2. The thing is I only get the error when I introduce a vat number from my own country (when tax should still be applied). Other valid EU vat numbers are validated fine but not the Vat numbers from my ouwn country (Spain). I already have Spain selected as "my country" on the vat configuration page.

 

Anyone else having the same issue?

Link to comment
Share on other sites

  • 2 years later...

Hello,

 

1.5.4.1 and module v.1.7.

 

EU service was down few days ago for some minutes and now module is giving error "service not available"

 

I have:

 

- reset module

- increase timeout value from 2 to 10

- url link seems ok

   http://ec.europa.eu/taxation_customs/vies/viesquer.do?ms='.urlencode($prefix).'&iso='.urlencode($prefix).'&vat='.urlencode($vat);

 

Anything else to check?

Link to comment
Share on other sites

×
×
  • Create New...