diff --git a/app/controllers/split_checkout_controller.rb b/app/controllers/split_checkout_controller.rb index 28cc0220b2..6ded33fb28 100644 --- a/app/controllers/split_checkout_controller.rb +++ b/app/controllers/split_checkout_controller.rb @@ -36,14 +36,7 @@ class SplitCheckoutController < ::BaseController advance_order_state redirect_to_step else - flash.now[:error] ||= I18n.t( - 'split_checkout.errors.saving_failed', - messages: @order.errors.full_messages.to_sentence - ) - - render status: :unprocessable_entity, operations: cable_car. - replace("#checkout", partial("split_checkout/checkout")). - replace("#flashes", partial("shared/flashes", locals: { flashes: flash })) + render_error end rescue Spree::Core::GatewayError => e flash[:error] = I18n.t(:spree_gateway_error_flash_for_checkout, error: e.message) @@ -53,6 +46,17 @@ class SplitCheckoutController < ::BaseController private + def render_error + flash.now[:error] ||= I18n.t( + 'split_checkout.errors.saving_failed', + messages: @order.errors.full_messages.to_sentence + ) + + render status: :unprocessable_entity, operations: cable_car. + replace("#checkout", partial("split_checkout/checkout")). + replace("#flashes", partial("shared/flashes", locals: { flashes: flash })) + end + def flash_error_when_no_shipping_method_available flash[:error] = I18n.t('split_checkout.errors.no_shipping_methods_available') end