Business::Tax::VAT::Validation(3pm) | User Contributed Perl Documentation | Business::Tax::VAT::Validation(3pm) |
Business::Tax::VAT::Validation - Validate EU VAT numbers against VIES/HMRC
use Business::Tax::VAT::Validation; my $hvatn=Business::Tax::VAT::Validation->new(); # Check number if ($hvatn->check($VAT, [$member_state])){ print "OK\n"; } else { print $hvatn->get_last_error; }
This class provides an easy API to check European VAT numbers' syntax, and check if they have been registered by the competent authorities.
It asks the EU database (VIES) for this, using its SOAP API. Basic checks that the supplied VAT number fit the expected format for the specified EU member state are performed first, to avoid unnecessarily sending queries to VIES for input that could never be valid.
It also supports looking up VAT codes from the United Kingdom by using the REST API provided by their HMRC.
$hvatn=Business::Tax::VAT::Validation->new(); # If your system is located behind a proxy : $hvatn=Business::Tax::VAT::Validation->new(-proxy => ['http', 'http://example.com:8001/']); # Note : See LWP::UserAgent for proxy options.
@ms=$hvatn->member_states;
%re=$hvatn->regular_expressions;
returns
( AT => 'U[0-9]{8}', ... SK => '[0-9]{10}', );
$ok=$hvatn->check($vatNumber, [$countryCode]);
You may either provide the VAT number under its complete form (e.g. BE-123456789, BE123456789) or specify the VAT and MSC (vatNumber and countryCode) individually.
Valid MS values are :
AT, BE, BG, CY, CZ, DE, DK, EE, EL, ES, FI, FR, GB, HR, HU, IE, IT, LU, LT, LV, MT, NL, PL, PT, RO, SE, SI, SK, XI
$ok=$hvatn->local_check($VAT, [$member_state]);
# Get all available information as a hashref: my $info = $hvatn->information(); # Get a particular key: my $address = $hvatn->information('address');
Which information is offered depends on the checker used - for UK VAT numbers, checked via the HMRC API, "address" is the only key which will be set.
For EU VAT numbers checked via VIES, you can expect "name" and "address". This hashref will be reset every time you call check() or local_check()
my $err = $hvatn->get_last_error_code(); my $txt = $hvatn->get_last_error();
Possible errors are :
If error_code > 16, you should temporarily accept the provided number, and periodically perform new checks until response is OK or error < 17 If error_code > 256, you should temporarily accept the provided number, contact the author, and perform a new check when the software is updated.
LWP::UserAgent
<http://ec.europa.eu/taxation_customs/vies/faqvies.do> for the FAQs related to the VIES service.
<https://developer.service.hmrc.gov.uk/api-documentation/docs/api/service/vat-registered-companies-api/1.0> for details of the service provided by the UK's HMRC.
If you find this module useful, or have any comments, suggestions or improvements, feel free to let me know.
Original author: Bernard Nauwelaerts <bpgn@cpan.org>
Maintainership since 2015: David Precious (BIGPRESH) <davidp@preshweb.co.uk>
Many thanks to the following people, actively involved in the development of this software by submitting patches, bug reports, new members regexps, VIES interface changes,... (sorted by last intervention) :
item * Tatu Wikman (tswfi)
GPL3. Enjoy! See COPYING for further information on the GPL.
See <http://ec.europa.eu/taxation_customs/vies/viesdisc.do> to known the limitations of the EU validation service.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
2022-08-21 | perl v5.34.0 |