Require a label to be passed to WebGUI::Shop::Pay->addPaymentGateway
This commit is contained in:
parent
60362cb747
commit
b8d9d38da6
2 changed files with 30 additions and 11 deletions
|
|
@ -33,7 +33,7 @@ readonly session => my %session;
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 addPaymentGateway ( $class, $options )
|
||||
=head2 addPaymentGateway ( $class, $label, $options )
|
||||
|
||||
The interface method for creating new, configured instances of PayDriver. If the PayDriver throws an exception, it is propagated
|
||||
back up to the top.
|
||||
|
|
@ -42,6 +42,10 @@ back up to the top.
|
|||
|
||||
The class of the new PayDriver object to create.
|
||||
|
||||
=head4 $label
|
||||
|
||||
The label for this instance.
|
||||
|
||||
=head4 $options
|
||||
|
||||
A list of properties to assign to this PayDriver. See C<definition> for details.
|
||||
|
|
@ -49,16 +53,19 @@ A list of properties to assign to this PayDriver. See C<definition> for details
|
|||
=cut
|
||||
|
||||
sub addPaymentGateway {
|
||||
my $self = shift;
|
||||
my $requestedClass = shift;
|
||||
my $options = shift;
|
||||
my $self = shift;
|
||||
my $requestedClass = shift;
|
||||
my $label = shift;
|
||||
my $options = shift;
|
||||
WebGUI::Error::InvalidParam->throw(error => q{Must provide a class to create an object})
|
||||
unless defined $requestedClass;
|
||||
WebGUI::Error::InvalidParam->throw(error => q{The requested class is not enabled in your WebGUI configuration file}, param => $requestedClass)
|
||||
unless isIn($requestedClass, (keys %{$self->getDrivers}) );
|
||||
WebGUI::Error::InvalidParam->throw(error => q{Must provide a label to create an object})
|
||||
unless $label;
|
||||
WebGUI::Error::InvalidParam->throw(error => q{You must pass a hashref of options to create a new PayDriver object})
|
||||
unless defined($options) and ref $options eq 'HASH' and scalar keys %{ $options };
|
||||
my $driver = eval { WebGUI::Pluggable::instanciate($requestedClass, 'create', [ $self->session, 'TEMPORARY_LABEL', $options ]) };
|
||||
my $driver = eval { WebGUI::Pluggable::instanciate($requestedClass, 'create', [ $self->session, $label, $options ]) };
|
||||
return $driver;
|
||||
}
|
||||
|
||||
|
|
|
|||
24
t/Shop/Pay.t
24
t/Shop/Pay.t
|
|
@ -31,7 +31,7 @@ my $session = WebGUI::Test->session;
|
|||
#----------------------------------------------------------------------------
|
||||
# Tests
|
||||
|
||||
my $tests = 25;
|
||||
my $tests = 27;
|
||||
plan tests => 1 + $tests;
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
|
@ -114,6 +114,18 @@ cmp_deeply(
|
|||
|
||||
eval { $gateway = $pay->addPaymentGateway('WebGUI::Shop::PayDriver::Cash'); };
|
||||
$e = Exception::Class->caught();
|
||||
isa_ok($e, 'WebGUI::Error::InvalidParam', 'addPaymentGateway croaks without a label');
|
||||
cmp_deeply(
|
||||
$e,
|
||||
methods(
|
||||
error => 'Must provide a label to create an object',
|
||||
),
|
||||
'addPaymentGateway requires a label',
|
||||
);
|
||||
|
||||
|
||||
eval { $gateway = $pay->addPaymentGateway('WebGUI::Shop::PayDriver::Cash', 'JAL'); };
|
||||
$e = Exception::Class->caught();
|
||||
isa_ok($e, 'WebGUI::Error::InvalidParam', 'addPaymentGateway croaks without options to build a object with');
|
||||
cmp_deeply(
|
||||
$e,
|
||||
|
|
@ -123,7 +135,7 @@ cmp_deeply(
|
|||
'addPaymentGateway croaks without options to build a object with',
|
||||
);
|
||||
|
||||
eval { $gateway = $pay->addPaymentGateway('WebGUI::Shop::PayDriver::Cash', {}); };
|
||||
eval { $gateway = $pay->addPaymentGateway('WebGUI::Shop::PayDriver::Cash', 'JAL', {}); };
|
||||
$e = Exception::Class->caught();
|
||||
isa_ok($e, 'WebGUI::Error::InvalidParam', 'addPaymentGateway croaks without options to build a object with');
|
||||
cmp_deeply(
|
||||
|
|
@ -138,14 +150,14 @@ my $options = {
|
|||
enabled => 1,
|
||||
label => 'Cold, stone hard cash',
|
||||
};
|
||||
my $newDriver = $pay->addPaymentGateway('WebGUI::Shop::PayDriver::Cash', $options);
|
||||
my $newDriver = $pay->addPaymentGateway('WebGUI::Shop::PayDriver::Cash', 'JAL', $options);
|
||||
isa_ok($newDriver, 'WebGUI::Shop::PayDriver::Cash', 'added a new, configured Cash driver');
|
||||
is($newDriver->label, 'JAL', 'label passed correctly to paydriver');
|
||||
|
||||
diag ('----> THE NEXT TEST IS SUPPOSED TO FAIL! REMOVE WHEN RESOLVED. <----');
|
||||
isnt ($newDriver->label, 'TEMPORARY_LABEL', 'fail test until the addPaymentGateway interface is resolved.');
|
||||
|
||||
#TODO: check if options are stored.
|
||||
|
||||
|
||||
#######################################################################
|
||||
#
|
||||
# getDrivers
|
||||
|
|
@ -225,7 +237,7 @@ my $otherOptions = {
|
|||
enabled => 1,
|
||||
label => 'Even harder cash',
|
||||
};
|
||||
my $anotherDriver = $pay->addPaymentGateway('WebGUI::Shop::PayDriver::Cash', $otherOptions);
|
||||
my $anotherDriver = $pay->addPaymentGateway('WebGUI::Shop::PayDriver::Cash', 'Pomade', $otherOptions);
|
||||
|
||||
my $gateways = $pay->getPaymentGateways;
|
||||
my @returnedIds = map {$_->getId} @{ $gateways };
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue