Class: Vindi::Plan

Inherits:
Model
  • Object
show all
Defined in:
lib/vindi/models/plan.rb

Overview

Plans

plan = Vindi::Plan.new.tap do |p|

p.name = "Monthly Plan"
p.description = "This plan will be renewed every month in the same day"
p.period = "monthly"
p.recurring = true
p.code = 1
p.plan_items = [
  {
    cycles: nil,
    product_id: 1
  }
]

end

plan = Vindi::Plan.new.tap do |p|

p.name = "Yearly Plan"
p.description = "This plan will be paid in 12 installments"
p.period = "yearly"
p.billing_cycles = 1
p.installments = 12
p.code = 1
p.plan_items = [
  {
    cycles: nil,
    product_id: 1
  }
]

end

Examples:

List active plans


plans = Vindi::Plan.active

Create a recurring plan


Create an yearly plan with installments


Instance Method Summary collapse

Methods inherited from Model

#archive!, first, last, #valid?

Instance Method Details

#period=(value) ⇒ Object



55
56
57
58
59
# File 'lib/vindi/models/plan.rb', line 55

def period=(value)
  raise "invalid period" unless %w[monthly quarterly biannually yearly].include? value.to_s

  send "set_#{value}"
end

#recurring=(value) ⇒ Object



51
52
53
# File 'lib/vindi/models/plan.rb', line 51

def recurring=(value)
  self.billing_cycles = value ? nil : 0
end