Class: Spree::OrderCapturing

Inherits:
Object
  • Object
show all
Defined in:
app/models/spree/order_capturing.rb

Instance Method Summary collapse

Constructor Details

#initialize(order, sorted_payment_method_classes = nil) ⇒ OrderCapturing

Returns a new instance of OrderCapturing.



15
16
17
18
19
20
# File 'app/models/spree/order_capturing.rb', line 15

def initialize(order, sorted_payment_method_classes = nil)
  Spree::Deprecation.warn "Spree::OrderCapturing is deprecated and will be removed without replacement. " \
    "Please implement your own automated capturing logic in your store."
  @order = order
  @sorted_payment_method_classes = sorted_payment_method_classes || Spree::OrderCapturing.sorted_payment_method_classes
end

Instance Method Details

#capture_paymentsObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'app/models/spree/order_capturing.rb', line 22

def capture_payments
  return if @order.paid?

  Spree::OrderMutex.with_lock!(@order) do
    uncaptured_amount = @order.display_total.cents

    sorted_payments(@order).each do |payment|
      amount = [uncaptured_amount, payment.money.cents].min

      if amount > 0
        payment.capture!(amount)
        uncaptured_amount -= amount
      elsif Spree::OrderCapturing.void_unused_payments
        payment.void_transaction!
      end
    end
  end
end