Class: Workarea::CancelOrder

Inherits:
Object
  • Object
show all
Defined in:
app/services/workarea/cancel_order.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(order, params = {}) ⇒ CancelOrder

Returns a new instance of CancelOrder.



5
6
7
8
# File 'app/services/workarea/cancel_order.rb', line 5

def initialize(order, params = {})
  @order = order
  @params = params || {}
end

Instance Attribute Details

#orderObject (readonly)

Returns the value of attribute order.



3
4
5
# File 'app/services/workarea/cancel_order.rb', line 3

def order
  @order
end

#paramsObject (readonly)

Returns the value of attribute params.



3
4
5
# File 'app/services/workarea/cancel_order.rb', line 3

def params
  @params
end

Instance Method Details

#performObject



41
42
43
44
45
46
47
# File 'app/services/workarea/cancel_order.rb', line 41

def perform
  restock if restock?
  refund if refund?
  update_fulfillment if update_fulfillment?

  order.cancel.tap { |canceled| update_metrics if canceled }
end

#refundObject



27
28
29
30
31
# File 'app/services/workarea/cancel_order.rb', line 27

def refund
  result = Payment::Refund.new(payment: payment, amounts: refund_amounts)
  result.complete!
  result
end

#refund?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'app/services/workarea/cancel_order.rb', line 14

def refund?
  params[:refund].to_s =~ /true/i
end

#restockObject



22
23
24
25
# File 'app/services/workarea/cancel_order.rb', line 22

def restock
  transaction = Inventory::Transaction.captured_for_order(order.id)
  transaction.rollback unless transaction.blank?
end

#restock?Boolean

Returns:

  • (Boolean)


10
11
12
# File 'app/services/workarea/cancel_order.rb', line 10

def restock?
  params[:restock].to_s =~ /true/i
end

#update_fulfillmentObject



33
34
35
36
37
38
39
# File 'app/services/workarea/cancel_order.rb', line 33

def update_fulfillment
  cancellations = order.items.map do |item|
    { 'id' => item.id.to_s, 'quantity' => item.quantity }
  end

  fulfillment.cancel_items(cancellations)
end

#update_fulfillment?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'app/services/workarea/cancel_order.rb', line 18

def update_fulfillment?
  params[:fulfillment].to_s =~ /true/i
end