Skip to content

Commit

Permalink
Catch GatewayError exception and handle by updating flash.now[:error]
Browse files Browse the repository at this point in the history
  • Loading branch information
jibees committed Apr 1, 2022
1 parent e2b1c0d commit 4f10b92
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions app/controllers/split_checkout_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ def edit
end

def update
if confirm_order || update_order
if confirm_or_update_order
return if performed?

clear_invalid_payments
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")).
Expand All @@ -40,6 +40,13 @@ def update

private

def confirm_or_update_order
confirm_order || update_order
rescue Spree::Core::GatewayError => e
flash.now[:error] = I18n.t(:spree_gateway_error_flash_for_checkout, error: e.message)
false
end

def clear_invalid_payments
@order.payments.with_state(:invalid).delete_all
end
Expand Down

0 comments on commit 4f10b92

Please sign in to comment.