driesvints / vat-calculator

Handle all the hard stuff related to EU MOSS tax/vat regulations, the way it should be.
MIT License
1.2k stars 88 forks source link

Problem with getIPBasedCountry and isValidVATNumber #7

Closed dadastudio closed 9 years ago

dadastudio commented 9 years ago

Hi,

I try to make use of VatCalculator in Laravel but got this error when running locally:

ErrorException in VatCalculator.php line 136: file_get_contents(http://ip2c.org/::1): failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found

when I run:

$countryCode = VatCalculator::getIPBasedCountry();

I think I installed it correctly because this works: VatCalculator::calculate( 10.00, 'PL' );

Also VatCalculator::isValidVATNumber('NL 123456789 B01'); returns nothing.

Thx.

dadastudio commented 9 years ago

getClientIP() returns ::1, what is $_SERVER[ 'REMOTE_ADDR' ].

mpociot commented 9 years ago

Hi,

The problem is that your local server address is 127.0.0.1 or localhost, or even ::1.

Since your PHP server is running locally it only knows about your local IP address, which of course can't be resolved to a country.

About the "isValidVATNumber" issue - what ia the response? It can either throw an exception or return true/false.

dadastudio commented 9 years ago

Thank you for a quick response. The problem was that I wanted to echo the result and when vat was invalid it echoed nothing. It works correctly with if.

Thanks. And excuse me for bothering. :)

mpociot commented 9 years ago

No problem :)