Class: Returnly::Refunder
- Inherits:
-
Object
- Object
- Returnly::Refunder
- Includes:
- RefundsConfiguration
- Defined in:
- lib/returnly/refunder.rb
Instance Attribute Summary collapse
-
#customer_return ⇒ Object
Returns the value of attribute customer_return.
-
#line_items ⇒ Object
Returns the value of attribute line_items.
-
#order ⇒ Object
Returns the value of attribute order.
-
#product_refund_amount ⇒ Object
Returns the value of attribute product_refund_amount.
-
#refund_calculator ⇒ Object
Returns the value of attribute refund_calculator.
-
#return_item_amount_calculator ⇒ Object
Returns the value of attribute return_item_amount_calculator.
-
#return_item_restock_policy ⇒ Object
Returns the value of attribute return_item_restock_policy.
-
#shipping_refund_amount ⇒ Object
Returns the value of attribute shipping_refund_amount.
Instance Method Summary collapse
-
#initialize(order:, line_items:, product_refund_amount:, shipping_refund_amount:) ⇒ Refunder
constructor
A new instance of Refunder.
- #proceed! ⇒ Object
- #process_return_items ⇒ Object
- #product_available_amount ⇒ Object
- #refund_available_amount ⇒ Object
- #reimbursement ⇒ Object
Methods included from RefundsConfiguration
#gift_card_class, #gift_card_estimate_class, #refund_calculator_class, #refund_presenter_class, #refunder_class, #return_item_amount_calculator_class, #return_item_builder_class, #return_item_restock_policy_class
Constructor Details
#initialize(order:, line_items:, product_refund_amount:, shipping_refund_amount:) ⇒ Refunder
Returns a new instance of Refunder.
14 15 16 17 18 19 20 21 |
# File 'lib/returnly/refunder.rb', line 14 def initialize(order:, line_items:, product_refund_amount:, shipping_refund_amount:) self.order = order self.line_items = line_items self.product_refund_amount = product_refund_amount self.shipping_refund_amount = shipping_refund_amount configure end |
Instance Attribute Details
#customer_return ⇒ Object
Returns the value of attribute customer_return.
5 6 7 |
# File 'lib/returnly/refunder.rb', line 5 def customer_return @customer_return end |
#line_items ⇒ Object
Returns the value of attribute line_items.
5 6 7 |
# File 'lib/returnly/refunder.rb', line 5 def line_items @line_items end |
#order ⇒ Object
Returns the value of attribute order.
5 6 7 |
# File 'lib/returnly/refunder.rb', line 5 def order @order end |
#product_refund_amount ⇒ Object
Returns the value of attribute product_refund_amount.
5 6 7 |
# File 'lib/returnly/refunder.rb', line 5 def product_refund_amount @product_refund_amount end |
#refund_calculator ⇒ Object
Returns the value of attribute refund_calculator.
5 6 7 |
# File 'lib/returnly/refunder.rb', line 5 def refund_calculator @refund_calculator end |
#return_item_amount_calculator ⇒ Object
Returns the value of attribute return_item_amount_calculator.
5 6 7 |
# File 'lib/returnly/refunder.rb', line 5 def return_item_amount_calculator @return_item_amount_calculator end |
#return_item_restock_policy ⇒ Object
Returns the value of attribute return_item_restock_policy.
5 6 7 |
# File 'lib/returnly/refunder.rb', line 5 def return_item_restock_policy @return_item_restock_policy end |
#shipping_refund_amount ⇒ Object
Returns the value of attribute shipping_refund_amount.
5 6 7 |
# File 'lib/returnly/refunder.rb', line 5 def shipping_refund_amount @shipping_refund_amount end |
Instance Method Details
#proceed! ⇒ Object
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/returnly/refunder.rb', line 31 def proceed! return proceed_without_line_items if line_items.empty? return proceed_with_product_zero_amount if product_refund_amount.to_d.zero? process_return_items if customer_return.save! perform_reimbursement RefundPresenter.present_refund(self) end end |
#process_return_items ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/returnly/refunder.rb', line 23 def process_return_items each_return_item do |return_item| return_item.amount = return_item_amount_calculator.return_item_refund_amount return_item return_item.additional_tax_total = 0 return_item.resellable = return_item_restock_policy.should_return_item? return_item end end |
#product_available_amount ⇒ Object
50 51 52 53 |
# File 'lib/returnly/refunder.rb', line 50 def product_available_amount total = order.total - (order.shipment_total + refund_calculator.shipping_tax + refunds) [total, product_refund_amount.to_d].min end |
#refund_available_amount ⇒ Object
42 43 44 |
# File 'lib/returnly/refunder.rb', line 42 def refund_available_amount @available_amount ||= Money.from_amount(product_available_amount) end |
#reimbursement ⇒ Object
46 47 48 |
# File 'lib/returnly/refunder.rb', line 46 def reimbursement @_reimbursement ||= Spree::Reimbursement.build_from_customer_return(customer_return) end |