The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Business::Tax::VAT::Validation - A class for european VAT numbers validation.

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

DESCRIPTION

This class provides an easy api to check european VAT numbers' syntax, and if they has been registered by the competent authorities.

It asks the EU database (VIES) for this, using its web interface methods.

CONSTRUCTOR

new Class constructor.
    $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.

PROPERTIES

member_states Returns all member states 2-digit codes as array
    @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, e.g. embedded as javascript in a web form.

    %re=$hvatn->regular_expressions;

returns

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

METHODS

check - Checks if a VAT number exists into the VIES database
    $ok=$hvatn->check($number, [$memberStateCode, $requesterMemberStateCode, $requesterNumber, $traderName, $traderCompanyType, $traderStreet, $traderPostalCode, $traderCity]);

You may either provide the VAT number under its complete form (e.g. BE-123456789, BE123456789) or either specify VAT and MSC (number and memberStateCode) individually.

Valid MS values are :

 AT, BE, BG, CY, CZ, DE, DK, EE, EL, ES,
 FI, FR, GB, HU, IE, IT, LU, LT, LV, MT,
 NL, PL, PT, RO, SE, SI, SK

Additional fields are availaible for all members :

 requesterMemberStateCode
 requesterNumber

Additional fields are availaible for these members :

 EL (Greece)
 ES (Spain)

These fields are :

 traderName
 traderCompanyType
 traderStreet
 traderPostalCode
 traderCity
local_check - Checks if a VAT number format is valid This method is based on regexps only and DOES NOT ask the VIES database
    $ok=$hvatn->local_check($VAT, [$member_state]);
    
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 :

  • 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.

  • 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 !!!

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.

WHY NOT SOAP ?

Just because this module's author wasn't given such time to do so. Furthermore, the SOAP module available at CPAN at time of writing is farly too complex to be used here, simple tasks having to be simply performed. However, if you already use SOAP in your application, it may be better to query the VIES database by this way. See the VIES documentation for further details on how to use it.

SEE ALSO

LWP::UserAgent

FEEDBACK

If you find this module useful, or have any comments, suggestions or improvements, please let me know.

AUTHOR

Bernard Nauwelaerts <bpgn@cpan.org>

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

  • 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

LICENSE

GPL. Enjoy! See COPYING for further informations 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.

1 POD Error

The following errors were encountered while parsing the POD:

Around line 427:

Non-ASCII character seen before =encoding in 'Benoît'. Assuming UTF-8