From 2c1005522b95c2153f45e9293c3e4865fda12dd3 Mon Sep 17 00:00:00 2001 From: Frank Dillon Date: Thu, 26 Jul 2007 21:15:48 +0000 Subject: [PATCH] Commerce changes: Credit Card failures now bounce user back to checkout screen with error there Added Check commerce plugin and removed select box from Cash plugin. Users now don't have to chose twice. Added label to each payment plugin. ITransact module now defaults to "Credit Card" for display purposes. --- lib/WebGUI/Commerce/Payment.pm | 21 ++- lib/WebGUI/Commerce/Payment/Cash.pm | 64 ++++--- lib/WebGUI/Commerce/Payment/Check.pm | 84 +++++++++ lib/WebGUI/Commerce/Payment/ITransact.pm | 14 ++ lib/WebGUI/Operation/Commerce.pm | 36 ++-- lib/WebGUI/i18n/English/Commerce.pm | 12 +- .../i18n/English/CommercePaymentCash.pm | 7 +- .../i18n/English/CommercePaymentCheck.pm | 163 ++++++++++++++++++ .../i18n/English/CommercePaymentITransact.pm | 7 +- 9 files changed, 364 insertions(+), 44 deletions(-) create mode 100644 lib/WebGUI/Commerce/Payment/Check.pm create mode 100644 lib/WebGUI/i18n/English/CommercePaymentCheck.pm diff --git a/lib/WebGUI/Commerce/Payment.pm b/lib/WebGUI/Commerce/Payment.pm index c8638aaea..3e1b9cea7 100644 --- a/lib/WebGUI/Commerce/Payment.pm +++ b/lib/WebGUI/Commerce/Payment.pm @@ -97,7 +97,13 @@ sub configurationForm { $f = WebGUI::HTMLForm->new($self->session); my $i18n = WebGUI::International->new($self->session, 'Commerce'); - $f->yesNo( + $f->text( + -name => $self->prepend('label'), + -value => $self->label, + -label => $i18n->get('label'), + -hoverHelp => $i18n->get('label hoverhelp'), + ); + $f->yesNo( -name => $self->prepend('enabled'), -value => $self->enabled, -label => $i18n->get('enable'), @@ -289,6 +295,19 @@ sub errorCode { #------------------------------------------------------------------- +=head2 label ( ) + +Returns the label for the commerce plugin. + +=cut + +sub label { + my $self = shift; + return $self->get("label") || $self->namespace; +} + +#------------------------------------------------------------------- + =head2 load ( namespace ) A convienient method to load a plugin. It handles all error checking and stuff for you. diff --git a/lib/WebGUI/Commerce/Payment/Cash.pm b/lib/WebGUI/Commerce/Payment/Cash.pm index 8200d7e86..396d9b80e 100644 --- a/lib/WebGUI/Commerce/Payment/Cash.pm +++ b/lib/WebGUI/Commerce/Payment/Cash.pm @@ -44,22 +44,16 @@ sub checkoutForm { my ($self, $u, $f, %months, %years, $i18n); $self = shift; - $i18n = WebGUI::International->new($self->session, 'CommercePaymentCash'); + $i18n = $self->i18n; $u = WebGUI::User->new($self->session,$self->session->user->userId); $f = WebGUI::HTMLForm->new($self->session); - $f->selectBox( - -name=>"paymentMethod", - -label=>$i18n->get("payment method"), - -value=>[$self->session->form->process("paymentMethod")], - -defaultValue=>['cash'], - -options=> { 'cash' => $i18n->get('cash'), - 'check' => $i18n->get('check'), - 'other' => $i18n->get('other'), - } - ); + $f->readOnly( + -label=>$i18n->get("payment method"), + -value=>ucfirst($self->getPaymentMethod), + ); $f->text( -name => 'firstName', @@ -115,8 +109,7 @@ sub checkoutForm { sub configurationForm { my ($self, $f, $i18n); $self = shift; - $i18n = WebGUI::International->new($self->session, 'CommercePaymentCash'); - + $i18n = $self->i18n; $f = WebGUI::HTMLForm->new($self->session); $f->textarea( @@ -131,7 +124,6 @@ sub configurationForm { -label => $i18n->get('complete transaction'), -hoverHelp => $i18n->get('complete transaction description'), ); - return $self->SUPER::configurationForm($f->printRowsOnly); } @@ -141,6 +133,15 @@ sub confirmTransaction { return 0; } +#------------------------------------------------------------------- +sub i18n { + my $self = shift; + unless (exists $self->{_i18n}) { + $self->{_i18n} = WebGUI::International->new($self->session,'CommercePaymentCash'); + } + return $self->{_i18n}; +} + #------------------------------------------------------------------- =head2 init ( namespace ) @@ -161,18 +162,25 @@ sub init { my ($class, $self); $class = shift; my $session = shift; - $self = $class->SUPER::init($session,'Cash'); - + my $namespace = shift || 'Cash'; + $self = $class->SUPER::init($session,$namespace); return $self; } #------------------------------------------------------------------- sub gatewayId { my $self = shift; - - return $self->get('paymentMethod').":".$self->session->id->generate; + return $self->getPaymentMethod.":".$self->session->id->generate; } +#------------------------------------------------------------------- +sub getPaymentMethod { + my $self = shift; + unless($self->{_paymentMethod}) { + $self->{_paymentMethod} = "cash"; + } + return $self->{_paymentMethod}; +} #------------------------------------------------------------------- sub errorCode { @@ -180,6 +188,19 @@ sub errorCode { return $self->{_error}->{code}; } +#------------------------------------------------------------------- +=head2 label ( ) + +Returns the label for the commerce plugin. + +=cut + +sub label { + my $self = shift; + my $i18n = $self->i18n; + return $self->get("label") || $i18n->get("label"); +} + #------------------------------------------------------------------- sub name { return 'Cash'; @@ -198,7 +219,7 @@ sub normalTransaction { $normal = shift; if ($normal) { - my $i18n = WebGUI::International->new($self->session, 'CommercePaymentCash'); + my $i18n = $self->i18n; $self->{_transactionParams} = { AMT => sprintf('%.2f', $normal->{amount}), DESCRIPTION => $normal->{description} || $i18n->get('no description'), @@ -260,7 +281,7 @@ sub validateFormData { my ($self, @error, $i18n, $currentYear, $currentMonth); $self = shift; - $i18n = WebGUI::International->new($self->session,'CommercePaymentCash'); + $i18n = $self->i18n; push (@error, $i18n->get('invalid firstName')) unless ($self->session->form->process("firstName")); push (@error, $i18n->get('invalid lastName')) unless ($self->session->form->process("lastName")); @@ -271,7 +292,8 @@ sub validateFormData { unless (@error) { $self->{_paymentData} = { - PAYMENTMETHOD => $self->session->form->process("paymentMethod"), + PAYMENTMETHOD => $self->getPaymentMethod, + #$self->session->form->process("paymentMethod"), }; $self->{_userData} = { diff --git a/lib/WebGUI/Commerce/Payment/Check.pm b/lib/WebGUI/Commerce/Payment/Check.pm new file mode 100644 index 000000000..4e9c40856 --- /dev/null +++ b/lib/WebGUI/Commerce/Payment/Check.pm @@ -0,0 +1,84 @@ +package WebGUI::Commerce::Payment::Check; + +=head1 LEGAL + + ------------------------------------------------------------------- + WebGUI is Copyright 2001-2007 Plain Black Corporation. + ------------------------------------------------------------------- + Please read the legal notices (docs/legal.txt) and the license + (docs/license.txt) that came with this distribution before using + this software. + ------------------------------------------------------------------- + http://www.plainblack.com info@plainblack.com + ------------------------------------------------------------------- + +=head1 NAME + +Package WebGUI::Commerce::Payment::Check + +=head1 DESCRIPTION + +Payment plug-in for check transactions. + +=cut + +use strict; +use WebGUI::HTMLForm; +use WebGUI::Commerce::Payment; +use WebGUI::Commerce::Item; +use Tie::IxHash; +use WebGUI::International; +use WebGUI::SQL; +use base 'WebGUI::Commerce::Payment::Cash'; + +#------------------------------------------------------------------- +sub getPaymentMethod { + my $self = shift; + unless($self->{_paymentMethod}) { + $self->{_paymentMethod} = "check"; + } + return $self->{_paymentMethod}; +} + +#------------------------------------------------------------------- +sub i18n { + my $self = shift; + unless (exists $self->{_i18n}) { + $self->{_i18n} = WebGUI::International->new($self->session,'CommercePaymentCheck'); + } + return $self->{_i18n}; +} + +#------------------------------------------------------------------- + +=head2 init ( namespace ) + +Constructor for the Check plugin. + +=head3 session + +A copy of the session object + +=head3 namespace + +The namespace of the plugin. + +=cut + +sub init { + my ($class, $self); + $class = shift; + my $session = shift; + my $namespace = shift || 'Check'; + $self = $class->SUPER::init($session,$namespace); + return $self; +} + +#------------------------------------------------------------------- +sub name { + return 'Check'; +} + + +1; + diff --git a/lib/WebGUI/Commerce/Payment/ITransact.pm b/lib/WebGUI/Commerce/Payment/ITransact.pm index e125f7c52..288fd806d 100644 --- a/lib/WebGUI/Commerce/Payment/ITransact.pm +++ b/lib/WebGUI/Commerce/Payment/ITransact.pm @@ -353,6 +353,20 @@ sub errorCode { return undef; } +#------------------------------------------------------------------- + +=head2 label ( ) + +Returns the label for the commerce plugin. + +=cut + +sub label { + my $self = shift; + my $i18n = WebGUI::International->new($self->session,'CommercePaymentITransact'); + return $self->get("label") || $i18n->get("label"); +} + #------------------------------------------------------------------- sub name { return 'ITransact'; diff --git a/lib/WebGUI/Operation/Commerce.pm b/lib/WebGUI/Operation/Commerce.pm index 86df39dfc..783565e23 100644 --- a/lib/WebGUI/Operation/Commerce.pm +++ b/lib/WebGUI/Operation/Commerce.pm @@ -272,7 +272,9 @@ sub www_checkoutConfirm { my $session = shift; my ($plugin, $f, %var, $errors, $i18n, $shoppingCart, $normal, $recurring, $shipping, $total, $subTotal); $errors = shift; - + my $inVars = shift; + %var = %{$inVars} if (defined $inVars); + $i18n = WebGUI::International->new($session, 'Commerce'); # If the user isn't logged in yet, let him do so or have him create an account @@ -530,21 +532,23 @@ sub www_checkoutSubmit { push(@resultLoop, $var); } - $shoppingCart->empty unless ($checkoutError); - - $param{title} = $i18n->get('transaction error title'); - $param{statusExplanation} = $i18n->get('status codes information'); - $param{resultLoop} = \@resultLoop; - + if($checkoutError) { + $param{'title' } = $i18n->get('transaction error title'); + $param{'statusExplanation'} = $i18n->get('status codes information'); + $param{'resultLoop' } = \@resultLoop; + $param{'purchaseError' } = "true"; + return www_checkoutConfirm($session,undef,\%param); + } + + #Empty shopping cart + $shoppingCart->empty; + #Clear Checkout Scratch _clearCheckoutScratch($session); # If everythings ok show the purchase history - return WebGUI::Operation::TransactionLog::www_viewPurchaseHistory($session) unless ($checkoutError); - - # If an error has occurred show the template errorlog - return $session->style->userStyle(WebGUI::Asset->newByDynamicClass($session,$session->setting->get("commerceTransactionErrorTemplateId"))->process(\%param)); + return WebGUI::Operation::TransactionLog::www_viewPurchaseHistory($session); } - + #------------------------------------------------------------------- =head2 www_completePendingTransaction ( $session ) @@ -666,13 +670,6 @@ sub www_editCommerceSettings { -value => $session->setting->get('commercePurchaseHistoryTemplateId'), -namespace => 'Commerce/ViewPurchaseHistory' ); - $tabform->getTab('general')->template( - -name => 'commerceTransactionErrorTemplateId', - -label => $i18n->get('transaction error template'), - -hoverHelp => $i18n->get('transaction error template description'), - -value => $session->setting->get('commerceTransactionErrorTemplateId'), - -namespace => 'Commerce/TransactionError' - ); $tabform->getTab('general')->template( -name => 'commerceCheckoutCanceledTemplateId', -label => $i18n->get('checkout canceled template'), @@ -1129,6 +1126,7 @@ sub www_selectPaymentGateway { foreach (@$plugins) { push(@pluginLoop, { name => $_->name, + label => $_->label, namespace => $_->namespace, formElement => WebGUI::Form::radio($session,{name=>'paymentGateway', value=>$_->namespace}) }) if ($session->user->isInGroup($_->get('whoCanUse'))); diff --git a/lib/WebGUI/i18n/English/Commerce.pm b/lib/WebGUI/i18n/English/Commerce.pm index 9ac7af424..7402efbe3 100755 --- a/lib/WebGUI/i18n/English/Commerce.pm +++ b/lib/WebGUI/i18n/English/Commerce.pm @@ -643,7 +643,17 @@ our $I18N = { lastUpdated => 1128920490, }, - + 'label' => { + message => q|Label|, + lastUpdated => 0, + context => q|Commerce Payment Plugin Label| + }, + + 'label hoverhelp' => { + message => q|Label for displaying payment plugin to users. This will be the display if user can choose from different payment gateways available.|, + lastUpdated => 0, + context => q|Hoverhelp for Commerce Payment Plugin Label| + }, }; 1; diff --git a/lib/WebGUI/i18n/English/CommercePaymentCash.pm b/lib/WebGUI/i18n/English/CommercePaymentCash.pm index 18e3a5adb..ad0f18bb0 100755 --- a/lib/WebGUI/i18n/English/CommercePaymentCash.pm +++ b/lib/WebGUI/i18n/English/CommercePaymentCash.pm @@ -1,7 +1,12 @@ package WebGUI::i18n::English::CommercePaymentCash; our $I18N = { - 'phone' => { + 'label' => { + message => q|Cash|, + lastUpdated => 0, + context => q|Default Cash payment gateway label| + }, + 'phone' => { message => q|Telephone Number|, lastUpdated => 0, context => q|Form label in the checkout form of the iTransact module.| diff --git a/lib/WebGUI/i18n/English/CommercePaymentCheck.pm b/lib/WebGUI/i18n/English/CommercePaymentCheck.pm new file mode 100644 index 000000000..615d9ed90 --- /dev/null +++ b/lib/WebGUI/i18n/English/CommercePaymentCheck.pm @@ -0,0 +1,163 @@ +package WebGUI::i18n::English::CommercePaymentCheck; + +our $I18N = { + 'label' => { + message => q|Check|, + lastUpdated => 0, + context => q|Default Check payment gateway label| + }, + 'phone' => { + message => q|Telephone Number|, + lastUpdated => 0, + context => q|Form label in the checkout form of the iTransact module.| + }, + 'country' => { + message => q|Country|, + lastUpdated => 0, + context => q|Form label in the checkout form of the iTransact module.| + }, + 'firstName' => { + message => q|First name|, + lastUpdated => 0, + context => q|Form label in the checkout form of the iTransact module.| + }, + 'lastName' => { + message => q|Last name|, + lastUpdated => 0, + context => q|Form label in the checkout form of the iTransact module.| + }, + 'address' => { + message => q|Address|, + lastUpdated => 1101772170, + context => q|Form label in the checkout form of the iTransact module.| + }, + 'city' => { + message => q|City|, + lastUpdated => 1101772171, + context => q|Form label in the checkout form of the iTransact module.| + }, + 'state' => { + message => q|State|, + lastUpdated => 1101772173, + context => q|Form label in the checkout form of the iTransact module.| + }, + 'zipcode' => { + message => q|Zipcode|, + lastUpdated => 1101772174, + context => q|Form label in the checkout form of the iTransact module.| + }, + 'email' => { + message => q|Email|, + lastUpdated => 1101772176, + context => q|Form label in the checkout form of the iTransact module.| + }, + 'cardNumber' => { + message => q|Credit card number|, + lastUpdated => 1101772177, + context => q|Form label in the checkout form of the iTransact module.| + }, + 'expiration date' => { + message => q|Expiration date|, + lastUpdated => 1101772180, + context => q|Form label in the checkout form of the iTransact module.| + }, + 'cvv2' => { + message => q|Verification number (ie. CVV2)|, + lastUpdated => 1101772182, + context => q|Form label in the checkout form of the iTransact module.| + }, + + 'vendorId' => { + message => q|Username (Vendor ID)|, + lastUpdated => 0, + context => q|Form label in the configuration form of the iTransact module.| + }, + 'use cvv2' => { + message => q|Use CVV2|, + lastUpdated => 0, + context => q|Form label in the configuration form of the iTransact module.| + }, + 'emailMessage' => { + message => q|Email message|, + lastUpdated => 0, + context => q|Form label in the configuration form of the iTransact module.| + }, + 'password' => { + message => q|Password|, + lastUpdated => 0, + context => q|Form label in the configuration form of the iTransact module.| + }, + + 'module name' => { + message => q|Cash|, + lastUpdated => 0, + context => q|The displayed name of the payment module.| + }, + + 'invalid firstName' => { + message => q|You have to enter a valid first name.|, + lastUpdated => 0, + context => q|An error indicating that an invalid first name has been entered.| + }, + 'invalid lastName' => { + message => q|You have to enter a valid last name.|, + lastUpdated => 0, + context => q|An error indicating that an invalid last name has been entered.| + }, + 'invalid address' => { + message => q|You have to enter a valid address.|, + lastUpdated => 0, + context => q|An error indicating that an invalid street has been entered.| + }, + 'invalid city' => { + message => q|You have to enter a valid city.|, + lastUpdated => 0, + context => q|An error indicating that an invalid city has been entered.| + }, + 'invalid zip' => { + message => q|You have to enter a valid zipcode.|, + lastUpdated => 0, + context => q|An error indicating that an invalid zipcode has been entered.| + }, + 'invalid email' => { + message => q|You have to enter a valid email address.|, + lastUpdated => 0, + context => q|An error indicating that an invalid email address has been entered.| + }, + 'no description' => { + message => q|No description|, + lastUpdated => 0, + context => q|The default description of purchase of users.| + }, + 'cash' => { + message => q|Cash|, + lastUpdated => 0, + context => q|Option to use physical money as a form of payment.| + }, + 'check' => { + message => q|Check|, + lastUpdated => 0, + context => q|Option to use a check as a form of payment.| + }, + 'other' => { + message => q|Other|, + lastUpdated => 0, + context => q|Option to use a something aside from cash or check as a payment.| + }, + 'payment method' => { + message => q|Payment Method|, + lastUpdated => 0, + context => q|Label for selecting how to pay for this purchase.| + }, + 'complete transaction' => { + message => q|Complete Transaction on Submit?|, + lastUpdated => 0, + }, + 'complete transaction description' => { + message => q|When set to 'yes', the transaction is completed when the user submits payment details. When set to 'no', the transaction is set to pending and must be manually set to complete. This may be useful if you wish to allow site visitors to select the Cash Payment method, but would like to wait for payment to clear before completing the transaction.|, + lastUpdated => 0, + }, +}; + +1; + diff --git a/lib/WebGUI/i18n/English/CommercePaymentITransact.pm b/lib/WebGUI/i18n/English/CommercePaymentITransact.pm index 9f33f074c..92bbb95bf 100755 --- a/lib/WebGUI/i18n/English/CommercePaymentITransact.pm +++ b/lib/WebGUI/i18n/English/CommercePaymentITransact.pm @@ -1,7 +1,12 @@ package WebGUI::i18n::English::CommercePaymentITransact; our $I18N = { - 'phone' => { + 'label' => { + message => q|Credit Card|, + lastUpdated => 0, + context => q|Default ITransact payment gateway label| + }, + 'phone' => { message => q|Telephone Number|, lastUpdated => 0, context => q|Form label in the checkout form of the iTransact module.|