Class: PaidUp::Plan

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/paid_up/plan.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#stripe_dataObject

Returns the value of attribute stripe_data.



6
7
8
# File 'app/models/paid_up/plan.rb', line 6

def stripe_data
  @stripe_data
end

Instance Method Details

#amountObject



61
62
63
64
65
66
67
# File 'app/models/paid_up/plan.rb', line 61

def amount
  if stripe_data.present?
    stripe_data.amount
  else
    0
  end
end

#chargeObject



73
74
75
# File 'app/models/paid_up/plan.rb', line 73

def charge
  money.amount
end

#currencyObject



77
78
79
80
81
82
83
# File 'app/models/paid_up/plan.rb', line 77

def currency
  if stripe_data.present?
    stripe_data.currency.upcase
  else
    :default_currency.l.upcase
  end
end

#feature_setting(feature_name) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'app/models/paid_up/plan.rb', line 20

def feature_setting(feature_name)
  feature = PaidUp::Feature.find_by_slug(feature_name) || raise(:feature_not_found.l)
  raw = plan_feature_settings.where(feature: feature_name)
  case feature.setting_type
    when 'boolean'
      if raw.empty?
        false
      else
        raw.first.setting != 0
      end
    when 'table_rows', 'rolify_rows'
      if raw.empty?
        0
      else
        raw.first.setting
      end
    else
      raise :error_handling_feature_setting.l feature: feature
  end
end

#feature_unlimited?(feature_name) ⇒ Boolean

Returns:

  • (Boolean)


41
42
43
# File 'app/models/paid_up/plan.rb', line 41

def feature_unlimited?(feature_name)
  feature_setting(feature_name) == PaidUp::Unlimited.to_i
end

#intervalObject



45
46
47
48
49
50
51
# File 'app/models/paid_up/plan.rb', line 45

def interval
  if stripe_data.present?
    stripe_data.interval
  else
    :default_interval.l
  end
end

#interval_countObject



53
54
55
56
57
58
59
# File 'app/models/paid_up/plan.rb', line 53

def interval_count
  if stripe_data.present?
    stripe_data.interval_count
  else
    1
  end
end

#moneyObject



69
70
71
# File 'app/models/paid_up/plan.rb', line 69

def money
  Money.new(amount, currency)
end

#reload(*args, &blk) ⇒ Object



14
15
16
17
18
# File 'app/models/paid_up/plan.rb', line 14

def reload(*args, &blk)
  super *args, &blk
  load_stripe_data
  self
end