diff --git a/lib/WebGUI/Commerce/Payment.pm b/lib/WebGUI/Commerce/Payment.pm index 8b012bf05..a6ea2c9aa 100644 --- a/lib/WebGUI/Commerce/Payment.pm +++ b/lib/WebGUI/Commerce/Payment.pm @@ -21,7 +21,7 @@ An abstract class for all payment plugins to extend. Invoking goes as follows: - $plugin = WebGUI::Commerce::Payment->new('MyPlugin'); + $plugin = WebGUI::Commerce::Payment->init('MyPlugin'); =head1 METHODS @@ -173,11 +173,12 @@ Returns a reference to an array of all enabled instantiated payment plugins. =cut sub getEnabledPlugins { + my ($session) = @_; my (@enabledPlugins, $plugin, @plugins); - @enabledPlugins = $self->session->db->buildArray("select namespace from commerceSettings where type='Payment' and fieldName='enabled' and fieldValue='1'"); + @enabledPlugins = $session->db->buildArray("select namespace from commerceSettings where type='Payment' and fieldName='enabled' and fieldValue='1'"); foreach (@enabledPlugins) { - $plugin = WebGUI::Commerce::Payment->load($_); + $plugin = WebGUI::Commerce::Payment->load($session, $_); push(@plugins, $plugin) if ($plugin); } @@ -197,13 +198,14 @@ The namespace of the plugin. =cut sub init { - my ($class, $namespace, $properties); + my ($class, $session, $namespace, $properties); $class = shift; + $session = shift; $namespace = shift; - $properties = $self->session->db->buildHashRef("select fieldName, fieldValue from commerceSettings where namespace=".$self->session->db->quote($namespace)." and type='Payment'"); + $properties = $session->db->buildHashRef("select fieldName, fieldValue from commerceSettings where namespace=".$session->db->quote($namespace)." and type='Payment'"); - bless {_properties=>$properties, _namespace=>$namespace, _enabled=>$properties->{enabled}}, $class; + bless {_session=>$session, _properties=>$properties, _namespace=>$namespace, _enabled=>$properties->{enabled}}, $class; } #------------------------------------------------------------------- @@ -215,6 +217,7 @@ Returns the gatewayId of the transaction. You must override this method. =cut sub gatewayId { + my ($self) = @_; return $self->session->errorHandler->fatal("You must override the gatewayId method in your Payment plugin."); } @@ -253,6 +256,7 @@ Returns the error code of the last submission. =cut sub errorCode { + my ($self) = @_; return $self->session->errorHandler->fatal("You must override thie errorCode method in the payment plugin."); } @@ -263,6 +267,10 @@ sub errorCode { A convienient method to load a plugin. It handles all error checking and stuff for you. This is a SUPER class method only and shoud NOT be overridden. +=head3 session + +The session variable. + =head3 namespace The namespace of the plugin. @@ -272,14 +280,15 @@ The namespace of the plugin. sub load { my ($class, $namespace, $load, $cmd, $plugin); $class = shift; + my $session = shift; $namespace = shift; $cmd = "WebGUI::Commerce::Payment::$namespace"; $load = "use $cmd"; eval($load); - $self->session->errorHandler->warn("Payment plugin failed to compile: $cmd.".$@) if($@); + $session->errorHandler->warn("Payment plugin failed to compile: $cmd.".$@) if($@); $plugin = eval($cmd."->init"); - $self->session->errorHandler->warn("Couldn't instantiate payment plugin: $cmd.".$@) if($@); + $session->errorHandler->warn("Couldn't instantiate payment plugin: $cmd.".$@) if($@); return $plugin; } @@ -292,7 +301,8 @@ Returns the (display) name of the plugin. You must override this method. =cut sub name { - return $self->session->errorHandler->fatal("You must override the name method in the payment plugin."); + my ($session) = @_; + return $session->errorHandler->fatal("You must override the name method in the payment plugin."); } #------------------------------------------------------------------- @@ -363,6 +373,7 @@ Returns the result code of the transaction. You must override this method. =cut sub resultCode { + my ($self) = @_; return $self->session->errorHandler->fatal("You must override the resultCode method in the payment plugin."); } @@ -375,6 +386,7 @@ Returns the result message of the transaction. You must override this method. =cut sub resultMessage { + my ($self) = @_; return $self->session->errorHandler->fatal("You must override the resultMessage method in the payment plugin."); } @@ -420,8 +432,9 @@ The period you want the name for. =cut sub recurringPeriodValues { + my ($session) = @_; my ($i18n, %periods); - $i18n = WebGUI::International->new($self->session, 'Commerce'); + $i18n = WebGUI::International->new($session, 'Commerce'); tie %periods, "Tie::IxHash"; %periods = ( Weekly => $i18n->get('weekly'), @@ -438,6 +451,19 @@ sub recurringPeriodValues { #------------------------------------------------------------------- +=head2 session ( ) + +Returns the local copy of the session variable + +=cut + +sub session { + my ($self) = @_; + return $self->{_session}; +} + +##------------------------------------------------------------------- + =head2 shippingCost ( amount ) This sets the shippingcost involved with the transaction. Your plugin must override this @@ -450,6 +476,7 @@ The amaount of money that's being charged for shipping. =cut sub shippingCost { + my ($self) = @_; return $self->session->errorHandler->fatal("You must override the shippingCost method in the payment plugin."); } @@ -467,6 +494,7 @@ The description of the shiping cost. =cut sub shippingDescription { + my ($self) = @_; return $self->session->errorHandler->fatal("You must override the shippingDescription method in the payment plugin."); } @@ -484,6 +512,7 @@ You must override this method. =cut sub supports { + my ($self) = @_; return $self->session->errorHandler->fatal("You must override the supports method in the payment plugin."); } @@ -496,6 +525,7 @@ A boolean indicating whether the payment has been finished or not. You must over =cut sub transactionCompleted { + my ($self) = @_; return $self->session->errorHandler->fatal("You must override the transactionCompleted method in the payment plugin."); } @@ -508,6 +538,7 @@ Returns an error message if a transaction error has occurred. You must override =cut sub transactionError { + my ($self) = @_; return $self->session->errorHandler->fatal("You must override the transactionError method in the payment plugin."); } @@ -520,6 +551,7 @@ A boolean indicating whether the payment is pending or not. You must override th =cut sub transactionPending { + my ($self) = @_; return $self->session->errorHandler->fatal("You must override the transactionPending method in the payment plugin."); } @@ -534,6 +566,7 @@ undef. You must override this method. =cut sub validateFormData { + my ($self) = @_; return $self->session->errorHandler->fatal("You must override the validateFormData method in the payment plugin."); } diff --git a/lib/WebGUI/Commerce/Payment/ITransact.pm b/lib/WebGUI/Commerce/Payment/ITransact.pm index 6319f357b..f4d23c9ad 100644 --- a/lib/WebGUI/Commerce/Payment/ITransact.pm +++ b/lib/WebGUI/Commerce/Payment/ITransact.pm @@ -565,14 +565,14 @@ sub errorCode { #------------------------------------------------------------------- sub name { - my $i18n = WebGUI::International->new($self->session, "CommercePaymentITransact"); + my ($session) = @_; + my $i18n = WebGUI::International->new($session, "CommercePaymentITransact"); return $i18n->get('module name'); } #------------------------------------------------------------------- sub namespace { my $self = shift; - return $self->{_namespace}; } diff --git a/lib/WebGUI/Commerce/ShoppingCart.pm b/lib/WebGUI/Commerce/ShoppingCart.pm index 72b94c3b9..f759d375f 100644 --- a/lib/WebGUI/Commerce/ShoppingCart.pm +++ b/lib/WebGUI/Commerce/ShoppingCart.pm @@ -206,7 +206,7 @@ sub getItems { my ($self, $periodResolve, %cartContent, $item, $properties, @recurring, @normal); $self = shift; - $periodResolve = WebGUI::Commerce::Payment::recurringPeriodValues; + $periodResolve = WebGUI::Commerce::Payment::recurringPeriodValues($self->session); %cartContent = %{$self->{_items}}; foreach (values(%cartContent)) { $item = WebGUI::Commerce::Item->new($_->{itemId}, $_->{itemType}); diff --git a/lib/WebGUI/Commerce/Transaction.pm b/lib/WebGUI/Commerce/Transaction.pm index 7c80a3b12..f4b8ea6ca 100644 --- a/lib/WebGUI/Commerce/Transaction.pm +++ b/lib/WebGUI/Commerce/Transaction.pm @@ -61,7 +61,7 @@ sub cancelTransaction { # Recurring transactions can only have one item, so our items must be the first $item = $self->getItems->[0]; - $plugin = WebGUI::Commerce::Payment->load($self->gateway); + $plugin = WebGUI::Commerce::Payment->load($self->session, $self->gateway); $plugin->cancelRecurringPayment({ id => $self->gatewayId, transaction => $self, diff --git a/lib/WebGUI/Operation/Commerce.pm b/lib/WebGUI/Operation/Commerce.pm index 8b7b2c890..3f84c23b2 100644 --- a/lib/WebGUI/Operation/Commerce.pm +++ b/lib/WebGUI/Operation/Commerce.pm @@ -60,7 +60,7 @@ sub _clearShippingScratch { sub _paymentSelected { my $session = shift; return 0 unless ($session->scratch->get('paymentGateway')); - my $plugin = WebGUI::Commerce::Payment->load($session->scratch->get('paymentGateway')); + my $plugin = WebGUI::Commerce::Payment->load($session, $session->scratch->get('paymentGateway')); return 1 if ($plugin && $plugin->enabled); return 0; } @@ -171,7 +171,7 @@ sub www_checkoutConfirm { $var{total} = sprintf('%.2f', $total + $shipping->calc); - $plugin = WebGUI::Commerce::Payment->load($session->scratch->get('paymentGateway')); + $plugin = WebGUI::Commerce::Payment->load($session, $session->scratch->get('paymentGateway')); $f = WebGUI::HTMLForm->new($session); $f->hidden( @@ -217,7 +217,7 @@ sub www_checkoutSubmit { $shipping->setOptions(Storable::thaw($session->scratch->get('shippingOptions'))) if ($session->scratch->get('shippingOptions')); # Load payment plugin. - $plugin = WebGUI::Commerce::Payment->load($session->scratch->get('paymentGateway')); + $plugin = WebGUI::Commerce::Payment->load($session, $session->scratch->get('paymentGateway')); $shoppingCart = WebGUI::Commerce::ShoppingCart->new; ($normal, $recurring) = $shoppingCart->getItems; @@ -339,7 +339,7 @@ sub www_confirmRecurringTransaction { my $session = shift; my($plugin, %var); - $plugin = WebGUI::Commerce::Payment->load($session->form->process("gateway")); + $plugin = WebGUI::Commerce::Payment->load($session, $session->form->process("gateway")); if ($plugin) { $plugin->confirmRecurringTransaction; } @@ -349,7 +349,7 @@ sub www_confirmRecurringTransaction { sub www_confirmTransaction { my $session = shift; my($plugin, %var); - $plugin = WebGUI::Commerce::Payment->load($session->form->process("pg")); + $plugin = WebGUI::Commerce::Payment->load($session, $session->form->process("pg")); if ($plugin->confirmTransaction) { WebGUI::Commerce::Transaction->new($plugin->getTransactionId)->completeTransaction; @@ -433,7 +433,7 @@ sub www_editCommerceSettings { # Check which payment plugins will compile, and load them. foreach (@{$session->config->get("paymentPlugins")}) { - $plugin = WebGUI::Commerce::Payment->load($_); + $plugin = WebGUI::Commerce::Payment->load($session, $_); if ($plugin) { push(@paymentPlugins, $plugin); $paymentPlugins{$_} = $plugin->name; @@ -668,7 +668,7 @@ sub www_selectPaymentGateway { _clearPaymentScratch; $i18n = WebGUI::International->new($session, 'Commerce'); - $plugins = WebGUI::Commerce::Payment->getEnabledPlugins; + $plugins = WebGUI::Commerce::Payment->getEnabledPlugins($session); if (scalar(@$plugins) > 1) { foreach (@$plugins) { push(@pluginLoop, { @@ -696,7 +696,7 @@ sub www_selectPaymentGateway { #------------------------------------------------------------------- sub www_selectPaymentGatewaySave { my $session = shift; - if (WebGUI::Commerce::Payment->load($session->form->process("paymentGateway"))->enabled) { + if (WebGUI::Commerce::Payment->load($session, $session->form->process("paymentGateway"))->enabled) { $session->scratch->set('paymentGateway', $session->form->process("paymentGateway")); } else { $session->scratch->set('paymentGateway', '-delete-'); diff --git a/lib/WebGUI/Operation/Subscription.pm b/lib/WebGUI/Operation/Subscription.pm index 2c89c1f1d..6d720df99 100644 --- a/lib/WebGUI/Operation/Subscription.pm +++ b/lib/WebGUI/Operation/Subscription.pm @@ -238,7 +238,7 @@ sub www_editSubscription { -label => $i18n->get('subscription duration'), -hoverHelp => $i18n->get('subscription duration description'), -value => [$properties->{duration} || 'Monthly'], - -options=> WebGUI::Commerce::Payment::recurringPeriodValues + -options=> WebGUI::Commerce::Payment->recurringPeriodValues($session), ); $f->text( -name => 'executeOnSubscription',