| 1 |
#!/usr/bin/env perl |
| 2 |
use strict; |
| 3 |
use warnings; |
| 4 |
use Test; |
| 5 |
|
| 6 |
my %distant_checks = ( |
| 7 |
AT => ['U12345678'], |
| 8 |
BE => ['0123456789'], |
| 9 |
BG => ['123456789', '1234567890'], |
| 10 |
CY => ['12345678A'], |
| 11 |
CZ => ['12345678', '123456789', '1234567890'], |
| 12 |
DE => ['123456789'], |
| 13 |
DK => ['12345678', '12 45 78 90', '1245 78 90'], |
| 14 |
EE => ['123456789'], |
| 15 |
EL => ['123456789'], |
| 16 |
ES => ['123456789', 'A2345678B'], |
| 17 |
FI => ['12345678'], |
| 18 |
FR => ['12345678901', '12 456789012', 'A2 456789012', '1B 456789012', 'AB 456789012'], |
| 19 |
GB => ['123456789', '123456789012', '123 5678 01', '123 5678 12 234','GD345', 'HA123'], |
| 20 |
XI => ['123456789', '123456789012', '123 5678 01', '123 5678 12 234','GD345', 'HA123'], |
| 21 |
HU => ['12345678'], |
| 22 |
IE => ['1234567A', '1B34567C', '1+34567C', '1*34567C'], |
| 23 |
IT => ['12345678901'], |
| 24 |
LT => ['123456789', '123456789012'], |
| 25 |
LU => ['12345678'], |
| 26 |
LV => ['12345678901'], |
| 27 |
MT => ['12345678'], |
| 28 |
NL => ['123456789B12'], |
| 29 |
PL => ['1234567890'], |
| 30 |
PT => ['123456789'], |
| 31 |
RO => ['12', '123', '1234', '12345', '123456', '1234567', '12345678', '123456789', '1234567890'], |
| 32 |
SE => ['123456789012'], |
| 33 |
SI => ['12345678'], |
| 34 |
SK => ['1234567890'] |
| 35 |
); |
| 36 |
|
| 37 |
use Business::Tax::VAT::Validation; |
| 38 |
|
| 39 |
my $tests = 0; |
| 40 |
|
| 41 |
for my $ms (keys %distant_checks) { |
| 42 |
$tests+= $#{$distant_checks{$ms}} + 1 |
| 43 |
} |
| 44 |
|
| 45 |
plan tests => $tests; |
| 46 |
|
| 47 |
my $hvat=Business::Tax::VAT::Validation->new(); |
| 48 |
for my $ms (keys %distant_checks) { |
| 49 |
for my $t (@{$distant_checks{$ms}}) { |
| 50 |
my $res=$hvat->check($t, $ms); |
| 51 |
if ($res){ |
| 52 |
ok(1); |
| 53 |
} else { |
| 54 |
my $err = $hvat->get_last_error_code; |
| 55 |
if ($err == 2) { |
| 56 |
ok(1) |
| 57 |
} elsif ($err > 16 && $err < 257) { |
| 58 |
skip(1); |
| 59 |
} elsif ($err > 257) { |
| 60 |
warn("skipping $ms$t : ".$hvat->get_last_error."\n"); |
| 61 |
skip(1); |
| 62 |
} elsif ($err == 3 && $ms eq 'GB' && ($t eq 'GD345' || $t eq 'HA123')) { |
| 63 |
# These two codes are only successfully looked up in VIES, HMRC |
| 64 |
# throws a 400 error indicating that the code is malformed. |
| 65 |
# This does not seem correct, but is observed behaviour. |
| 66 |
warn("skipping $ms$t : ".$hvat->get_last_error."\n"); |
| 67 |
skip(1); |
| 68 |
} else { |
| 69 |
warn("Distant check for $ms$t failed: ".$err.' '.$hvat->get_last_error."\n"); |
| 70 |
ok(0); |
| 71 |
} |
| 72 |
} |
| 73 |
### To be cool with VIES server ! |
| 74 |
sleep(1); |
| 75 |
} |
| 76 |
} |
| 77 |
exit 0; |
| 78 |
__END__ |