From 760abafd9c803a511eeaae81c7df3505e27671ee Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Mon, 24 May 2010 11:05:33 -0700 Subject: [PATCH] Put back a www_checkout method, to be used by the Payment plugin when displaying upstream errors. Fixes bug #11584. --- docs/changelog/7.x.x.txt | 1 + lib/WebGUI/Shop/Cart.pm | 52 ++++++++++++++++++++++++++-------------- 2 files changed, 35 insertions(+), 18 deletions(-) diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index 2c4fddd1d..c91862e18 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -5,6 +5,7 @@ - added #9774: More owner information in the gallery - fixed #11581: Calendar problems - fixed #11583: EMS: Tokens do not follow their permissions + - fixed #11584: Errors on checkout when payment problems occur 7.9.5 - Asset->www_copy now has a progress bar diff --git a/lib/WebGUI/Shop/Cart.pm b/lib/WebGUI/Shop/Cart.pm index 2da7a25ec..5b2afe4f5 100644 --- a/lib/WebGUI/Shop/Cart.pm +++ b/lib/WebGUI/Shop/Cart.pm @@ -905,6 +905,38 @@ sub www_ajaxSetCartItemShippingId { #------------------------------------------------------------------- +=head2 www_checkout ( ) + +All checks and work for checking out are contained in here. + +=cut + +sub www_checkout { + my $self = shift; + my $session = $self->session; + ##Setting a shipping address greatly simplifies the Transaction + if (! $self->requiresShipping && ! $self->get('shippingAddressId')) { + $self->update({shippingAddressId => $self->get('billingAddressId')}); + } + if ($self->readyForCheckout()) { + my $total = $self->calculateTotal; + ##Handle rounding errors, and checkout immediately if the amount is 0 since + ##at least the ITransact driver won't accept $0 checkout. + if (sprintf('%.2f', $total + $self->calculateShopCreditDeduction($total)) eq '0.00') { + my $transaction = WebGUI::Shop::Transaction->create($session, {cart => $self}); + $transaction->completePurchase('zero', 'success', 'success'); + $self->onCompletePurchase; + $transaction->sendNotifications(); + return $transaction->thankYou(); + } + my $gateway = $self->getPaymentGateway; + return $gateway->www_getCredentials; + } + return $self->www_view; +} + +#------------------------------------------------------------------- + =head2 www_lookupPosUser ( ) Adds a Point of Sale user to the cart. @@ -950,24 +982,8 @@ sub www_update { return undef; } elsif ($session->form->get('checkout')) { - ##Setting a shipping address greatly simplifies the Transaction - if (! $self->requiresShipping && ! $self->get('shippingAddressId')) { - $self->update({shippingAddressId => $self->get('billingAddressId')}); - } - if ($self->readyForCheckout()) { - my $total = $self->calculateTotal; - ##Handle rounding errors, and checkout immediately if the amount is 0 since - ##at least the ITransact driver won't accept $0 checkout. - if (sprintf('%.2f', $total + $self->calculateShopCreditDeduction($total)) eq '0.00') { - my $transaction = WebGUI::Shop::Transaction->create($session, {cart => $self}); - $transaction->completePurchase('zero', 'success', 'success'); - $self->onCompletePurchase; - $transaction->sendNotifications(); - return $transaction->thankYou(); - } - my $gateway = $self->getPaymentGateway; - return $gateway->www_getCredentials; - } + ##Shortcut method for checkout, so that the cart form contents don't get lost. + return $self->www_checkout(); } return $self->www_view; }