From 8bbb80ef5515b90d48fafabd6d14c3a650ddcdca Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Bellet Date: Thu, 31 Mar 2022 15:33:01 +0200 Subject: [PATCH] Catch GatewayError exception and handle by updating flash[:error] --- app/controllers/split_checkout_controller.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/controllers/split_checkout_controller.rb b/app/controllers/split_checkout_controller.rb index 27fdb901ab..40534cf792 100644 --- a/app/controllers/split_checkout_controller.rb +++ b/app/controllers/split_checkout_controller.rb @@ -31,12 +31,16 @@ class SplitCheckoutController < ::BaseController advance_order_state redirect_to_step else - flash.now[:error] = I18n.t('split_checkout.errors.global') + flash.now[:error] ||= I18n.t('split_checkout.errors.global') render status: :unprocessable_entity, operations: cable_car. replace("#checkout", partial("split_checkout/checkout")). replace("#flashes", partial("shared/flashes", locals: { flashes: flash })) end + rescue Spree::Core::GatewayError => e + flash[:error] = I18n.t(:spree_gateway_error_flash_for_checkout, error: e.message) + @order.update_column(:state, "payment") + render operations: cable_car.redirect_to(url: checkout_step_path(:payment)) end private