Add a method for Payment Drivers to see if they can used by a particular user, canUse.

Add some tests for the method.
Have Pay->getOptions use the method.
This commit is contained in:
Colin Kuskie 2008-07-21 16:14:52 +00:00
parent a3274f47ec
commit 8779905ac3
4 changed files with 66 additions and 3 deletions

View file

@ -10,6 +10,7 @@ use WebGUI::Inbox;
use WebGUI::International;
use WebGUI::HTMLForm;
use WebGUI::Macro;
use WebGUI::User;
use WebGUI::Shop::Cart;
use JSON;
@ -81,10 +82,52 @@ sub cancelRecurringPayment {
my $self = shift;
my $transaction = shift;
WebGUI::Error::OverrideMe->throw();
}
}
#-------------------------------------------------------------------
=head2 canUse ( user )
Checks to see if the user can use this Payment Driver.
=head3 user
A hashref containing user information. The user referenced will be checked
to see if they can use the Payment Driver. If missing, then $session->user
will be used.
=head4 userId
A userId used to build a user object.
=head4 user
A user object that will be used directly.
=cut
sub canUse {
my $self = shift;
my $user = shift;
my $userObject;
if (!defined $user or ref($user) ne 'HASH') {
$userObject = $self->session->user;
}
else {
if (exists $user->{user}) {
$userObject = $user->{user};
}
elsif (exists $user->{userId}) {
$userObject = WebGUI::User->new($self->session, $user->{userId});
}
else {
WebGUI::Error::InvalidParam->throw(error => q{Must provide user information})
}
}
return $userObject->isInGroup($self->get('groupToUse'));
}
#-------------------------------------------------------------------
=head2 className ( )
Accessor for the className of the object. This is the name of the driver that is used