Business-Tax-VAT-Validation

 view release on metacpan or  search on metacpan

lib/Business/Tax/VAT/Validation.pm  view on Meta::CPAN

}

=item B<information> - Returns information related to the last checked VAT number

    # 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, C<address> is the only key which will be set.

For EU VAT numbers checked via VIES, you can expect C<name> and C<address>.
This hashref will be reset every time you call check() or local_check()

=cut

sub information {
    my ( $self, $key, @other ) = @_;
    if ($key) {
        return $self->{information}{$key}
    } else {
        return ($self->{information})
    }
}

=item B<get_last_error_code> - Returns the last recorded error code

=item B<get_last_error> - Returns the last recorded error

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

Possible errors are :

=over 4

=item *
 -1  The provided VAT number is valid (so, no error occurred)

=item *
  0  Unknown MS code : Internal checkup failed (Specified Member State does not exist)

=item *
  1  Invalid VAT number format : Internal checkup failed (bad syntax)

=item *
  2  This VAT number doesn't exist in EU database : distant checkup

=item *
  3  This VAT number contains errors : distant checkup

=item *
 17  Time out connecting to the database : Temporary error when the connection to the database times out

=item *
 18  Member Sevice Unavailable: The EU database is unable to reach the requested member's database.

=item *
 19  The EU database is too busy.

=item *
 20  Connexion to the VIES database failed.

=item *
 21  The VIES interface failed to parse a stream. This error occurs unpredictabely, so you should retry your validation request.

=item *
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...

=item *
500  The VIES server encountered an internal server error.
Error 500 : soap:Server TIMEOUT
Error 500 : soap:Server MS_UNAVAILABLE

=back

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.

=cut

sub get_last_error {
    $_[0]->{error};
}

sub get_last_error_code {
    $_[0]->{error_code};
}

=item B<get_last_response> - Returns the full last response

=cut

sub get_last_response {
    $_[0]->{response};
}

### PRIVATE FUNCTIONS ==========================================================
sub _get_ua {
    my ($self) = @_;
    my $ua = LWP::UserAgent->new;
    if ( ref $self->{proxy} eq 'ARRAY' ) {
        $ua->proxy( @{ $self->{proxy} } );
    } else {
        $ua->env_proxy;
    }
    $ua->agent( 'Business::Tax::VAT::Validation/'. $Business::Tax::VAT::Validation::VERSION );
    return $ua;
}

sub _check_vies {
  my ($self, $vatNumber, $countryCode) = @_;
  my $ua = $self->_get_ua();
  my $request = HTTP::Request->new(POST => $self->{baseurl});
  $request->content(_in_soap_envelope($vatNumber, $countryCode));
  $request->content_type("text/xml; charset=utf-8");

  my $response = $ua->request($request);



( run in 1.099 second using v1.01-cache-2.11-cpan-600a1bdf6e4 )