User cart not automatically cleaned with paypal payment method

Create issue
Issue #773 resolved
Former user created an issue

On a successful paypal payment, when the user is returned to the site success page, there is a possibility that the paypal IPN request has not been already processed. Since the cart is cleared when the IPN is received, the user will see it's cart still full with his just processed order.

This cause several problems: - The client may think that his order has not correctly processed. - If the client click on the cart and the IPN has been received before completing the request, the user will then see an empty cart page - If the client click on the cart and the IPN request has still not arrived, the client may then proceed to another checkout

The following page clears the cart when the user is returned from the paypal payment (on the success page). The rest of the order is then proceeded normally when the IPN is processed: {{{ --- satchmo-0.8.1.orig/satchmo/payment/modules/paypal/ +++ satchmo-0.8.1/satchmo/payment/modules/paypal/ @@ -19,6 +19,7 @@ from satchmo.payment.config import payment_live from import Cart from satchmo.utils.dynamic import lookup_url, lookup_template +from import bad_or_missing

log = logging.getLogger()

@@ -155,9 +156,6 @@ for item in order.orderitem_set.filter(productsubscriptionproductrecurring=True, completed=False): item.completed = True - for cart in Cart.objects.filter( - cart.empty() - except: log.exception(''.join(format_exception(*exc_info())))

@@ -185,3 +183,27 @@ return False

 return True

+ +def success(request): + """ + The order has been succesfully processed. This can be used to generate a receipt or some other confirmation + """ + try: + order = Order.objects.from_request(request) + except Order.DoesNotExist: + return bad_or_missing(request, _('Your order has already been processed.')) + + # Added to track total sold for each product + for item in order.orderitem_set.all(): + product = item.product + product.total_sold += item.quantity + product.items_in_stock -= item.quantity + + + # Clean up cart now, the rest of the order will be cleaned on paypal IPN + for cart in Cart.objects.filter( + cart.empty() + + del request.session['orderID'] + context = RequestContext(request, {'order': order}) + return render_to_response('checkout/success.html', context) --- satchmo-0.8.1.orig/satchmo/payment/modules/paypal/ +++ satchmo-0.8.1/satchmo/payment/modules/paypal/ @@ -6,6 +6,6 @@ urlpatterns = patterns('satchmo', (r'^$', 'payment.modules.paypal.views.pay_ship_info', {'SSL': config.SSL.value}, 'PAYPAL_satchmo_checkout-step2'), (r'^confirm/$', 'payment.modules.paypal.views.confirm_info', {'SSL': config.SSL.value}, 'PAYPAL_satchmo_checkout-step3 '), - (r'^success/$', 'payment.views.checkout.success', {'SSL': config.SSL.value}, 'PAYPAL_satchmo_checkout-success'), + (r'^success/$', 'payment.modules.paypal.views.success', {'SSL': config.SSL.value}, 'PAYPAL_satchmo_checkout-success'), (r'^ipn/$', 'payment.modules.paypal.views.ipn', {'SSL': config.SSL.value}, 'PAYPAL_satchmo_checkout-ipn'), ) }}}

Reported by mbouchar

Comments (2)

  1. Log in to comment