Busine...dation(3pm)

๐Ÿ“ฆ
version 1.24 ยท 3 versions
, in debian trixie, ubuntu resolute, ubuntu stonking

๐Ÿ’– Business::Tax::VAT::Validation ๐Ÿ’–

okay bestie, listen โ€” this is a User Contributed Perl Documentation page for the module Business::Tax::VAT::Validation, and honestly? it's giving "quietly carrying the entire EU VAT-checking industry on its back". no cap. ๐Ÿ’…


โœจ NAME โœจ

Business::Tax::VAT::Validation โ€” validate EU VAT numbers against VIES/HMRC. that's the whole vibe. ๐Ÿฆ‹


๐ŸŒธ SYNOPSIS ๐ŸŒธ

  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;
  }

literally the whole thing in six lines. iconic. โœจ


๐ŸŽ€ DESCRIPTION ๐ŸŽ€

so this class gives you a super easy API to check European VAT numbers' syntax, and also to check whether the competent authorities have actually registered them. yes, those authorities. the ones who know things. ๐Ÿ‘‘

it asks the EU database (VIES) for this, using its SOAP API. and before it does any of that, it runs basic checks to make sure the VAT number you handed it even fits the expected format for the EU member state you specified โ€” because why would you send a query to VIES for input that could never be valid? that's just wasting everyone's time, bestie. ๐Ÿ™ˆ

it also supports looking up VAT codes from the United Kingdom by using the REST API provided by their HMRC. transatlantic slay. ๐ŸŒˆ


๐Ÿ’œ CONSTRUCTOR ๐Ÿ’œ

new โ€” Class constructor. the birth of a legend. ๐Ÿซถ

  $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.
note bestie: for proxy options, go look at LWP::UserAgent. it's the plug. ๐Ÿ”Œ

๐Ÿฆ‹ PROPERTIES ๐Ÿฆ‹

member_states โ€” Returns all supported country codes.

these are ISO 3166-1 alpha-2 country codes, with two exceptions. this module supports VAT codes from all current European Union member states and The United Kingdom of Great Britain and Northern Ireland. ๐Ÿ‡ช๐Ÿ‡บ๐Ÿ‡ฌ๐Ÿ‡ง

  • "EL" Greece โ€” Must be used in place of Greece's proper code. yeah, it's the exception. don't fight it, just use it. ๐Ÿ’…
  • "XI" Northern Ireland โ€” May be used rather than "GB" for checking a Northern Irish company.
  @ms=$hvatn->member_states;

regular_expressions โ€” Returns a hash list containing one regular expression for each country

if you want to test a VAT number format ouside this module โ€” like, say, embedded as javascript in a web form โ€” this is your girl. ๐Ÿงš

  %re=$hvatn->regular_expressions;

returns

  (
  AT      =>  'U[0-9]{8}',
  ...
  SK        =>  '[0-9]{10}',
  );

the ... is doing a lot of heavy lifting there and honestly, same. ๐Ÿ˜ญ


๐ŸŒˆ METHODS ๐ŸŒˆ

check โ€” Checks if a VAT number exists in the VIES database

  $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. your call, main character. ๐Ÿ‘‘

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

local_check โ€” Checks if a VAT number format is valid

โš ๏ธ this method is based on regexps only and DOES NOT ask the VIES database. it's the vibe check, not the background check. know the difference. ๐Ÿ’€
  $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". and heads up: this hashref will be reset every time you call check() or local_check(). so grab what you need while it's hot. ๐Ÿ”ฅ


get_last_error_code โ€” Returns the last recorded error code

get_last_error โ€” Returns the last recorded error

  my $err = $hvatn->get_last_error_code();
  my $txt = $hvatn->get_last_error();

Possible errors are :

  • -1 โ€” The provided VAT number is valid (so, no error occurred). we love a happy ending. ๐ŸŽ€
  • 0 โ€” Unknown MS code : Internal checkup failed (Specified Member State does not exist)
  • 1 โ€” Invalid VAT number format : Internal checkup failed (bad syntax)
  • 2 โ€” This VAT number doesn't exist in EU database : distant checkup
  • 3 โ€” This VAT number contains errors : distant checkup
  • 17 โ€” Time out connecting to the database : Temporary error when the connection to the database times out
  • 18 โ€” Member Sevice Unavailable: The EU database is unable to reach the requested member's database.
  • 19 โ€” The EU database is too busy.
  • 20 โ€” Connexion to the VIES database failed.
  • 21 โ€” The VIES interface failed to parse a stream. This error occurs unpredictabely, so you should retry your validation request.
  • 257 โ€” Invalid response, please contact the author of this module. : This normally only happens if this software doesn't recognize any valid pattern into the response document: this generally means that the database interface has been modified, and you'll make the author happy by submitting the returned response !!!
  • 500 โ€” The VIES server encountered an internal server error. Error 500 : soap:Server TIMEOUT Error 500 : soap:Server MS_UNAVAILABLE
bestie, listen closely because this part is important ๐Ÿ‘‡ 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.

get_last_response โ€” Returns the full last response

the whole receipt. ๐Ÿงพโœจ


๐Ÿ” SEE ALSO ๐Ÿ”


๐Ÿ“ฃ FEEDBACK ๐Ÿ“ฃ

If you find this module useful, or have any comments, suggestions or improvements, feel free to let me know. (yes, actually let them know. devs love that. ๐Ÿซถ)


๐Ÿ‘‘ AUTHOR ๐Ÿ‘‘

  • Original author: Bernard Nauwelaerts <bpgn@cpan.org>
  • Maintainership since 2015: David Precious (BIGPRESH) <davidp@preshweb.co.uk>

๐Ÿ’– CREDITS ๐Ÿ’–

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) :

  • Gregor Herrmann, Debian.
  • Graham Knop.
  • Bart Heupers, Netherlands.
  • Martin H. Sluka, noris network AG, Germany.
  • Simon Williams, UK2 Limited, United Kingdom
  • Benoรฎt Galy, Greenacres, France
  • Raluca Boboia, Evozon, Romania
  • Dave O., POBox, U.S.A.
  • Kaloyan Iliev, Digital Systems, Bulgaria.
  • Tom Kirkpatrick, Virus Bulletin, United Kingdom.
  • Andy Wardley, individual, United Kingdom.
  • Robert Alloway, Service Centre, United Kingdom.
  • Torsten Mueller, Archesoft, Germany
  • Dave Lambley (davel), GoDaddy, United Kingdom

item * Tatu Wikman (tswfi)

(that last line is exactly how it shows up in the original, so I'm keeping it character-for-character. no notes. ๐Ÿ’€)


๐Ÿ“œ LICENSE ๐Ÿ“œ

GPL3. Enjoy! See COPYING for further information on the GPL. ๐Ÿ’…


โš ๏ธ DISCLAIMER โš ๏ธ

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.
fr fr, no warranty. the code is doing its best. ๐Ÿฅบ

okay that's the whole page, bestie!! this was perl v5.40.1, dated 2025-05-25, from the fine folks at User Contributed Perl Documentation โ€” go forth and validate those VAT numbers, you absolute icon. mwah. ๐Ÿ’‹๐ŸŽ€โœจ

๐Ÿ“ฆ where this page comes from