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.
7 8 9 10 |
# File 'app/services/workarea/cancel_order.rb', line 7 def initialize(order, params = {}) @order = order @params = params || {} end |
Instance Attribute Details
#order ⇒ Object (readonly)
Returns the value of attribute order.
5 6 7 |
# File 'app/services/workarea/cancel_order.rb', line 5 def order @order end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
5 6 7 |
# File 'app/services/workarea/cancel_order.rb', line 5 def params @params end |
Instance Method Details
#perform ⇒ Object
43 44 45 46 47 48 49 |
# File 'app/services/workarea/cancel_order.rb', line 43 def perform restock if restock? refund if refund? update_fulfillment if update_fulfillment? order.cancel end |
#refund ⇒ Object
29 30 31 32 33 |
# File 'app/services/workarea/cancel_order.rb', line 29 def refund result = Payment::Refund.new(payment: payment, amounts: refund_amounts) result.complete! result end |
#refund? ⇒ Boolean
16 17 18 |
# File 'app/services/workarea/cancel_order.rb', line 16 def refund? params[:refund].to_s =~ /true/i end |
#restock ⇒ Object
24 25 26 27 |
# File 'app/services/workarea/cancel_order.rb', line 24 def restock transaction = Inventory::Transaction.captured_for_order(order.id) transaction.rollback unless transaction.blank? end |
#restock? ⇒ Boolean
12 13 14 |
# File 'app/services/workarea/cancel_order.rb', line 12 def restock? params[:restock].to_s =~ /true/i end |
#update_fulfillment ⇒ Object
35 36 37 38 39 40 41 |
# File 'app/services/workarea/cancel_order.rb', line 35 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
20 21 22 |
# File 'app/services/workarea/cancel_order.rb', line 20 def update_fulfillment? params[:fulfillment].to_s =~ /true/i end |