Adding VIES recheck workflow and tests.
This commit is contained in:
parent
f582bfd99e
commit
e88b0ca0d7
6 changed files with 313 additions and 7 deletions
|
|
@ -176,7 +176,20 @@ sub addVATNumber {
|
|||
0,
|
||||
] );
|
||||
|
||||
return $numberIsValid ? undef : $i18n->get('vies unavailable');
|
||||
if ( $numberIsValid ) {
|
||||
return undef;
|
||||
}
|
||||
else {
|
||||
my $workflow = WebGUI::Workflow::Instance->create( $self->session, {
|
||||
workflowId => 'taxeurecheckworkflow01',
|
||||
parameters => {
|
||||
userId => $user->userId,
|
||||
vatNumber => $number,
|
||||
},
|
||||
} )->start();
|
||||
|
||||
return $i18n->get('vies unavailable');
|
||||
}
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
|
@ -823,6 +836,45 @@ sub isUsableVATNumber {
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 recheckVATNumber ( vatNumber, user )
|
||||
|
||||
=cut
|
||||
|
||||
sub recheckVATNumber {
|
||||
my $self = shift;
|
||||
my $number = shift;
|
||||
my $user = shift || $self->session->user;
|
||||
|
||||
my $validator = Business::Tax::VAT::Validation->new;
|
||||
|
||||
my $isValid = $validator->check( $number );
|
||||
my $errorCode = $validator->get_last_error_code;
|
||||
|
||||
if ( $isValid ) {
|
||||
$self->session->db->write(
|
||||
'update tax_eu_vatNumbers set viesValidated=?, viesErrorCode=? where vatNumber=? and userId=?',
|
||||
[
|
||||
1,
|
||||
undef,
|
||||
$number,
|
||||
$user->userId,
|
||||
],
|
||||
);
|
||||
|
||||
return 'VALID';
|
||||
}
|
||||
elsif ( $errorCode < 17 ) {
|
||||
$self->deleteVATNumber( $number, $user );
|
||||
|
||||
return 'INVALID';
|
||||
}
|
||||
else {
|
||||
return 'UNKNOWN';
|
||||
}
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 skuFormDefinition ( )
|
||||
|
||||
Returns a hash ref containing the form definition for the per sku options for this tax driver.
|
||||
|
|
|
|||
94
lib/WebGUI/Workflow/Activity/RecheckVATNumber.pm
Normal file
94
lib/WebGUI/Workflow/Activity/RecheckVATNumber.pm
Normal file
|
|
@ -0,0 +1,94 @@
|
|||
package WebGUI::Workflow::Activity::RecheckVATNumber;
|
||||
|
||||
|
||||
=head1 LEGAL
|
||||
|
||||
-------------------------------------------------------------------
|
||||
WebGUI is Copyright 2001-2009 Plain Black Corporation.
|
||||
-------------------------------------------------------------------
|
||||
Please read the legal notices (docs/legal.txt) and the license
|
||||
(docs/license.txt) that came with this distribution before using
|
||||
this software.
|
||||
-------------------------------------------------------------------
|
||||
http://www.plainblack.com info@plainblack.com
|
||||
-------------------------------------------------------------------
|
||||
|
||||
=cut
|
||||
|
||||
use strict;
|
||||
use WebGUI::Shop::TaxDriver::EU;
|
||||
use base 'WebGUI::Workflow::Activity';
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Package WebGUI::Workflow::Activity::RecheckVATNumber
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
Rechecks VAT number trhough the EU VIES service that could not be checked at the time they were submitted.
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
See WebGUI::Workflow::Activity for details on how to use any activity.
|
||||
|
||||
=head1 METHODS
|
||||
|
||||
These methods are available from this class:
|
||||
|
||||
=cut
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 definition ( session, definition )
|
||||
|
||||
See WebGUI::Workflow::Activity::defintion() for details.
|
||||
|
||||
=cut
|
||||
|
||||
sub definition {
|
||||
my $class = shift;
|
||||
my $session = shift;
|
||||
my $definition = shift;
|
||||
my $i18n = WebGUI::International->new($session, "Activity_RecheckVATNumber");
|
||||
|
||||
push ( @{ $definition }, {
|
||||
name =>$i18n->get("topicName"),
|
||||
} );
|
||||
|
||||
return $class->SUPER::definition( $session, $definition );
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 execute ( [ object ] )
|
||||
|
||||
See WebGUI::Workflow::Activity::execute() for details.
|
||||
|
||||
=cut
|
||||
|
||||
sub execute {
|
||||
my $self = shift;
|
||||
my $object = shift;
|
||||
my $instance = shift;
|
||||
|
||||
my $params = $instance->get('parameters');
|
||||
my $user = WebGUI::User->new( $self->session, $params->{ userId } );
|
||||
my $taxDriver = WebGUI::Shop::TaxDriver::EU->new( $self->session );
|
||||
|
||||
my $result = $taxDriver->recheckVATNumber( $params->{ vatNumber }, $user );
|
||||
$self->session->log->warn( "Checked $params->{ vatNumber } for user $params->{ userId }, result: $result");
|
||||
|
||||
|
||||
# If the validity of the number is known we're finished.
|
||||
if ( $result eq 'VALID' || $result eq 'INVALID' ) {
|
||||
return $self->COMPLETE;
|
||||
}
|
||||
|
||||
# Otherwise, try again in an hour.
|
||||
return $self->WAITING( 3600 );
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
#vim:ft=perl
|
||||
14
lib/WebGUI/i18n/English/Activity_RecheckVATNumber.pm
Normal file
14
lib/WebGUI/i18n/English/Activity_RecheckVATNumber.pm
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
package WebGUI::i18n::English::Activity_RecheckVATNumber;
|
||||
|
||||
use strict;
|
||||
|
||||
our $I18N = {
|
||||
'topicName' => {
|
||||
message => q|Recheck VAT number|,
|
||||
lastUpdated => 0,
|
||||
context => q|Title of the VAT number recheck workflow activity|,
|
||||
},
|
||||
};
|
||||
|
||||
1;
|
||||
|
||||
|
|
@ -9,7 +9,8 @@ our $I18N = {
|
|||
},
|
||||
|
||||
'vies unavailable' => {
|
||||
message => q|Number validation currently not available. Check later.|,
|
||||
message => q|Number validation is currently not available. Your number will be rechecked automatically
|
||||
after some time.|,
|
||||
lastUpdated => 0,
|
||||
context => q|An error message|,
|
||||
},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue