diff --git a/lib/WebGUI/Shop/Pay.pm b/lib/WebGUI/Shop/Pay.pm index 11579f3f8..302933ee6 100644 --- a/lib/WebGUI/Shop/Pay.pm +++ b/lib/WebGUI/Shop/Pay.pm @@ -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 for details. @@ -49,16 +53,19 @@ A list of properties to assign to this PayDriver. See C 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; } diff --git a/t/Shop/Pay.t b/t/Shop/Pay.t index a6c714754..0618612f9 100644 --- a/t/Shop/Pay.t +++ b/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 };