Class: Worker::Capture

Inherits:
Base
  • Object
show all
Defined in:
lib/spree_batch_capture/worker/capture.rb

Class Method Summary collapse

Class Method Details

.before_run(options) ⇒ Object



33
34
35
# File 'lib/spree_batch_capture/worker/capture.rb', line 33

def self.before_run(options)
  options[:order] = Order.find(options[:order_id])
end

.default_queue_nameObject



41
42
43
# File 'lib/spree_batch_capture/worker/capture.rb', line 41

def self.default_queue_name
  return "capture"
end

.run(options) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/spree_batch_capture/worker/capture.rb', line 4

def self.run(options)
  order = options[:order]

  return true unless order.payment_state == "balance_due"

  if order.payments.nil? || ( order.payments && order.payments.empty? )
    raise Error::UnexpectedWorkerError.new "Attempted to capture an order without any payments."
  else 

    order.payments.each do |payment|
      payment_source = payment.source
      if payment_source.can_capture? payment
        begin
          payment_source.capture(payment)
        rescue => e
          payment.fail
          log_payment_error payment, "Error capturing payment for order #{order.number}. #{e.class} :: #{e.message}"
        end

      else
        log_payment_error payment, "Order #{order.number} is not eligible for capture with payment #{payment.source_type} for #{payment.amount}."
      end
    end
  end

  return true

end

.worker_klass_nameObject



37
38
39
# File 'lib/spree_batch_capture/worker/capture.rb', line 37

def self.worker_klass_name
  return "Capture"
end