From 0ba670b1807be507a6766122ddd65d90d4724d18 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Fri, 27 Nov 2020 11:42:46 +0000 Subject: [PATCH] Ensure order is cleanly reset to cart state when redirecting to cart --- app/controllers/spree/paypal_controller_decorator.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/controllers/spree/paypal_controller_decorator.rb b/app/controllers/spree/paypal_controller_decorator.rb index 9d20713efa..71d559590a 100644 --- a/app/controllers/spree/paypal_controller_decorator.rb +++ b/app/controllers/spree/paypal_controller_decorator.rb @@ -61,7 +61,7 @@ Spree::PaypalController.class_eval do # At this point the user has come back from the Paypal form, and we get one # last chance to interact with the payment process before the money moves... - return handle_insufficient_stock unless sufficient_stock? + return reset_to_cart unless sufficient_stock? @order.payments.create!({ source: Spree::PaypalExpressCheckout.create({ @@ -114,6 +114,11 @@ Spree::PaypalController.class_eval do end end + def reset_to_cart + OrderCheckoutRestart.new(@order).call + handle_insufficient_stock + end + # See #1074 and #1837 for more detail on why we need this # An 'orphaned' Spree::Payment is created for every call to CheckoutController#update # for orders that are processed using a Spree::Gateway::PayPalExpress payment method