From b4a45c6adae405ace2765547d63245c5ad327eb6 Mon Sep 17 00:00:00 2001 From: Martin Kamerbeek Date: Thu, 29 May 2008 21:09:29 +0000 Subject: [PATCH] - Fixed recurring payment cancelation and added error handling - Made transactions with recurring items recurring - Fixed some bugs in the email receipt code - Added email receipt template to migrated plugins --- docs/upgrades/upgrade_7.5.10-7.5.11.pl | 8 ++++++-- lib/WebGUI/Shop/PayDriver.pm | 11 ++++++----- lib/WebGUI/Shop/PayDriver/ITransact.pm | 9 +++++---- lib/WebGUI/Shop/Transaction.pm | 23 +++++++++++++++++++---- 4 files changed, 36 insertions(+), 15 deletions(-) diff --git a/docs/upgrades/upgrade_7.5.10-7.5.11.pl b/docs/upgrades/upgrade_7.5.10-7.5.11.pl index beb9c1ae4..8902137cf 100644 --- a/docs/upgrades/upgrade_7.5.10-7.5.11.pl +++ b/docs/upgrades/upgrade_7.5.10-7.5.11.pl @@ -1420,6 +1420,7 @@ sub migratePaymentPlugins { print "\tMigrating WebGUI default commerce plugins..." unless $quiet; foreach my $namespace (qw{ Cash ITransact }) { + # Get properties from old plugin my $properties = $session->db->buildHashRef( 'select fieldName, fieldValue from commerceSettings where type=\'Payment\' and namespace=?', [ @@ -1427,8 +1428,11 @@ sub migratePaymentPlugins { ] ); - $properties->{ groupToUse } = $properties->{ whoCanUse }; + # And set new properties + $properties->{ groupToUse } = $properties->{ whoCanUse }; + $properties->{ receiptEmailTemplateId } = 'BMzuE91-XB8E-XGll1zpvA'; + # Create paydriver instance my $plugin = eval { WebGUI::Pluggable::instanciate("WebGUI::Shop::PayDriver::$namespace", 'create', [ $session, @@ -1437,13 +1441,13 @@ sub migratePaymentPlugins { ]) }; + # Print warning message for ITransact users that they must change their postback url if ( $namespace eq 'ITransact' && $properties->{ vendorId } ) { print "\n\t\t!!CAUTION!!: The postback url for ITransact has changed. Please log in to your virtual " ."terminal and change the postback url to:\n\n\t\t" .'https://'.$session->config->get("sitename")->[0] .'/?shop=pay;method=do;do=processRecurringTransactionPostback;paymentGatewayId='.$plugin->getId."\n\t"; } - } print "Done\n" unless $quiet; diff --git a/lib/WebGUI/Shop/PayDriver.pm b/lib/WebGUI/Shop/PayDriver.pm index b432660f2..a94915ea7 100644 --- a/lib/WebGUI/Shop/PayDriver.pm +++ b/lib/WebGUI/Shop/PayDriver.pm @@ -578,6 +578,7 @@ sub processTransaction { $transactionProperties->{ paymentMethod } = $self; $transactionProperties->{ cart } = $cart; $transactionProperties->{ paymentAddress } = $paymentAddress if defined $paymentAddress; + $transactionProperties->{ isRecurring } = $cart->requiresRecurringPayment; # Create a transaction... my $transaction = WebGUI::Shop::Transaction->create( $self->session, $transactionProperties ); @@ -678,25 +679,25 @@ sub sendNotifications { $var{items} = \@items; # render - my $template = WebGUI::Asset::Template->new($session, $session->setting->get("receiptEmailTemplateId")); + my $template = WebGUI::Asset::Template->new( $session, $self->get("receiptEmailTemplateId") ); my $inbox = WebGUI::Inbox->new($session); # purchase receipt - $inbox->addMessage( + $inbox->addMessage( { message => $template->process(\%var), subject => $i18n->get('receipt subject').' '.$transaction->get('orderNumber'), userId => $transaction->get('userId'), status => 'completed', - ); + } ); # shop owner notification $var{viewDetailUrl} = $url->page('shop=transaction;method=view;transactionId='.$transaction->getId,1); - $inbox->addMessage( + $inbox->addMessage( { message => $template->process(\%var), subject => $i18n->get('a sale has been made').' '.$transaction->get('orderNumber'), groupId => $self->get('saleNotificationGroupId'), status => 'unread', - ); + } ); } #------------------------------------------------------------------- diff --git a/lib/WebGUI/Shop/PayDriver/ITransact.pm b/lib/WebGUI/Shop/PayDriver/ITransact.pm index 7af443c9d..45e4ad0d9 100644 --- a/lib/WebGUI/Shop/PayDriver/ITransact.pm +++ b/lib/WebGUI/Shop/PayDriver/ITransact.pm @@ -18,7 +18,7 @@ sub _generateCancelRecurXml { $vendorIdentification->{ HomePage } = $self->session->setting->get("companyURL"); my $recurUpdate; - $recurUpdate->{ OperationXID } = $transaction->get('gatewayId'); + $recurUpdate->{ OperationXID } = $transaction->get('transactionCode'); $recurUpdate->{ RemReps } = 0; my $xmlStructure = { @@ -247,8 +247,9 @@ sub cancelRecurringPayment { $session->errorHandler->info( "GatewayFailureResponse: result: [" . $response->content . "]" ); return( 0, - $transactionResult->{ Status }, - $transactionResult->{ ErrorMessage } . ' Category: ' . $transactionResult->{ ErrorCategory } + "Status: " . $transactionResult->{ Status } + ." Message: " . $transactionResult->{ ErrorMessage } + ." Category: " . $transactionResult->{ ErrorCategory } ); } else { # RecurUpdateResponse: We have succesfully sent the XML and it was correct. Note that this doesn't mean @@ -264,7 +265,7 @@ sub cancelRecurringPayment { # Uppercase the status b/c the documentation is not clear on the case. my $isSuccess = uc( $status ) eq 'OK' && $remainingTerms == 0; - return ( $isSuccess, $status, "$errorMessage Category: $errorCategory" ); + return ( $isSuccess, "Status: $status Message: $errorMessage Category: $errorCategory" ); } } else { # Connection Error diff --git a/lib/WebGUI/Shop/Transaction.pm b/lib/WebGUI/Shop/Transaction.pm index e0e882763..4e8f05a65 100644 --- a/lib/WebGUI/Shop/Transaction.pm +++ b/lib/WebGUI/Shop/Transaction.pm @@ -72,17 +72,28 @@ sub addItem { =head2 cancelRecurring ( ) -Cancel a recurring transaction, and calls onCancelRecurring in whatever sku is attached to this transaction. +Cancel a recurring transaction, and calls onCancelRecurring in whatever sku is attached to this transaction. If the +cancelation fails, returns an error message. =cut sub cancelRecurring { my ($self) = @_; - $self->getPaymentGateway->cancelRecurringPayment($self); - my ($item) = $self->getItems; + my ($success, $message) = $self->getPaymentGateway->cancelRecurringPayment($self); + + # Handle failed cancelation. + unless ($success) { + return + "Canceling recurring transaction failed. The following response was received from the payment gateway:
" + . $message; + } + + my ($item) = @{ $self->getItems }; $item->getSku->onCancelRecurring($item); my $recurringId = ($self->get('originatingTransactionId') || $self->getId); $self->session->db->write("update transaction set isRecurring=0 where transactionId=? or originatingTransactionId=?",[$recurringId,$recurringId]); + + return undef; } #------------------------------------------------------------------- @@ -606,7 +617,11 @@ sub www_cancelRecurring { my ($class, $session) = @_; my $self = $class->new($session, $session->form->get("transactionId")); return $session->privilege->insufficient unless (WebGUI::Shop::Admin->new($session)->canManage || $session->user->userId eq $self->get('userId')); - $self->cancelRecurring; + my $error = $self->cancelRecurring; + + # TODO: Needs to be templated or included in www_view. + return $error if $error; + return $class->www_view($session); }