2022-09-15 20:19:19 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
# Provides methods for cancel an order
|
2022-09-16 17:54:41 +02:00
|
|
|
class Orders::OrderCanceledService
|
2022-09-15 20:19:19 +02:00
|
|
|
def call(order, current_user)
|
2022-09-16 17:54:41 +02:00
|
|
|
raise ::UpdateOrderStateError if %w[cart canceled refunded delivered].include?(order.state)
|
2022-09-15 20:19:19 +02:00
|
|
|
|
|
|
|
order.state = 'canceled'
|
|
|
|
ActiveRecord::Base.transaction do
|
|
|
|
activity = order.order_activities.create(activity_type: 'canceled', operator_profile_id: current_user.invoicing_profile.id)
|
|
|
|
order.save
|
|
|
|
NotificationCenter.call type: 'notify_user_order_is_canceled',
|
|
|
|
receiver: order.statistic_profile.user,
|
|
|
|
attached_object: activity
|
|
|
|
end
|
|
|
|
order.reload
|
|
|
|
end
|
|
|
|
end
|