Class: Workarea::CancelOrder
- Inherits:
-
Object
- Object
- Workarea::CancelOrder
- Defined in:
- app/services/workarea/cancel_order.rb
Instance Attribute Summary collapse
-
#order ⇒ Object
readonly
Returns the value of attribute order.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
Instance Method Summary collapse
-
#initialize(order, params = {}) ⇒ CancelOrder
constructor
A new instance of CancelOrder.
- #perform ⇒ Object
- #refund ⇒ Object
- #refund? ⇒ Boolean
- #restock ⇒ Object
- #restock? ⇒ Boolean
- #update_fulfillment ⇒ Object
- #update_fulfillment? ⇒ Boolean
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
#order ⇒ Object (readonly)
Returns the value of attribute order.
3 4 5 |
# File 'app/services/workarea/cancel_order.rb', line 3 def order @order end |
#params ⇒ Object (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
#perform ⇒ Object
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 |
#refund ⇒ Object
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
14 15 16 |
# File 'app/services/workarea/cancel_order.rb', line 14 def refund? params[:refund].to_s =~ /true/i end |
#restock ⇒ Object
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
10 11 12 |
# File 'app/services/workarea/cancel_order.rb', line 10 def restock? params[:restock].to_s =~ /true/i end |
#update_fulfillment ⇒ Object
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
18 19 20 |
# File 'app/services/workarea/cancel_order.rb', line 18 def update_fulfillment? params[:fulfillment].to_s =~ /true/i end |