Extract #gateway_error

This commit is contained in:
Matt-Yorkley
2021-12-05 23:28:01 +00:00
parent 7633255bea
commit 28d89103eb
2 changed files with 8 additions and 7 deletions

View File

@@ -33,7 +33,8 @@ class CheckoutController < ::BaseController
def edit
return handle_redirect_from_stripe if valid_payment_intent_provided?
rescue Spree::Core::GatewayError => e
rescue_from_spree_gateway_error(e)
gateway_error(e)
action_failed(e)
end
def update
@@ -42,7 +43,8 @@ class CheckoutController < ::BaseController
checkout_workflow(params_adapter.shipping_method_id)
rescue Spree::Core::GatewayError => e
rescue_from_spree_gateway_error(e)
gateway_error(e)
action_failed(e)
rescue StandardError => e
flash[:error] = I18n.t("checkout.failed")
action_failed(e)
@@ -204,11 +206,6 @@ class CheckoutController < ::BaseController
end
end
def rescue_from_spree_gateway_error(error)
flash[:error] = t(:spree_gateway_error_flash_for_checkout, error: error.message)
action_failed(error)
end
def permitted_params
PermittedAttributes::Checkout.new(params).call
end

View File

@@ -66,4 +66,8 @@ module OrderCompletion
@order.errors.full_messages.to_sentence
end
def gateway_error(error)
flash[:error] = t(:spree_gateway_error_flash_for_checkout, error: error.message)
end
end