Files
openfoodnetwork/app/services/order_checkout_restart.rb
Luis Ramos 8a9dae0ee2 Run rubocop autocorrect
This is the result of bundle exec rubocop --auto-correct
2020-06-22 12:23:10 +01:00

35 lines
583 B
Ruby

# frozen_string_literal: true
# Resets the passed order to cart state while clearing associated payments and shipments
class OrderCheckoutRestart
def initialize(order)
@order = order
end
def call
return if order.cart?
reset_state_to_cart
clear_shipments
clear_payments
order.reload
end
private
attr_reader :order
def reset_state_to_cart
order.restart_checkout!
end
def clear_shipments
order.shipments.with_state(:pending).destroy_all
end
def clear_payments
order.payments.with_state(:checkout).destroy_all
end
end