Move advance_order_state from checkout_controller to OrderWorkflow service

This commit is contained in:
Luis Ramos
2020-07-28 23:43:07 +01:00
parent 26eee4631f
commit c3f99050fd
2 changed files with 10 additions and 11 deletions

View File

@@ -148,7 +148,7 @@ class CheckoutController < Spree::StoreController
end
def handle_redirect_from_stripe
if advance_order_state(@order) && order_complete?
if OrderWorkflow.new(@order).next && order_complete?
checkout_succeeded
redirect_to(order_path(@order)) && return
else
@@ -177,7 +177,7 @@ class CheckoutController < Spree::StoreController
@order.select_shipping_method(shipping_method_id) if @order.state == "delivery"
next if advance_order_state(@order)
next if OrderWorkflow.new(@order).next
return update_failed
end
@@ -194,15 +194,6 @@ class CheckoutController < Spree::StoreController
true
end
# Perform order.next, guarding against StaleObjectErrors
def advance_order_state(order)
tries ||= 3
order.next
rescue ActiveRecord::StaleObjectError
retry unless (tries -= 1).zero?
false
end
def order_error
if @order.errors.present?
@order.errors.full_messages.to_sentence

View File

@@ -13,6 +13,14 @@ class OrderWorkflow
advance_order!(advance_order_options)
end
def next
tries ||= 3
order.next
rescue ActiveRecord::StaleObjectError
retry unless (tries -= 1).zero?
false
end
private
def advance_order_options