diff --git a/docs/upgrades/upgrade_6.2.9-6.3.0.sql b/docs/upgrades/upgrade_6.2.9-6.3.0.sql
index 181ef6be7..e2bbdba44 100644
--- a/docs/upgrades/upgrade_6.2.9-6.3.0.sql
+++ b/docs/upgrades/upgrade_6.2.9-6.3.0.sql
@@ -92,7 +92,7 @@ create table layout (
INSERT INTO settings VALUES ('commerceCheckoutCanceledTemplateId','1');
INSERT INTO settings VALUES ('commerceConfirmCheckoutTemplateId','1');
INSERT INTO settings VALUES ('commercePaymentPlugin','PayFlowPro');
-INSERT INTO settings VALUES ('commerceSendDailyReportTo','');
+INSERT INTO settings VALUES ('commerceSelectPaymentGatewayTemplateId','1');
INSERT INTO settings VALUES ('commerceTransactionErrorTemplateId','1');
INSERT INTO template VALUES ('1','Subscription code redemption','\r\nBatch: \r\n\r\n\r\n
\r\n','Operation/RedeemSubscription',1,1);
INSERT INTO template VALUES ('1','Subscriptionitem default template','
\r\n
\r\n
\r\n
\r\n$
\r\n\">Subscribe now
','Macro/SubscriptionItem',1,1);
@@ -168,4 +168,4 @@ CREATE TABLE commerceSettings (
namespace varchar(64) NOT NULL default '',
type varchar(10) NOT NULL default ''
) TYPE=MyISAM;
-
+INSERT INTO template VALUES ('1','Default payment gateway selection template','\r\n
\r\n \r\n \r\n \r\n \r\n | \r\n | \r\n
\r\n \r\n
\r\n \r\n \r\n\r\n \r\n','Commerce/SelectPaymentGateway',1,1);
diff --git a/lib/WebGUI/Commerce/Payment.pm b/lib/WebGUI/Commerce/Payment.pm
index a733ed9f9..f3b186efc 100644
--- a/lib/WebGUI/Commerce/Payment.pm
+++ b/lib/WebGUI/Commerce/Payment.pm
@@ -4,12 +4,49 @@ use strict;
use WebGUI::SQL;
use WebGUI::International;
use Tie::IxHash;
+use WebGUI::HTMLForm;
+
+#-------------------------------------------------------------------
+sub configurationForm {
+ my ($self, $form, $f);
+ $self = shift;
+ $form = shift;
+
+ $f = WebGUI::HTMLForm->new;
+ $f->yesNo(
+ -name => $self->prepend('enabled'),
+ -value => $self->enabled,
+#### intl ####
+ -label => 'Enable',
+ );
+ $f->raw($form);
+
+ return $f->printRowsOnly;
+}
+
+#-------------------------------------------------------------------
+sub enabled {
+ return $_[0]->{_enabled};
+}
#-------------------------------------------------------------------
sub get {
return $_[0]->{_properties}{$_[1]};
}
+#-------------------------------------------------------------------
+sub getEnabledPlugins {
+ my (@enabledPlugins, $plugin, @plugins);
+ @enabledPlugins = WebGUI::SQL->buildArray("select namespace from commerceSettings where type='Payment' and fieldName='enabled' and fieldValue='1'");
+
+ foreach (@enabledPlugins) {
+ $plugin = WebGUI::Commerce::Payment->load($_);
+ push(@plugins, $plugin) if ($plugin);
+ }
+
+ return \@plugins;
+}
+
#-------------------------------------------------------------------
sub init {
my ($class, $namespace, $properties);
@@ -18,7 +55,7 @@ sub init {
$properties = WebGUI::SQL->buildHashRef("select fieldName, fieldValue from commerceSettings where namespace=".quote($namespace)." and type='Payment'");
- bless {_properties => $properties, _namespace=>$namespace}, $class;
+ bless {_properties=>$properties, _namespace=>$namespace, _enabled=>$properties->{enabled}}, $class;
}
#-------------------------------------------------------------------
diff --git a/lib/WebGUI/Commerce/Payment/PayFlowPro.pm b/lib/WebGUI/Commerce/Payment/PayFlowPro.pm
index 05c581875..09e4e2657 100644
--- a/lib/WebGUI/Commerce/Payment/PayFlowPro.pm
+++ b/lib/WebGUI/Commerce/Payment/PayFlowPro.pm
@@ -10,7 +10,6 @@ use WebGUI::International;
our @ISA = qw(WebGUI::Commerce::Payment);
-
#-------------------------------------------------------------------
sub cancelRecurringPayment {
my ($self, $recurring);
@@ -138,7 +137,7 @@ sub configurationForm {
-subText=> $i18n->get('testModeEnabled')
);
- return $f->printRowsOnly;
+ return $self->SUPER::configurationForm($f->printRowsOnly);
}
#-------------------------------------------------------------------
diff --git a/lib/WebGUI/Help/Commerce.pm b/lib/WebGUI/Help/Commerce.pm
index 43ade4b32..2526a86ec 100644
--- a/lib/WebGUI/Help/Commerce.pm
+++ b/lib/WebGUI/Help/Commerce.pm
@@ -59,6 +59,22 @@ our $HELP = {
}
]
},
+
+ 'select payment gateway template' => {
+ title => 'help select payment template title',
+ body => 'help select payment template body',
+ related => [
+ {
+ tag => 'template language',
+ namespace => 'WebGUI'
+ },
+ {
+ tag => 'templates manage',
+ namespace => 'WebGUI'
+ }
+ ]
+ },
+
};
1;
diff --git a/lib/WebGUI/Operation.pm b/lib/WebGUI/Operation.pm
index 1a5f539eb..af0f67d11 100644
--- a/lib/WebGUI/Operation.pm
+++ b/lib/WebGUI/Operation.pm
@@ -263,6 +263,7 @@ sub getOperations {
'listPendingTransactions' => 'WebGUI::Operation::Commerce',
'cancelTransaction' => 'WebGUI::Operation::Commerce',
'completePendingTransaction' => 'WebGUI::Operation::Commerce',
+ 'selectPaymentGateway' => 'WebGUI::Operation::Commerce',
'viewPurchaseHistory' => 'WebGUI::Operation::TransactionLog',
'cancelRecurringTransaction' => 'WebGUI::Operation::TransactionLog',
};
diff --git a/lib/WebGUI/Operation/Commerce.pm b/lib/WebGUI/Operation/Commerce.pm
index a7cff3f89..116aa4cc7 100644
--- a/lib/WebGUI/Operation/Commerce.pm
+++ b/lib/WebGUI/Operation/Commerce.pm
@@ -17,6 +17,7 @@ use WebGUI::International;
use WebGUI::Template;
use WebGUI::HTTP;
use WebGUI::Paginator;
+use WebGUI::Form;
#-------------------------------------------------------------------
sub _submenu {
@@ -35,6 +36,14 @@ sub _submenu {
return $ac->render($workarea, $title);
}
+#-------------------------------------------------------------------
+sub _gatewaySelected {
+ return 0 unless ($session{form}{paymentGateway});
+ my $plugin = WebGUI::Commerce::Payment->load($session{form}{paymentGateway});
+ return 1 if ($plugin && $plugin->enabled);
+ return 0;
+}
+
#-------------------------------------------------------------------
sub www_cancelTransaction {
my ($transaction, %var);
@@ -61,12 +70,16 @@ sub www_checkoutConfirm {
$errors = shift;
$i18n = WebGUI::International->new('Commerce');
-
- unless ($session{setting}{commercePaymentPlugin}) {
- $var{errorLoop} = [{message=>$i18n->get('no payment gateway')}];
- return WebGUI::Template::process($session{setting}{commerceConfirmCheckoutTemplateId}, 'Commerce/ConfirmCheckout', \%var);
- }
+ # If the user isn't logged in yet, let him do so or have him create an account
+ if ($session{user}{userId} == 1) {
+ WebGUI::Session::setScratch('redirectAfterLogin', WebGUI::URL::page('op=checkout'));
+ return WebGUI::Operation::execute('displayLogin');
+ }
+
+ # If no payment gateway has been selected yet, have the user do so now.
+ return WebGUI::Operation::execute('selectPaymentGateway') unless _gatewaySelected;
+
$var{errorLoop} = [ map {{message => $_}} @{$errors} ] if $errors;
# Put contents of cart in template vars
@@ -78,16 +91,12 @@ sub www_checkoutConfirm {
$var{recurringLoop} = $recurring;
$var{recurringItems} = scalar(@$recurring);
- $plugin = WebGUI::Commerce::Payment->load($session{setting}{commercePaymentPlugin});
+ $plugin = WebGUI::Commerce::Payment->load($session{form}{paymentGateway});
- # If the user isn't logged in yet, let him do so or have him create an account
- if ($session{user}{userId} == 1) {
- WebGUI::Session::setScratch('redirectAfterLogin', WebGUI::URL::page('op=checkout'));
- return WebGUI::Operation::execute('displayLogin');
- }
$f = WebGUI::HTMLForm->new;
$f->hidden('op', 'checkoutSubmit');
+ $f->hidden('paymentGateway', $session{form}{paymentGateway});
$f->raw($plugin->checkoutForm);
$f->submit($i18n->get('pay button'));
@@ -103,14 +112,17 @@ sub www_checkoutSubmit {
@normal, $currentPurchase, $checkoutError, @resultLoop, %param, $normal, $recurring, $formError);
$i18n = WebGUI::International->new('Commerce');
-
+
# check if user has already logged in
if ($session{user}{userId} == 1) {
WebGUI::Session::setScratch('redirectAfterLogin', WebGUI::URL::page('op=checkout'));
return WebGUI::Operation::execute('displayLogin');
}
- $plugin = WebGUI::Commerce::Payment->load($session{setting}{commercePaymentPlugin});
+ # Check if a valid payment gateway has bee selected. If not have the user do so.
+ return WebGUI::Operation::execute('selectPaymentGateway') unless _gatewaySelected;
+
+ $plugin = WebGUI::Commerce::Payment->load($session{form}{paymentGateway});
$shoppingCart = WebGUI::Commerce::ShoppingCart->new;
($normal, $recurring) = $shoppingCart->getItems;
@@ -215,7 +227,7 @@ sub www_completePendingTransaction {
#-------------------------------------------------------------------
sub www_confirmTransaction {
my($plugin, %var);
- $plugin = WebGUI::Commerce::Payment->load($session{setting}{commercePaymentPlugin});
+ $plugin = WebGUI::Commerce::Payment->load($session{form}{pg});
if ($plugin->confirmTransaction) {
WebGUI::Commerce::Transaction->new($plugin->getTransactionId)->completeTransaction;
@@ -235,7 +247,7 @@ sub www_editCommerceSettings {
payment=>{label=>$i18n->get('payment tab')},
);
- $paymentPlugin = $session{setting}{commercePaymentPlugin} || $session{config}{paymentPlugins}->[0];
+ $paymentPlugin = $session{config}{paymentPlugins}->[0];
$tabform = WebGUI::TabForm->new(\%tabs);
$tabform->hidden({name => 'op', value => 'editCommerceSettingsSave'});
@@ -259,6 +271,12 @@ sub www_editCommerceSettings {
-value => $session{setting}{commerceCheckoutCanceledTemplateId},
-namespace => 'Commerce/CheckoutCanceled'
);
+ $tabform->getTab('general')->template(
+ -name => 'commerceSelectPaymentGatewayTemplateId',
+ -label => $i18n->get('checkout select payment template'),
+ -value => $session{setting}{commerceSelectPaymentGatewayTemplateId},
+ -namespace => 'Commerce/SelectPaymentGateway'
+ );
$tabform->getTab('general')->email(
-name => 'commerceSendDailyReportTo',
-label => $i18n->get('daily report email'),
@@ -281,7 +299,7 @@ sub www_editCommerceSettings {
$tabform->getTab('payment')->raw('');
$tabform->getTab("payment")->selectList(
-name => 'commercePaymentPlugin',
- -options => \%paymentPlugins, #{map {$_ => $_} @{$session{config}{paymentPlugins}}},
+ -options => \%paymentPlugins,
-label => $i18n->get('payment form'),
-value => [$paymentPlugin],
-extras => 'onChange="activePayment=operateHidden(this.options[this.selectedIndex].value,activePayment)"'
@@ -366,6 +384,32 @@ sub www_listPendingTransactions {
_submenu($output, 'list pending transactions', 'list pending transactions');
}
+#-------------------------------------------------------------------
+sub www_selectPaymentGateway {
+ my ($plugins, $f, $i18n, @pluginLoop, %var);
+
+ $i18n = WebGUI::International->new('Commerce');
+ $plugins = WebGUI::Commerce::Payment->getEnabledPlugins;
+
+ foreach (@$plugins) {
+ push(@pluginLoop, {
+ name => $_->name,
+ namespace => $_->namespace,
+ formElement => WebGUI::Form::radio({name=>'paymentGateway', value=>$_->namespace})
+ });
+ }
+
+ $var{pluginLoop} = \@pluginLoop;
+ $var{message} = $i18n->get('select payment gateway');
+ $var{pluginsAvailable} = @$plugins;
+ $var{noPluginsMessage} = $i18n->get('no payment gateway');
+ $var{formHeader} = WebGUI::Form::formHeader.WebGUI::Form::hidden({name=>'op', value=>'checkoutConfirm'});
+ $var{formSubmit} = WebGUI::Form::submit({value=>$i18n->get('payment gateway select')});
+ $var{formFooter} = WebGUI::Form::formFooter;
+
+ return WebGUI::Template::process($session{setting}{commerceSelectPaymentGatewayTemplateId}, 'Commerce/SelectPaymentGateway', \%var);
+}
+
#-------------------------------------------------------------------
sub www_transactionComplete {
return WebGUI::Operation::execute('viewPurchaseHistory');
diff --git a/lib/WebGUI/i18n/English/Commerce.pm b/lib/WebGUI/i18n/English/Commerce.pm
index cf2fb321b..5ec9cfa53 100755
--- a/lib/WebGUI/i18n/English/Commerce.pm
+++ b/lib/WebGUI/i18n/English/Commerce.pm
@@ -365,6 +365,63 @@ A template loop containing the items that were checked out. The following templa
lastUpdated => 0,
context => q|The message that sais which payment plugins did not compile.|
},
+ 'select payment gateway'=> {
+ message => q|Please select a payment gateway.|,
+ lastUpdated => 0,
+ context => q|The message that asks the user to select a payment gateway.|
+ },
+ 'payment gateway select' => {
+ message => q|Select gateway|,
+ lastUpdated => 0,
+ context => q|The text on the submit button of the select gateway form.|
+ },
+ 'checkout select payment template' => {
+ message => q|Select payment gateway template|,
+ lastUpdated => 0,
+ context => q|The formlabel for the 'select payment gateway template' option in the commerce part of the admin console.|
+ },
+ 'help select payment template title' => {
+ message => q|Select payment gateway template|,
+ lastUpdated => 0,
+ context => q|The title of the 'select payment gateway' help page.|
+ },
+ 'help select payment template body' => {
+ message => q|In this template the following template variables are available:
+
+message
+This is the message that ask the user to select a payment gateway.
+
+pluginsAvailable
+A boolean value that is true when one or more payment plugins can be loaded and are enabled.
+
+noPluginsMessage
+A message that sais that there are no payment plugins that ca be used.
+
+formHeader
+This contains the form header and all hidden form variables that are needed for a successfull checkout.
+
+formFooter
+The form footer.
+
+formSubmit
+The submit button for this form.
+
+pluginLoop
+A template loop containing all enabled payment plugins. Within this loop the following template variables are provided:
+
+name
+The name of the plugin.
+
+namespace
+The namespace of the plugin. You only need this if you want to create your own custom foem elements.
+
+formElement
+A radio button tied to this plugin.
+
|,
+ lastUpdated => 0,
+ context => q|The body of the help page of the select payment gateway template.|
+ },
+
};
1;