| 1 | package Business::Tax::VAT::Validation; | ||||||||||||||||||||||||||||||||||||
| 2 | =pod | ||||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||||
| 4 | =encoding UTF-8 | ||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||
| 6 | =cut | ||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||
| 8 | ############################################################################ | ||||||||||||||||||||||||||||||||||||
| 9 | # Original author: # | ||||||||||||||||||||||||||||||||||||
| 10 | # IT Development software # | ||||||||||||||||||||||||||||||||||||
| 11 | # European VAT number validator # | ||||||||||||||||||||||||||||||||||||
| 12 | # Created 06/08/2003 # | ||||||||||||||||||||||||||||||||||||
| 13 | # # | ||||||||||||||||||||||||||||||||||||
| 14 | # Maintainership kindly handed over to David Precious (BIGPRESH) in 2015 # | ||||||||||||||||||||||||||||||||||||
| 15 | ############################################################################ | ||||||||||||||||||||||||||||||||||||
| 16 | # COPYRIGHT NOTICE # | ||||||||||||||||||||||||||||||||||||
| 17 | # Copyright 2003 Bernard Nauwelaerts All Rights Reserved. # | ||||||||||||||||||||||||||||||||||||
| 18 | # Copyright 2015 David Precious All Rights Reserved. # | ||||||||||||||||||||||||||||||||||||
| 19 | # # | ||||||||||||||||||||||||||||||||||||
| 20 | # THIS SOFTWARE IS RELEASED UNDER THE GNU Public Licence version 3 # | ||||||||||||||||||||||||||||||||||||
| 21 | # Please see COPYING for details # | ||||||||||||||||||||||||||||||||||||
| 22 | # # | ||||||||||||||||||||||||||||||||||||
| 23 | # DISCLAIMER # | ||||||||||||||||||||||||||||||||||||
| 24 | # As usual with GNU software, this one is provided as is, # | ||||||||||||||||||||||||||||||||||||
| 25 | # WITHOUT ANY WARRANTY, without even the implied warranty of # | ||||||||||||||||||||||||||||||||||||
| 26 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. # | ||||||||||||||||||||||||||||||||||||
| 27 | # # | ||||||||||||||||||||||||||||||||||||
| 28 | ############################################################################ | ||||||||||||||||||||||||||||||||||||
| 29 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 30 | 4 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||
| 32 | 4 | our $VERSION = '1.24'; | |||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||
| 34 | 4 | ▶ | use HTTP::Request::Common qw(POST); | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 35 | 4 | ▶ | use LWP::UserAgent; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 36 | 4 | ▶ | use JSON qw/ decode_json /; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||
| 38 | =head1 NAME | ||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||
| 40 | Business::Tax::VAT::Validation - Validate EU VAT numbers against VIES/HMRC | ||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||
| 42 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||
| 44 | use Business::Tax::VAT::Validation; | ||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||
| 46 | my $hvatn=Business::Tax::VAT::Validation->new(); | ||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||
| 48 | # Check number | ||||||||||||||||||||||||||||||||||||
| 49 | if ($hvatn->check($VAT, [$member_state])){ | ||||||||||||||||||||||||||||||||||||
| 50 | print "OK\n"; | ||||||||||||||||||||||||||||||||||||
| 51 | } else { | ||||||||||||||||||||||||||||||||||||
| 52 | print $hvatn->get_last_error; | ||||||||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||
| 55 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||
| 57 | This class provides an easy API to check European VAT numbers' syntax, | ||||||||||||||||||||||||||||||||||||
| 58 | and check if they have been registered by the competent authorities. | ||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||
| 60 | It asks the EU database (VIES) for this, using its SOAP API. Basic checks that | ||||||||||||||||||||||||||||||||||||
| 61 | the supplied VAT number fit the expected format for the specified EU member | ||||||||||||||||||||||||||||||||||||
| 62 | state are performed first, to avoid unnecessarily sending queries to VIES for | ||||||||||||||||||||||||||||||||||||
| 63 | input that could never be valid. | ||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||
| 65 | It also supports looking up VAT codes from the United Kingdom by using the | ||||||||||||||||||||||||||||||||||||
| 66 | REST API provided by their HMRC. | ||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||
| 68 | =head1 CONSTRUCTOR | ||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||
| 70 | =over 4 | ||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||
| 72 | =item B<new> Class constructor. | ||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||
| 74 | $hvatn=Business::Tax::VAT::Validation->new(); | ||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||
| 77 | # If your system is located behind a proxy : | ||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||
| 79 | $hvatn=Business::Tax::VAT::Validation->new(-proxy => ['http', 'http://example.com:8001/']); | ||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||
| 81 | # Note : See LWP::UserAgent for proxy options. | ||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||
| 83 | =cut | ||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||
| 85 | 3 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=3 SCAR=11.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 86 | 3 | my ( $class, %arg ) = @_; | |||||||||||||||||||||||||||||||||||
| 87 | my $self = { | ||||||||||||||||||||||||||||||||||||
| 88 | baseurl => $arg{baseurl} || 'https://ec.europa.eu/taxation_customs/vies/services/checkVatService', | ||||||||||||||||||||||||||||||||||||
| 89 | hmrc_baseurl => $arg{hmrc_baseurl} || 'https://api.service.hmrc.gov.uk/organisations/vat/check-vat-number/lookup/', | ||||||||||||||||||||||||||||||||||||
| 90 | error => '', | ||||||||||||||||||||||||||||||||||||
| 91 | error_code => 0, | ||||||||||||||||||||||||||||||||||||
| 92 | response => '', | ||||||||||||||||||||||||||||||||||||
| 93 | re => { | ||||||||||||||||||||||||||||||||||||
| 94 | ### t/01_localcheck.t tests if these regexps accepts all regular VAT numbers, according to VIES FAQ | ||||||||||||||||||||||||||||||||||||
| 95 | AT => 'U[0-9]{8}', | ||||||||||||||||||||||||||||||||||||
| 96 | BE => '[01][0-9]{9}', | ||||||||||||||||||||||||||||||||||||
| 97 | BG => '[0-9]{9,10}', | ||||||||||||||||||||||||||||||||||||
| 98 | CY => '[0-9]{8}[A-Za-z]', | ||||||||||||||||||||||||||||||||||||
| 99 | CZ => '[0-9]{8,10}', | ||||||||||||||||||||||||||||||||||||
| 100 | DE => '[0-9]{9}', | ||||||||||||||||||||||||||||||||||||
| 101 | DK => '[0-9]{2} ?[0-9]{2} ?[0-9]{2} ?[0-9]{2}', | ||||||||||||||||||||||||||||||||||||
| 102 | EE => '[0-9]{9}', | ||||||||||||||||||||||||||||||||||||
| 103 | EL => '[0-9]{9}', | ||||||||||||||||||||||||||||||||||||
| 104 | ES => '([A-Za-z0-9][0-9]{7}[A-Za-z0-9])', | ||||||||||||||||||||||||||||||||||||
| 105 | FI => '[0-9]{8}', | ||||||||||||||||||||||||||||||||||||
| 106 | FR => '[A-Za-z0-9]{2} ?[0-9]{9}', | ||||||||||||||||||||||||||||||||||||
| 107 | GB => '([0-9]{3} ?[0-9]{4} ?[0-9]{2}|[0-9]{3} ?[0-9]{4} ?[0-9]{2} ?[0-9]{3}|GD[0-9]{3}|HA[0-9]{3})', | ||||||||||||||||||||||||||||||||||||
| 108 | HR => '[0-9]{11}', | ||||||||||||||||||||||||||||||||||||
| 109 | HU => '[0-9]{8}', | ||||||||||||||||||||||||||||||||||||
| 110 | IE => '[0-9][A-Za-z0-9\+\*][0-9]{5}[A-Za-z]{1,2}', | ||||||||||||||||||||||||||||||||||||
| 111 | IT => '[0-9]{11}', | ||||||||||||||||||||||||||||||||||||
| 112 | LT => '([0-9]{9}|[0-9]{12})', | ||||||||||||||||||||||||||||||||||||
| 113 | LU => '[0-9]{8}', | ||||||||||||||||||||||||||||||||||||
| 114 | LV => '[0-9]{11}', | ||||||||||||||||||||||||||||||||||||
| 115 | MT => '[0-9]{8}', | ||||||||||||||||||||||||||||||||||||
| 116 | NL => '[0-9]{9}B[0-9]{2}', | ||||||||||||||||||||||||||||||||||||
| 117 | PL => '[0-9]{10}', | ||||||||||||||||||||||||||||||||||||
| 118 | PT => '[0-9]{9}', | ||||||||||||||||||||||||||||||||||||
| 119 | RO => '[0-9]{2,10}', | ||||||||||||||||||||||||||||||||||||
| 120 | SE => '[0-9]{12}', | ||||||||||||||||||||||||||||||||||||
| 121 | SI => '[0-9]{8}', | ||||||||||||||||||||||||||||||||||||
| 122 | SK => '[0-9]{10}', | ||||||||||||||||||||||||||||||||||||
| 123 | XI => '([0-9]{3} ?[0-9]{4} ?[0-9]{2}|[0-9]{3} ?[0-9]{4} ?[0-9]{2} ?[0-9]{3}|GD[0-9]{3}|HA[0-9]{3})', | ||||||||||||||||||||||||||||||||||||
| 124 | }, | ||||||||||||||||||||||||||||||||||||
| 125 | proxy => $arg{-proxy}, | ||||||||||||||||||||||||||||||||||||
| 126 | 3 | ▶ | information => {} | ||||||||||||||||||||||||||||||||||
|
Condition50%2/4
$arg{'baseurl'} || 'https://ec.europa.eu/taxation_customs/vies/services/checkVatService'
$arg{'hmrc_baseurl'} || 'https://api.service.hmrc.gov.uk/organisations/vat/check-vat-number/lookup/'
MC/DC0%0/1
$arg{'baseurl'} || 'https://ec.europa.eu/taxation_customs/vies/services/checkVatService'
$arg{'baseurl'}
MC/DC0%0/1
$arg{'hmrc_baseurl'} || 'https://api.service.hmrc.gov.uk/organisations/vat/check-vat-number/lookup/'
$arg{'hmrc_baseurl'}
Truth table50%1/2
A
A= $arg{'baseurl'}
Truth table50%1/2
A
A= $arg{'hmrc_baseurl'}
| |||||||||||||||||||||||||||||||||||||
| 127 | }; | ||||||||||||||||||||||||||||||||||||
| 128 | 3 | $self = bless $self, $class; | |||||||||||||||||||||||||||||||||||
| 129 | 3 | $self->{members} = join( '|', keys %{ $self->{re} } ); | |||||||||||||||||||||||||||||||||||
| 130 | 3 | $self; | |||||||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||
| 133 | =back | ||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||
| 135 | =head1 PROPERTIES | ||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||
| 137 | =over 4 | ||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||
| 139 | =item B<member_states> Returns all supported country codes. | ||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||
| 141 | These are ISO 3166-1 alpha-2 country codes with two exceptions. This module | ||||||||||||||||||||||||||||||||||||
| 142 | supports VAT codes from all current European Union member states and The United | ||||||||||||||||||||||||||||||||||||
| 143 | Kingdom of Great Britain and Northern Ireland. | ||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||
| 145 | =over 4 | ||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||
| 147 | =item C<EL> Greece | ||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||
| 149 | Must be used in place of Greece's proper code. | ||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||
| 151 | =item C<XI> Northern Ireland | ||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||
| 153 | May be used rather than C<GB> for checking a Northern Irish company. | ||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||
| 155 | =back | ||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||
| 157 | @ms=$hvatn->member_states; | ||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||
| 159 | =cut | ||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||
| 161 | 0 | ▶ | sub member_states { | ||||||||||||||||||||||||||||||||||
|
Subroutine
member_states: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 162 | 0 | ( keys %{ $_[0]->{re} } ); | |||||||||||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||
| 165 | =item B<regular_expressions> - Returns a hash list containing one regular expression for each country | ||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||
| 167 | If you want to test a VAT number format ouside this module, e.g. embedded as javascript in a web form. | ||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||
| 169 | %re=$hvatn->regular_expressions; | ||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||
| 171 | returns | ||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||
| 173 | ( | ||||||||||||||||||||||||||||||||||||
| 174 | AT => 'U[0-9]{8}', | ||||||||||||||||||||||||||||||||||||
| 175 | ... | ||||||||||||||||||||||||||||||||||||
| 176 | SK => '[0-9]{10}', | ||||||||||||||||||||||||||||||||||||
| 177 | ); | ||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||
| 179 | =cut | ||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||
| 181 | 0 | ▶ | sub regular_expressions { | ||||||||||||||||||||||||||||||||||
|
Subroutine
regular_expressions: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 182 | 0 | ( %{ $_[0]->{re} } ); | |||||||||||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||
| 185 | =back | ||||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||||
| 187 | =head1 METHODS | ||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||
| 189 | =cut | ||||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||||
| 191 | =over 4 | ||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||
| 193 | =item B<check> - Checks if a VAT number exists in the VIES database | ||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||
| 195 | $ok=$hvatn->check($vatNumber, [$countryCode]); | ||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||
| 197 | You may either provide the VAT number under its complete form (e.g. BE-123456789, BE123456789) | ||||||||||||||||||||||||||||||||||||
| 198 | or specify the VAT and MSC (vatNumber and countryCode) individually. | ||||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||
| 200 | Valid MS values are : | ||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||
| 202 | AT, BE, BG, CY, CZ, DE, DK, EE, EL, ES, | ||||||||||||||||||||||||||||||||||||
| 203 | FI, FR, GB, HR, HU, IE, IT, LU, LT, LV, | ||||||||||||||||||||||||||||||||||||
| 204 | MT, NL, PL, PT, RO, SE, SI, SK, XI | ||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||
| 206 | =cut | ||||||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||||||
| 208 | 0 | ▶ | sub check { | ||||||||||||||||||||||||||||||||||
|
Subroutine
check: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 209 | 0 | my ($self, $vatNumber, $countryCode, @other) = @_; # @other is here for backward compatibility purposes | |||||||||||||||||||||||||||||||||||
| 210 | 0 | $self->{information} = {}; | |||||||||||||||||||||||||||||||||||
| 211 | 0 | ▶ | return $self->_set_error('You must provide a VAT number') unless $vatNumber; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 212 | 0 | ▶ | $countryCode ||= ''; | ||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$countryCode ||= ""
MC/DC0%0/1
$countryCode ||= ""
$countryCode
Truth table0%0/2
A
A= $countryCode
| |||||||||||||||||||||||||||||||||||||
| 213 | 0 | ( $vatNumber, $countryCode ) = $self->_format_vatn( $vatNumber, $countryCode ); | |||||||||||||||||||||||||||||||||||
| 214 | 0 | ▶ | if ($vatNumber) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 215 | 0 | ▶ | if ($countryCode eq 'GB') { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 216 | 0 | return $self->_check_hmrc($vatNumber, $countryCode); | |||||||||||||||||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||||||||||||||||
| 218 | 0 | return $self->_check_vies($vatNumber, $countryCode); | |||||||||||||||||||||||||||||||||||
| 219 | } | ||||||||||||||||||||||||||||||||||||
| 220 | 0 | 0; | |||||||||||||||||||||||||||||||||||
| 221 | } | ||||||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||||||
| 223 | =item B<local_check> - Checks if a VAT number format is valid | ||||||||||||||||||||||||||||||||||||
| 224 | This method is based on regexps only and DOES NOT ask the VIES database | ||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||
| 226 | $ok=$hvatn->local_check($VAT, [$member_state]); | ||||||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||||||
| 229 | =cut | ||||||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||||||
| 231 | 144 | ▶ | sub local_check { | ||||||||||||||||||||||||||||||||||
|
Subroutine
local_check: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 232 | 144 | my ( $self, $vatn, $mscc, @other ) = @_; # @other is here for backward compatibility purposes | |||||||||||||||||||||||||||||||||||
| 233 | 144 | $self->{information} = {}; | |||||||||||||||||||||||||||||||||||
| 234 | 144 | ▶ | return $self->_set_error('You must provide a VAT number') unless $vatn; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 235 | 144 | ▶ | $mscc ||= ''; | ||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$mscc ||= ""
MC/DC100%1/1
$mscc ||= ""
$mscc
Truth table100%2/2
A
A= $mscc
| |||||||||||||||||||||||||||||||||||||
| 236 | 144 | ( $vatn, $mscc ) = $self->_format_vatn( $vatn, $mscc ); | |||||||||||||||||||||||||||||||||||
| 237 | 144 | ▶ | if ($vatn) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 238 | 59 | return 1; | |||||||||||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||||||||||
| 240 | else { | ||||||||||||||||||||||||||||||||||||
| 241 | 85 | return 0; | |||||||||||||||||||||||||||||||||||
| 242 | } | ||||||||||||||||||||||||||||||||||||
| 243 | } | ||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||
| 245 | =item B<information> - Returns information related to the last checked VAT number | ||||||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||||||
| 247 | # Get all available information as a hashref: | ||||||||||||||||||||||||||||||||||||
| 248 | my $info = $hvatn->information(); | ||||||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||||
| 250 | # Get a particular key: | ||||||||||||||||||||||||||||||||||||
| 251 | my $address = $hvatn->information('address'); | ||||||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||||||
| 253 | Which information is offered depends on the checker used - for UK VAT numbers, | ||||||||||||||||||||||||||||||||||||
| 254 | checked via the HMRC API, C<address> is the only key which will be set. | ||||||||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||||||||
| 256 | For EU VAT numbers checked via VIES, you can expect C<name> and C<address>. | ||||||||||||||||||||||||||||||||||||
| 257 | This hashref will be reset every time you call check() or local_check() | ||||||||||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||||||||||
| 259 | =cut | ||||||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||||||
| 261 | 0 | ▶ | sub information { | ||||||||||||||||||||||||||||||||||
|
Subroutine
information: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 262 | 0 | my ( $self, $key, @other ) = @_; | |||||||||||||||||||||||||||||||||||
| 263 | 0 | ▶ | if ($key) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 264 | 0 | return $self->{information}{$key} | |||||||||||||||||||||||||||||||||||
| 265 | } else { | ||||||||||||||||||||||||||||||||||||
| 266 | return ($self->{information}) | ||||||||||||||||||||||||||||||||||||
| 267 | 0 | } | |||||||||||||||||||||||||||||||||||
| 268 | } | ||||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||||
| 270 | =item B<get_last_error_code> - Returns the last recorded error code | ||||||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||||||
| 272 | =item B<get_last_error> - Returns the last recorded error | ||||||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||||||
| 274 | my $err = $hvatn->get_last_error_code(); | ||||||||||||||||||||||||||||||||||||
| 275 | my $txt = $hvatn->get_last_error(); | ||||||||||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||||||||||
| 277 | Possible errors are : | ||||||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||||||
| 279 | =over 4 | ||||||||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||||||||
| 281 | =item * | ||||||||||||||||||||||||||||||||||||
| 282 | -1 The provided VAT number is valid (so, no error occurred) | ||||||||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||||||
| 284 | =item * | ||||||||||||||||||||||||||||||||||||
| 285 | 0 Unknown MS code : Internal checkup failed (Specified Member State does not exist) | ||||||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||||||
| 287 | =item * | ||||||||||||||||||||||||||||||||||||
| 288 | 1 Invalid VAT number format : Internal checkup failed (bad syntax) | ||||||||||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||||||||||
| 290 | =item * | ||||||||||||||||||||||||||||||||||||
| 291 | 2 This VAT number doesn't exist in EU database : distant checkup | ||||||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||||||
| 293 | =item * | ||||||||||||||||||||||||||||||||||||
| 294 | 3 This VAT number contains errors : distant checkup | ||||||||||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||||||||||
| 296 | =item * | ||||||||||||||||||||||||||||||||||||
| 297 | 17 Time out connecting to the database : Temporary error when the connection to the database times out | ||||||||||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||||||||||
| 299 | =item * | ||||||||||||||||||||||||||||||||||||
| 300 | 18 Member Sevice Unavailable: The EU database is unable to reach the requested member's database. | ||||||||||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||||||||||
| 302 | =item * | ||||||||||||||||||||||||||||||||||||
| 303 | 19 The EU database is too busy. | ||||||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||||||
| 305 | =item * | ||||||||||||||||||||||||||||||||||||
| 306 | 20 Connexion to the VIES database failed. | ||||||||||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||||||||||
| 308 | =item * | ||||||||||||||||||||||||||||||||||||
| 309 | 21 The VIES interface failed to parse a stream. This error occurs unpredictabely, so you should retry your validation request. | ||||||||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||||||||
| 311 | =item * | ||||||||||||||||||||||||||||||||||||
| 312 | 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 !!! | ||||||||||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||||||||||
| 314 | =item * | ||||||||||||||||||||||||||||||||||||
| 315 | 500 The VIES server encountered an internal server error. | ||||||||||||||||||||||||||||||||||||
| 316 | Error 500 : soap:Server TIMEOUT | ||||||||||||||||||||||||||||||||||||
| 317 | Error 500 : soap:Server MS_UNAVAILABLE | ||||||||||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||||||||||
| 319 | =back | ||||||||||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||||||||
| 321 | If error_code > 16, you should temporarily accept the provided number, and periodically perform new checks until response is OK or error < 17 | ||||||||||||||||||||||||||||||||||||
| 322 | If error_code > 256, you should temporarily accept the provided number, contact the author, and perform a new check when the software is updated. | ||||||||||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||||||||||
| 324 | =cut | ||||||||||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||||||||||
| 326 | 0 | ▶ | sub get_last_error { | ||||||||||||||||||||||||||||||||||
|
Subroutine
get_last_error: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 327 | 0 | $_[0]->{error}; | |||||||||||||||||||||||||||||||||||
| 328 | } | ||||||||||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||||||||||
| 330 | 0 | ▶ | sub get_last_error_code { | ||||||||||||||||||||||||||||||||||
|
Subroutine
get_last_error_code: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 331 | 0 | $_[0]->{error_code}; | |||||||||||||||||||||||||||||||||||
| 332 | } | ||||||||||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||||||||||
| 334 | =item B<get_last_response> - Returns the full last response | ||||||||||||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||||||||||
| 336 | =cut | ||||||||||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||||||||||
| 338 | 0 | ▶ | sub get_last_response { | ||||||||||||||||||||||||||||||||||
|
Subroutine
get_last_response: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 339 | 0 | $_[0]->{response}; | |||||||||||||||||||||||||||||||||||
| 340 | } | ||||||||||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||||||||||
| 342 | ### PRIVATE FUNCTIONS ========================================================== | ||||||||||||||||||||||||||||||||||||
| 343 | 0 | ▶ | sub _get_ua { | ||||||||||||||||||||||||||||||||||
|
Subroutine
_get_ua: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||
| 344 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||
| 345 | 0 | my $ua = LWP::UserAgent->new; | |||||||||||||||||||||||||||||||||||
| 346 | 0 | ▶ | if ( ref $self->{proxy} eq 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 347 | 0 | $ua->proxy( @{ $self->{proxy} } ); | |||||||||||||||||||||||||||||||||||
| 348 | } else { | ||||||||||||||||||||||||||||||||||||
| 349 | 0 | $ua->env_proxy; | |||||||||||||||||||||||||||||||||||
| 350 | } | ||||||||||||||||||||||||||||||||||||
| 351 | 0 | $ua->agent( 'Business::Tax::VAT::Validation/'. $Business::Tax::VAT::Validation::VERSION ); | |||||||||||||||||||||||||||||||||||
| 352 | 0 | return $ua; | |||||||||||||||||||||||||||||||||||
| 353 | } | ||||||||||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||||||||||
| 355 | 0 | ▶ | sub _check_vies { | ||||||||||||||||||||||||||||||||||
|
Subroutine
_check_vies: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||
| 356 | 0 | my ($self, $vatNumber, $countryCode) = @_; | |||||||||||||||||||||||||||||||||||
| 357 | 0 | my $ua = $self->_get_ua(); | |||||||||||||||||||||||||||||||||||
| 358 | 0 | my $request = HTTP::Request->new(POST => $self->{baseurl}); | |||||||||||||||||||||||||||||||||||
| 359 | 0 | $request->content(_in_soap_envelope($vatNumber, $countryCode)); | |||||||||||||||||||||||||||||||||||
| 360 | 0 | $request->content_type("text/xml; charset=utf-8"); | |||||||||||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||||||||||
| 362 | 0 | my $response = $ua->request($request); | |||||||||||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||||||||||
| 364 | 0 | ▶ | return $countryCode . '-' . $vatNumber if $self->_is_res_ok( $response->code, $response->decoded_content ); | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 365 | } | ||||||||||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||||||||||
| 367 | 0 | ▶ | sub _check_hmrc { | ||||||||||||||||||||||||||||||||||
|
Subroutine
_check_hmrc: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||||||||
| 368 | 0 | my ($self, $vatNumber, $countryCode) = @_; | |||||||||||||||||||||||||||||||||||
| 369 | 0 | my $ua = $self->_get_ua(); | |||||||||||||||||||||||||||||||||||
| 370 | |||||||||||||||||||||||||||||||||||||
| 371 | 0 | my $request = HTTP::Request->new(GET => $self->{hmrc_baseurl}.$vatNumber); | |||||||||||||||||||||||||||||||||||
| 372 | 0 | $request->header(Accept => 'application/vnd.hmrc.1.0+json'); | |||||||||||||||||||||||||||||||||||
| 373 | 0 | my $response = $ua->request($request); | |||||||||||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||||||||||
| 375 | 0 | $self->{res} = $response->decoded_content; | |||||||||||||||||||||||||||||||||||
| 376 | 0 | ▶ | if ($response->code == 200) { | ||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||
| 377 | 0 | my $data = decode_json($self->{res}); | |||||||||||||||||||||||||||||||||||
| 378 | 0 | $self->{information}->{name} = $data->{target}->{name}; | |||||||||||||||||||||||||||||||||||
| 379 | 0 | my $line = 1; | |||||||||||||||||||||||||||||||||||
| 380 | 0 | my $address = ""; | |||||||||||||||||||||||||||||||||||
| 381 | 0 | ▶ | while (defined $data->{target}->{address}->{"line$line"}) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 382 | 0 | $address .= $data->{target}->{address}->{"line$line"}."\n"; | |||||||||||||||||||||||||||||||||||
| 383 | 0 | $line++; | |||||||||||||||||||||||||||||||||||
| 384 | } | ||||||||||||||||||||||||||||||||||||
| 385 | 0 | $address .= $data->{target}->{address}->{postcode}; | |||||||||||||||||||||||||||||||||||
| 386 | 0 | $address .= "\n".$data->{target}->{address}->{countryCode}; | |||||||||||||||||||||||||||||||||||
| 387 | 0 | $self->{information}->{address} = $address; | |||||||||||||||||||||||||||||||||||
| 388 | 0 | $self->_set_error( -1, 'Valid VAT Number'); | |||||||||||||||||||||||||||||||||||
| 389 | } | ||||||||||||||||||||||||||||||||||||
| 390 | elsif ($response->code == 404) { | ||||||||||||||||||||||||||||||||||||
| 391 | 0 | return $self->_set_error( 2, 'Invalid VAT Number ('.$vatNumber.')'); | |||||||||||||||||||||||||||||||||||
| 392 | } | ||||||||||||||||||||||||||||||||||||
| 393 | elsif ($response->code == 400) { | ||||||||||||||||||||||||||||||||||||
| 394 | 0 | return $self->_set_error( 3, 'VAT number badly formed ('.$vatNumber.')'); | |||||||||||||||||||||||||||||||||||
| 395 | } | ||||||||||||||||||||||||||||||||||||
| 396 | else { | ||||||||||||||||||||||||||||||||||||
| 397 | 0 | return $self->_set_error( 500, 'Could not contact HMRC: '.$response->status_line); | |||||||||||||||||||||||||||||||||||
| 398 | } | ||||||||||||||||||||||||||||||||||||
| 399 | |||||||||||||||||||||||||||||||||||||
| 400 | 0 | return $countryCode . '-' . $vatNumber; | |||||||||||||||||||||||||||||||||||
| 401 | } | ||||||||||||||||||||||||||||||||||||
| 402 | |||||||||||||||||||||||||||||||||||||
| 403 | 144 | ▶ | sub _format_vatn { | ||||||||||||||||||||||||||||||||||
|
Subroutine
_format_vatn: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||
| 404 | 144 | my ( $self, $vatn, $mscc ) = @_; | |||||||||||||||||||||||||||||||||||
| 405 | 144 | my $null = ''; | |||||||||||||||||||||||||||||||||||
| 406 | 144 | $vatn =~ s/\-/ /g; | |||||||||||||||||||||||||||||||||||
| 407 | 144 | $vatn =~ s/\./ /g; | |||||||||||||||||||||||||||||||||||
| 408 | 144 | $vatn =~ s/\s+/ /g; | |||||||||||||||||||||||||||||||||||
| 409 | 144 | ▶ | if ( !$mscc && $vatn =~ s/^($self->{members}) ?/$null/e ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not $mscc and $vatn =~ s/^($self->{"members"}) ?/$null;/e
MC/DC50%1/2
not $mscc and $vatn =~ s/^($self->{"members"}) ?/$null;/e
not $mscc
$vatn =~ s/^($self->{"members"}) ?/$null;/e
Truth table66%2/3
not(A) and B
A= not $msccB= $vatn =~ s/^($self->{"members"}) ?/$null;/e
| |||||||||||||||||||||||||||||||||||||
| 410 | 59 | $mscc = $1; | |||||||||||||||||||||||||||||||||||
| 411 | } | ||||||||||||||||||||||||||||||||||||
| 412 | 144 | ▶ | return $self->_set_error( 0, "Unknown MS code" ) | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 413 | if $mscc !~ m/^($self->{members})$/; | ||||||||||||||||||||||||||||||||||||
| 414 | 144 | my $re = $self->{re}{$mscc}; | |||||||||||||||||||||||||||||||||||
| 415 | 144 | ▶ | return $self->_set_error( 1, "Invalid VAT number format" ) | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 416 | if $vatn !~ m/^$re$/; | ||||||||||||||||||||||||||||||||||||
| 417 | 59 | ( $vatn, $mscc ); | |||||||||||||||||||||||||||||||||||
| 418 | } | ||||||||||||||||||||||||||||||||||||
| 419 | |||||||||||||||||||||||||||||||||||||
| 420 | 0 | ▶ | sub _in_soap_envelope { | ||||||||||||||||||||||||||||||||||
|
Subroutine
_in_soap_envelope: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||
| 421 | 0 | my ($vatNumber, $countryCode)=@_; | |||||||||||||||||||||||||||||||||||
| 422 | 0 | return <<EWWSOAP; | |||||||||||||||||||||||||||||||||||
| 423 | <s11:Envelope xmlns:s11='http://schemas.xmlsoap.org/soap/envelope/'> | ||||||||||||||||||||||||||||||||||||
| 424 | <s11:Body> | ||||||||||||||||||||||||||||||||||||
| 425 | <tns1:checkVat xmlns:tns1='urn:ec.europa.eu:taxud:vies:services:checkVat:types'> | ||||||||||||||||||||||||||||||||||||
| 426 | <tns1:countryCode>$countryCode</tns1:countryCode> | ||||||||||||||||||||||||||||||||||||
| 427 | <tns1:vatNumber>$vatNumber</tns1:vatNumber> | ||||||||||||||||||||||||||||||||||||
| 428 | </tns1:checkVat> | ||||||||||||||||||||||||||||||||||||
| 429 | </s11:Body> | ||||||||||||||||||||||||||||||||||||
| 430 | </s11:Envelope> | ||||||||||||||||||||||||||||||||||||
| 431 | EWWSOAP | ||||||||||||||||||||||||||||||||||||
| 432 | } | ||||||||||||||||||||||||||||||||||||
| 433 | |||||||||||||||||||||||||||||||||||||
| 434 | 0 | ▶ | sub _is_res_ok { | ||||||||||||||||||||||||||||||||||
|
Subroutine
_is_res_ok: not called CC=14 SCAR=53.5
| |||||||||||||||||||||||||||||||||||||
| 435 | 0 | my ( $self, $code, $res ) = @_; | |||||||||||||||||||||||||||||||||||
| 436 | 0 | $self->{information}={}; | |||||||||||||||||||||||||||||||||||
| 437 | 0 | $res=~s/[\r\n]/ /g; | |||||||||||||||||||||||||||||||||||
| 438 | 0 | $self->{response} = $res; | |||||||||||||||||||||||||||||||||||
| 439 | 0 | ▶ | if ($code == 200) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 440 | 0 | ▶ | if ($res=~m/<ns2:valid> *(.*?) *<\/ns2:valid>/) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 441 | 0 | my $v = $1; | |||||||||||||||||||||||||||||||||||
| 442 | 0 | ▶ | if ($v eq 'true' || $v eq '1') { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$v eq "true" or $v eq 1
MC/DC0%0/2
$v eq "true" or $v eq 1
$v eq "true"
$v eq 1
Truth table0%0/3
A or B
A= $v eq "true"B= $v eq 1
| |||||||||||||||||||||||||||||||||||||
| 443 | 0 | ▶ | if ($res=~m/<ns2:name> *(.*?) *<\/ns2:name>/) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 444 | 0 | $self->{information}{name} = $1 | |||||||||||||||||||||||||||||||||||
| 445 | } | ||||||||||||||||||||||||||||||||||||
| 446 | 0 | ▶ | if ($res=~m/<ns2:address> *(.*?) *<\/ns2:address>/) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 447 | 0 | $self->{information}{address} = $1 | |||||||||||||||||||||||||||||||||||
| 448 | } | ||||||||||||||||||||||||||||||||||||
| 449 | 0 | $self->_set_error( -1, 'Valid VAT Number'); | |||||||||||||||||||||||||||||||||||
| 450 | 0 | return 1; | |||||||||||||||||||||||||||||||||||
| 451 | } else { | ||||||||||||||||||||||||||||||||||||
| 452 | 0 | return $self->_set_error( 2, 'Invalid VAT Number ('.$v.')'); | |||||||||||||||||||||||||||||||||||
| 453 | } | ||||||||||||||||||||||||||||||||||||
| 454 | } else { | ||||||||||||||||||||||||||||||||||||
| 455 | 0 | return $self->_set_error( 257, "Invalid response, please contact the author of this module. " . $res ); | |||||||||||||||||||||||||||||||||||
| 456 | } | ||||||||||||||||||||||||||||||||||||
| 457 | } else { | ||||||||||||||||||||||||||||||||||||
| 458 | 0 | ▶ | if ($res=~m/<faultcode> *(.*?) *<\/faultcode> *<faultstring> *(.*?) *<\/faultstring>/) { | ||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||
| 459 | 0 | my $faultcode = $1; | |||||||||||||||||||||||||||||||||||
| 460 | 0 | my $faultstring = $2; | |||||||||||||||||||||||||||||||||||
| 461 | 0 | ▶ | if ($faultcode eq 'soap:Server' && $faultstring eq 'TIMEOUT') { | ||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition0%0/3
$faultcode eq "soap:Server" and $faultstring eq "TIMEOUT"
MC/DC0%0/2
$faultcode eq "soap:Server" and $faultstring eq "TIMEOUT"
$faultcode eq "soap:Server"
$faultstring eq "TIMEOUT"
Truth table0%0/3
A and B
A= $faultcode eq "soap:Server"B= $faultstring eq "TIMEOUT"
| |||||||||||||||||||||||||||||||||||||
| 462 | 0 | return $self->_set_error(17, "The VIES server timed out. Please re-submit your request later.") | |||||||||||||||||||||||||||||||||||
| 463 | ▶ | } elsif ($faultcode eq 'soap:Server' && $faultstring eq 'MS_UNAVAILABLE') { | |||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$faultcode eq "soap:Server" and $faultstring eq "MS_UNAVAILABLE"
MC/DC0%0/2
$faultcode eq "soap:Server" and $faultstring eq "MS_UNAVAILABLE"
$faultcode eq "soap:Server"
$faultstring eq "MS_UNAVAILABLE"
Truth table0%0/3
A and B
A= $faultcode eq "soap:Server"B= $faultstring eq "MS_UNAVAILABLE"
| |||||||||||||||||||||||||||||||||||||
| 464 | 0 | return $self->_set_error(18, "Member State service unavailable. Please re-submit your request later.") | |||||||||||||||||||||||||||||||||||
| 465 | } elsif ($faultstring=~m/^Couldn't parse stream/) { | ||||||||||||||||||||||||||||||||||||
| 466 | 0 | return $self->_set_error( 21, "The VIES database failed to parse a stream. Please re-submit your request later." ); | |||||||||||||||||||||||||||||||||||
| 467 | } else { | ||||||||||||||||||||||||||||||||||||
| 468 | 0 | return $self->_set_error( $code, $1.' '.$2 ) | |||||||||||||||||||||||||||||||||||
| 469 | } | ||||||||||||||||||||||||||||||||||||
| 470 | } elsif ($res=~m/^Can't connect to/) { | ||||||||||||||||||||||||||||||||||||
| 471 | 0 | return $self->_set_error( 20, "Connexion to the VIES database failed. " . $res ); | |||||||||||||||||||||||||||||||||||
| 472 | } else { | ||||||||||||||||||||||||||||||||||||
| 473 | 0 | return $self->_set_error( 257, "Invalid response [".$code."], please contact the author of this module. " . $res ); | |||||||||||||||||||||||||||||||||||
| 474 | } | ||||||||||||||||||||||||||||||||||||
| 475 | } | ||||||||||||||||||||||||||||||||||||
| 476 | } | ||||||||||||||||||||||||||||||||||||
| 477 | |||||||||||||||||||||||||||||||||||||
| 478 | 85 | ▶ | sub _set_error { | ||||||||||||||||||||||||||||||||||
|
Subroutine
_set_error: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 479 | 85 | my ( $self, $code, $txt ) = @_; | |||||||||||||||||||||||||||||||||||
| 480 | 85 | $self->{error_code} = $code; | |||||||||||||||||||||||||||||||||||
| 481 | 85 | $self->{error} = $txt; | |||||||||||||||||||||||||||||||||||
| 482 | 85 | undef; | |||||||||||||||||||||||||||||||||||
| 483 | } | ||||||||||||||||||||||||||||||||||||
| 484 | |||||||||||||||||||||||||||||||||||||
| 485 | =back | ||||||||||||||||||||||||||||||||||||
| 486 | |||||||||||||||||||||||||||||||||||||
| 487 | =head1 SEE ALSO | ||||||||||||||||||||||||||||||||||||
| 488 | |||||||||||||||||||||||||||||||||||||
| 489 | LWP::UserAgent | ||||||||||||||||||||||||||||||||||||
| 490 | |||||||||||||||||||||||||||||||||||||
| 491 | L<https://ec.europa.eu/taxation_customs/vies/#/faq> for the FAQs related to the VIES service. | ||||||||||||||||||||||||||||||||||||
| 492 | |||||||||||||||||||||||||||||||||||||
| 493 | L<https://www.api.gov.uk/ch/companies-house> for details of the service provided by the UK's HMRC. | ||||||||||||||||||||||||||||||||||||
| 494 | |||||||||||||||||||||||||||||||||||||
| 495 | =head1 FEEDBACK | ||||||||||||||||||||||||||||||||||||
| 496 | |||||||||||||||||||||||||||||||||||||
| 497 | If you find this module useful, or have any comments, suggestions or improvements, feel free to let me know. | ||||||||||||||||||||||||||||||||||||
| 498 | |||||||||||||||||||||||||||||||||||||
| 499 | |||||||||||||||||||||||||||||||||||||
| 500 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||
| 501 | |||||||||||||||||||||||||||||||||||||
| 502 | Original author: Bernard Nauwelaerts <bpgn@cpan.org> | ||||||||||||||||||||||||||||||||||||
| 503 | |||||||||||||||||||||||||||||||||||||
| 504 | Maintainership since 2015: David Precious (BIGPRESH) <davidp@preshweb.co.uk> | ||||||||||||||||||||||||||||||||||||
| 505 | |||||||||||||||||||||||||||||||||||||
| 506 | |||||||||||||||||||||||||||||||||||||
| 507 | =head1 CREDITS | ||||||||||||||||||||||||||||||||||||
| 508 | |||||||||||||||||||||||||||||||||||||
| 509 | 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) : | ||||||||||||||||||||||||||||||||||||
| 510 | |||||||||||||||||||||||||||||||||||||
| 511 | =over 4 | ||||||||||||||||||||||||||||||||||||
| 512 | |||||||||||||||||||||||||||||||||||||
| 513 | =item * | ||||||||||||||||||||||||||||||||||||
| 514 | Gregor Herrmann, Debian. | ||||||||||||||||||||||||||||||||||||
| 515 | |||||||||||||||||||||||||||||||||||||
| 516 | =item * | ||||||||||||||||||||||||||||||||||||
| 517 | Graham Knop. | ||||||||||||||||||||||||||||||||||||
| 518 | |||||||||||||||||||||||||||||||||||||
| 519 | =item * | ||||||||||||||||||||||||||||||||||||
| 520 | Bart Heupers, Netherlands. | ||||||||||||||||||||||||||||||||||||
| 521 | |||||||||||||||||||||||||||||||||||||
| 522 | =item * | ||||||||||||||||||||||||||||||||||||
| 523 | Martin H. Sluka, noris network AG, Germany. | ||||||||||||||||||||||||||||||||||||
| 524 | |||||||||||||||||||||||||||||||||||||
| 525 | =item * | ||||||||||||||||||||||||||||||||||||
| 526 | Simon Williams, UK2 Limited, United Kingdom | ||||||||||||||||||||||||||||||||||||
| 527 | |||||||||||||||||||||||||||||||||||||
| 528 | =item * | ||||||||||||||||||||||||||||||||||||
| 529 | BenoƮt Galy, Greenacres, France | ||||||||||||||||||||||||||||||||||||
| 530 | |||||||||||||||||||||||||||||||||||||
| 531 | =item * | ||||||||||||||||||||||||||||||||||||
| 532 | Raluca Boboia, Evozon, Romania | ||||||||||||||||||||||||||||||||||||
| 533 | |||||||||||||||||||||||||||||||||||||
| 534 | =item * | ||||||||||||||||||||||||||||||||||||
| 535 | Dave O., POBox, U.S.A. | ||||||||||||||||||||||||||||||||||||
| 536 | |||||||||||||||||||||||||||||||||||||
| 537 | =item * | ||||||||||||||||||||||||||||||||||||
| 538 | Kaloyan Iliev, Digital Systems, Bulgaria. | ||||||||||||||||||||||||||||||||||||
| 539 | |||||||||||||||||||||||||||||||||||||
| 540 | =item * | ||||||||||||||||||||||||||||||||||||
| 541 | Tom Kirkpatrick, Virus Bulletin, United Kingdom. | ||||||||||||||||||||||||||||||||||||
| 542 | |||||||||||||||||||||||||||||||||||||
| 543 | =item * | ||||||||||||||||||||||||||||||||||||
| 544 | Andy Wardley, individual, United Kingdom. | ||||||||||||||||||||||||||||||||||||
| 545 | |||||||||||||||||||||||||||||||||||||
| 546 | =item * | ||||||||||||||||||||||||||||||||||||
| 547 | Robert Alloway, Service Centre, United Kingdom. | ||||||||||||||||||||||||||||||||||||
| 548 | |||||||||||||||||||||||||||||||||||||
| 549 | =item * | ||||||||||||||||||||||||||||||||||||
| 550 | Torsten Mueller, Archesoft, Germany | ||||||||||||||||||||||||||||||||||||
| 551 | |||||||||||||||||||||||||||||||||||||
| 552 | =item * | ||||||||||||||||||||||||||||||||||||
| 553 | Dave Lambley (davel), GoDaddy, United Kingdom | ||||||||||||||||||||||||||||||||||||
| 554 | |||||||||||||||||||||||||||||||||||||
| 555 | item * | ||||||||||||||||||||||||||||||||||||
| 556 | Tatu Wikman (tswfi) | ||||||||||||||||||||||||||||||||||||
| 557 | |||||||||||||||||||||||||||||||||||||
| 558 | =back | ||||||||||||||||||||||||||||||||||||
| 559 | |||||||||||||||||||||||||||||||||||||
| 560 | =head1 LICENSE | ||||||||||||||||||||||||||||||||||||
| 561 | |||||||||||||||||||||||||||||||||||||
| 562 | GPL3. Enjoy! See COPYING for further information on the GPL. | ||||||||||||||||||||||||||||||||||||
| 563 | |||||||||||||||||||||||||||||||||||||
| 564 | |||||||||||||||||||||||||||||||||||||
| 565 | =head1 DISCLAIMER | ||||||||||||||||||||||||||||||||||||
| 566 | |||||||||||||||||||||||||||||||||||||
| 567 | See L<http://ec.europa.eu/taxation_customs/vies/viesdisc.do> to known the limitations of the EU validation service. | ||||||||||||||||||||||||||||||||||||
| 568 | |||||||||||||||||||||||||||||||||||||
| 569 | This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; | ||||||||||||||||||||||||||||||||||||
| 570 | without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||||||||||||||||||||||||||||||||||||
| 571 | |||||||||||||||||||||||||||||||||||||
| 572 | =cut | ||||||||||||||||||||||||||||||||||||
| 573 | |||||||||||||||||||||||||||||||||||||
| 574 | 4 | 1; | |||||||||||||||||||||||||||||||||||