From e9313959eb48a94765cb37f311349ecc72f64a19 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Thu, 29 Apr 2010 14:31:13 -0700 Subject: [PATCH] Refactor out template processing code into the PayDriver module. --- lib/WebGUI/Shop/PayDriver.pm | 40 +++++++++---- lib/WebGUI/Shop/PayDriver/ITransact.pm | 11 +--- lib/WebGUI/Shop/PayDriver/Ogone.pm | 82 +++++++++++--------------- lib/WebGUI/i18n/English/PayDriver.pm | 5 ++ 4 files changed, 70 insertions(+), 68 deletions(-) diff --git a/lib/WebGUI/Shop/PayDriver.pm b/lib/WebGUI/Shop/PayDriver.pm index 8828af211..b2dc713a3 100644 --- a/lib/WebGUI/Shop/PayDriver.pm +++ b/lib/WebGUI/Shop/PayDriver.pm @@ -607,6 +607,35 @@ sub processPayment { =head2 processPropertiesFromFormPost ( ) +Updates pay driver with data from Form. + +=cut + +sub processTemplate { + my $self = shift; + my $session = $self->session; + my $templateId = shift; + my $var = shift; + my $i18n = WebGUI::International->new($session, 'PayDriver'); + + my $template = WebGUI::Asset::Template->new($session, $templateId); + my $output; + if (defined $template) { + $template->prepare; + $output = $template->process($var); + } + else { + $output = $i18n->get('template gone'); + } + return $output; + + +} + +#------------------------------------------------------------------- + +=head2 processPropertiesFromFormPost ( ) + Updates ship driver with data from Form. =cut @@ -752,16 +781,7 @@ sub www_getCredentials { }; $self->appendCartVariables($var); - my $template = WebGUI::Asset::Template->new($session, $self->get("summaryTemplateId")); - my $output; - if (defined $template) { - $template->prepare; - $output = $template->process($var); - } - else { - $output = $i18n->get('template gone', 'PayDriver_ITransact'); - } - + my $output = $self->processTemplate($self->get("summaryTemplateId"), $var); return $session->style->userStyle($output); } diff --git a/lib/WebGUI/Shop/PayDriver/ITransact.pm b/lib/WebGUI/Shop/PayDriver/ITransact.pm index de6bc0665..8cb7d9a69 100644 --- a/lib/WebGUI/Shop/PayDriver/ITransact.pm +++ b/lib/WebGUI/Shop/PayDriver/ITransact.pm @@ -669,16 +669,7 @@ sub www_getCredentials { }); $self->appendCartVariables($var); - my $template = WebGUI::Asset::Template->new($session, $self->get("credentialsTemplateId")); - my $output; - if (defined $template) { - $template->prepare; - $output = $template->process($var); - } - else { - $output = $i18n->get('template gone'); - } - + my $output = $self->processTemplate($self->get("credentialsTemplateId"), $var); return $session->style->userStyle($output); } diff --git a/lib/WebGUI/Shop/PayDriver/Ogone.pm b/lib/WebGUI/Shop/PayDriver/Ogone.pm index 81a6687b3..2f7a1743f 100644 --- a/lib/WebGUI/Shop/PayDriver/Ogone.pm +++ b/lib/WebGUI/Shop/PayDriver/Ogone.pm @@ -257,54 +257,6 @@ sub ogoneCheckoutButton { #------------------------------------------------------------------- -=head2 www_getCredentials ( [ addressId ] ) - -Displays the checkout form for this plugin. - -=head3 addressId - -Optionally supply this variable which will set the payment address to this addressId. - -=cut - -sub www_getCredentials { - my ($self, $addressId) = @_; - my $session = $self->session; - my $i18n = WebGUI::International->new( $session, 'PayDriver_Ogone' ); - - # Fetch transaction - my $transactionId = $session->form->process('transactionId'); - my $transaction; - if ($transactionId) { - $transaction = WebGUI::Shop::Transaction->new( $session, $transactionId ); - } - - # Or generate a new one - unless ($transaction) { - $transaction = $self->processTransaction( ); - } - - # Generate 'Proceed' button - my $var = { - proceedButton => $self->ogoneCheckoutButton, - }; - $self->appendCartVariables($var); - - my $template = WebGUI::Asset::Template->new($session, $self->get("summaryTemplateId")); - my $output; - if (defined $template) { - $template->prepare; - $output = $template->process($var); - } - else { - $output = $i18n->get('template gone', 'PayDriver_ITransact'); - } - - return $session->style->userStyle($output); -} - -#------------------------------------------------------------------- - =head2 checkPostbackSHA ( ) Processes the postback data Ogone sends after a payment/cancelation. Figures out which transaction the data belongs @@ -505,6 +457,40 @@ sub www_edit { #------------------------------------------------------------------- +=head2 www_getCredentials ( ) + +Displays the checkout form for this plugin. + +=cut + +sub www_getCredentials { + my ($self) = @_; + my $session = $self->session; + + # Fetch transaction + my $transactionId = $session->form->process('transactionId'); + my $transaction; + if ($transactionId) { + $transaction = WebGUI::Shop::Transaction->new( $session, $transactionId ); + } + + # Or generate a new one + unless ($transaction) { + $transaction = $self->processTransaction( ); + } + + # Generate 'Proceed' button + my $var = { + proceedButton => $self->ogoneCheckoutButton, + }; + $self->appendCartVariables($var); + + my $output = $self->processTemplate($self->get("summaryTemplateId"), $var); + return $session->style->userStyle($output); +} + +#------------------------------------------------------------------- + =head2 www_processTransaction ( ) This method is called by the post sale notfication. diff --git a/lib/WebGUI/i18n/English/PayDriver.pm b/lib/WebGUI/i18n/English/PayDriver.pm index c91fb0341..aece199ba 100644 --- a/lib/WebGUI/i18n/English/PayDriver.pm +++ b/lib/WebGUI/i18n/English/PayDriver.pm @@ -93,6 +93,11 @@ our $I18N = { lastUpdated => 0, context => q{Link to begin checkout again after failure}, }, + 'template gone' => { + message => q|The template for entering in credentials has been deleted. Please notify the site administrator.|, + lastUpdated => 0, + context => q|Error message when a template cannot be accessed.| + }, }; 1;