Class: Tang::ImportInvoicesJob

Inherits:
ActiveJob::Base
  • Object
show all
Defined in:
app/jobs/tang/import_invoices_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
# File 'app/jobs/tang/import_invoices_job.rb', line 5

def perform(starting_after = nil)
  # Do something later
  stripe_invoices = Stripe::Invoice.list(limit: 100, starting_after: starting_after)
  stripe_invoices.each do |stripe_invoice|
    invoice = Invoice.from_stripe(stripe_invoice)
    if invoice.present?
      stripe_invoice.lines.data.each do |stripe_invoice_item|
        InvoiceItem.from_stripe(stripe_invoice_item, invoice)
      end
    end
  end

  if stripe_invoices.has_more
    Tang::ImportInvoicesJob.perform_now(stripe_invoices.data.last.id)
  end
end