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:
parent
a3274f47ec
commit
8779905ac3
4 changed files with 66 additions and 3 deletions
|
|
@ -18,6 +18,7 @@
|
|||
- fixed: Bad International macro calls in Gallery Template
|
||||
- fixed: more i18n (Shop tags)
|
||||
- fixed: i18nagain
|
||||
- fixed: Cash available as a payment option to everyone
|
||||
|
||||
7.5.17
|
||||
- fixed: Payment Methods Hover Help Incomplete
|
||||
|
|
|
|||
|
|
@ -91,7 +91,10 @@ sub getDrivers {
|
|||
|
||||
=head2 getOptions ( $cart )
|
||||
|
||||
Returns a list of options for the user to pay to. It is a hash of hashrefs, with the key of the primary hash being the paymentGatewayId of the driver, and sub keys of label and button.
|
||||
Returns a set of options for the user to pay to. It is a hash of
|
||||
hashrefs, with the key of the primary hash being the paymentGatewayId
|
||||
of the driver, and sub keys of label and button. The hash will only
|
||||
contain payment gateways that this user is allowed to use.
|
||||
|
||||
=head3 $cart
|
||||
|
||||
|
|
@ -110,6 +113,7 @@ sub getOptions {
|
|||
my %options = ();
|
||||
|
||||
foreach my $gateway (@{ $self->getPaymentGateways() }) {
|
||||
next unless $gateway->canUse;
|
||||
if (!$recurringRequired || $gateway->handlesRecurring) {
|
||||
$options{$gateway->getId} = {
|
||||
label => $gateway->get("label"),
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ my $session = WebGUI::Test->session;
|
|||
#----------------------------------------------------------------------------
|
||||
# Tests
|
||||
|
||||
my $tests = 46;
|
||||
my $tests = 49;
|
||||
plan tests => 1 + $tests;
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
|
@ -459,6 +459,21 @@ cmp_deeply(
|
|||
);
|
||||
|
||||
|
||||
#######################################################################
|
||||
#
|
||||
# canUse
|
||||
#
|
||||
#######################################################################
|
||||
|
||||
$session->user({userId => 3});
|
||||
ok($driver->canUse, 'canUse: session->user is used if no argument is passed');
|
||||
ok(!$driver->canUse({userId => 1}), 'canUse: userId explicit works, visitor cannot use this driver');
|
||||
|
||||
TODO: {
|
||||
local $TODO = 'tests for canUse';
|
||||
ok(0, 'Test other users and groups');
|
||||
}
|
||||
|
||||
#######################################################################
|
||||
#
|
||||
# delete
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue