diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index a3c4433397..af057db34e 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -153,9 +153,11 @@ class ApplicationController < ActionController::Base def check_order_cycle_expiry if current_order_cycle&.closed? + Bugsnag.notify("Notice: order cycle closed during checkout completion", order: current_order) current_order.empty! current_order.set_order_cycle! nil flash[:info] = I18n.t('order_cycle_closed') + redirect_to main_app.shop_path end end diff --git a/app/controllers/checkout_controller.rb b/app/controllers/checkout_controller.rb index fe392d5058..49bfb940ab 100644 --- a/app/controllers/checkout_controller.rb +++ b/app/controllers/checkout_controller.rb @@ -81,7 +81,11 @@ class CheckoutController < ::BaseController def load_order @order = current_order - redirect_to(main_app.shop_path) && return if redirect_to_shop? + if order_invalid_for_checkout? + Bugsnag.notify("Notice: invalid order loaded during Stripe processing", order: @order) if valid_payment_intent_provided? + redirect_to(main_app.shop_path) && return + end + handle_invalid_stock && return unless valid_order_line_items? return if valid_payment_intent_provided? @@ -90,10 +94,8 @@ class CheckoutController < ::BaseController setup_for_current_state end - def redirect_to_shop? - !@order || - !@order.checkout_allowed? || - @order.completed? + def order_invalid_for_checkout? + !@order || @order.completed? || !@order.checkout_allowed? end def valid_order_line_items? @@ -241,7 +243,7 @@ class CheckoutController < ::BaseController end def checkout_failed(error = RuntimeError.new(order_error)) - Bugsnag.notify(error) + Bugsnag.notify(error, order: @order) flash[:error] = order_error if flash.blank? Checkout::PostCheckoutActions.new(@order).failure end diff --git a/spec/controllers/base_controller_spec.rb b/spec/controllers/base_controller_spec.rb index 02b68b3750..98d6183ea4 100644 --- a/spec/controllers/base_controller_spec.rb +++ b/spec/controllers/base_controller_spec.rb @@ -102,7 +102,7 @@ describe BaseController, type: :controller do it "redirects to shopfront with message if order cycle is expired" do expect(controller).to receive(:current_order_cycle).and_return(oc) - expect(controller).to receive(:current_order).and_return(order).twice + expect(controller).to receive(:current_order).and_return(order).at_least(:twice) expect(oc).to receive(:closed?).and_return(true) expect(order).to receive(:empty!) expect(order).to receive(:set_order_cycle!).with(nil)