Class: Tang::ImportPlansJob

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

def perform(starting_after = nil)
  # Do something later
  stripe_plans = Stripe::Plan.list(limit: 100, starting_after: starting_after)
  stripe_plans.each do |stripe_plan|
    Plan.find_or_create_by(stripe_id: stripe_plan.id) do |p|
      p.amount = stripe_plan.amount
      p.currency = stripe_plan.currency
      p.interval = stripe_plan.interval
      p.interval_count = stripe_plan.interval_count
      p.name = stripe_plan.name
      p.statement_descriptor = stripe_plan.statement_descriptor
      p.trial_period_days = stripe_plan.trial_period_days
    end
  end

  if stripe_plans.has_more
    Tang::ImportPlansJob.perform_now(stripe_plans.data.last.id)
  end
end