- Added tests for Pay

- Fixed some tests/code for PayDriver
 - Added i18n for PayDriver
 - Added a really, really bare-bones Cash plugin.
This commit is contained in:
Martin Kamerbeek 2008-03-11 16:33:10 +00:00
parent 39a0b6ff1f
commit 60362cb747
7 changed files with 415 additions and 23 deletions

View file

@ -58,7 +58,7 @@ sub addPaymentGateway {
unless isIn($requestedClass, (keys %{$self->getDrivers}) );
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, $options ]) };
my $driver = eval { WebGUI::Pluggable::instanciate($requestedClass, 'create', [ $self->session, 'TEMPORARY_LABEL', $options ]) };
return $driver;
}
@ -109,7 +109,7 @@ sub getOptions {
#-------------------------------------------------------------------
=head2 getPaymentGateway ( )
=head2 getPaymentGateway ( $id )
Looks up an existing PayDriver in the db by paymentGatewayId and returns
that object. If the PayDriver throws an exception, it is propagated

View file

@ -111,7 +111,7 @@ sub create {
my $self = WebGUI::Shop::PayDriver->_buildObj($session, $class, $paymentGatewayId, $label, $options);
# and persist this instance in the db
$session->db->write('insert into payment_Gateway (paymentGatewayId, label, className) VALUES (?,?,?)', [
$session->db->write('insert into paymentGateway (paymentGatewayId, label, className) VALUES (?,?,?)', [
$paymentGatewayId,
$label,
$class,
@ -146,26 +146,26 @@ sub definition {
%fields = (
label => {
fieldType => 'text',
label => $i18n->echo('label'),
hoverHelp => $i18n->echo('label help'),
label => $i18n->get('label'),
hoverHelp => $i18n->get('label help'),
defaultValue => "Credit Card",
},
enabled => {
fieldType => 'yesNo',
label => $i18n->echo('enabled'),
hoverHelp => $i18n->echo('enabled help'),
label => $i18n->get('enabled'),
hoverHelp => $i18n->get('enabled help'),
defaultValue => 1,
},
groupToUse => {
fieldType => 'group',
label => $i18n->echo('who can use'),
hoverHelp => $i18n->echo('who can use help'),
label => $i18n->get('who can use'),
hoverHelp => $i18n->get('who can use help'),
defaultValue => 1,
},
receiptMessage => {
fieldType => 'text',
label => $i18n->echo('receipt message'),
hoverHelp => $i18n->echo('receipt message help'),
label => $i18n->get('receipt message'),
hoverHelp => $i18n->get('receipt message help'),
defaultValue => undef,
},
);
@ -190,7 +190,7 @@ Removes this PayDriver object from the db.
sub delete {
my $self = shift;
$self->session->db->write('delete from payment_Gateway where paymentGatewayId=?', [
$self->session->db->write('delete from paymentGateway where paymentGatewayId=?', [
$self->getId,
]);
@ -285,11 +285,17 @@ sub getId {
Return a human readable name for this driver. Never overridden in the
subclass, instead specified in definition with the name "name".
This is a class method.
=cut
sub getName {
my $self = shift;
my $definition = $self->definition($self->session);
my $class = shift;
my $session = shift;
WebGUI::Error::InvalidParam->throw(error => q{Must provide a session variable})
unless ref $session eq 'WebGUI::Session';
my $definition = $class->definition($session);
return $definition->[0]->{name};
}
@ -312,7 +318,7 @@ sub new {
unless defined $paymentGatewayId;
# Fetch the instance data from the db
my $properties = $session->db->quickHashRef('select * from payment_Gateway where paymentGatewayId=?', [
my $properties = $session->db->quickHashRef('select * from paymentGateway where paymentGatewayId=?', [
$paymentGatewayId,
]);
WebGUI::Error::ObjectNotFound->throw(error => q{paymentGatewayId not found in db}, id => $paymentGatewayId)
@ -368,7 +374,7 @@ sub set {
unless ref $properties eq 'HASH' and scalar keys %{ $properties };
my $jsonOptions = to_json($properties);
$self->session->db->write('update payment_Gateway set options=? where paymentGatewayId=?', [
$self->session->db->write('update paymentGateway set options=? where paymentGatewayId=?', [
$jsonOptions,
$self->paymentGatewayId
]);

View file

@ -0,0 +1,56 @@
package WebGUI::Shop::PayDriver::Cash;
use strict;
use WebGUI::Shop::PayDriver;
use WebGUI::Exception;
use base qw/WebGUI::Shop::PayDriver/;
#-------------------------------------------------------------------
sub definition {
my $class = shift;
my $session = shift;
my $definition = shift;
my $i18n = WebGUI::International->new($session, 'PayDriver_Cash');
tie my %fields, 'Tie::IxHash';
%fields = (
sendReceipt => {
fieldType => 'yesNo',
label => $i18n->echo('sendReceipt'),
hoverHelp => $i18n->echo('sendReceipt help'),
defaultValue => 0,
},
);
push @{ $definition }, {
name => $i18n->echo('Cash'),
fields => \%fields,
};
return $class->SUPER::definition($session, $definition);
}
#-------------------------------------------------------------------
sub getButton {
}
#-------------------------------------------------------------------
sub www_collectPaymentInfo {
}
#-------------------------------------------------------------------
sub www_displayStatus {
}
1;

View file

@ -0,0 +1,57 @@
package WebGUI::i18n::English::PayDriver;
use strict;
our $I18N = {
'label' => {
message => q|Label|,
lastUpdated => 0,
context => q|Label for the label option.|
},
'label help' => {
message => q|The name by which this pagyment gateway is displayed.|,
lastUpdated => 0,
context => q|Hover help for the label option.|
},
'enabled' => {
message => q|Enabled|,
lastUpdated => 0,
context => q|Label for the enabled option.|,
},
'enabled help' => {
message => q|Sets whether this payment gateway is enabled|,
lastUpdated => 0,
context => q|Hover help for the enabled option.|,
},
'who can use' => {
message => q|Group to use this gateway|,
lastUpdate => 0,
context => q|Label for the group to use option.|,
},
'who can use help' => {
message => q|Specifies which group is allowed to use this payment gateway.|,
lastUpdated => 0,
context => q|Hover help for the group to use option.|,
},
'receipt message' => {
message => q|Receipt message|,
lastUpdated => 0,
context => q|Label for the receipt message option.|,
},
'receipt message help' => {
message => q|The message that will be attached to the receipt.|,
lastUpdated => 0,
context => q|Hover help the receipt message option.|,
},
};
1;