Class: Tang::ImportChargesJob

Inherits:
ActiveJob::Base
  • Object
show all
Defined in:
app/jobs/tang/import_charges_job.rb

Instance Method Summary collapse

Instance Method Details

#perform(starting_after = nil) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'app/jobs/tang/import_charges_job.rb', line 5

def perform(starting_after = nil)
  # Do something later
  stripe_charges = Stripe::Charge.list(limit: 100, starting_after: starting_after)
  stripe_charges.each do |stripe_charge|

    invoice = Invoice.find_by(stripe_id: stripe_charge.invoice)

    if invoice.present?
      Charge.from_stripe(stripe_charge, invoice)
    end

  end

  if stripe_charges.has_more
    Tang::ImportChargesJob.perform_now(stripe_charges.data.last.id)
  end
end