Class: Billy::Plan

Inherits:
ApplicationRecord show all
Defined in:
app/models/billy/plan.rb

Instance Method Summary collapse

Instance Method Details

#find_interval_planObject

Find a plan with the same name in the opposite interval This is useful when letting users upgrade to the yearly plan



42
43
44
45
46
47
48
# File 'app/models/billy/plan.rb', line 42

def find_interval_plan
  if interval == :month
    yearly.where(name: name).first
  else
    monthly.where(name: name).first
  end
end

#lemon_squeezy?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'app/models/billy/plan.rb', line 22

def lemon_squeezy?
  processor == "lemon_squeezy"
end

#lemon_squeezy_url(owner:) ⇒ Object

Generate a Lemon Squeezy URL with the passthrough details



27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/models/billy/plan.rb', line 27

def lemon_squeezy_url(owner:)
  return unless lemon_squeezy?

  url = "https://#{Billy.lemon_squeezy_site}.lemonsqueezy.com/checkout/buy/#{processor_extra}"
  url += "?embed=1"
  url += "&media=0"
  url += "&desc=0"
  url += "&checkout[email]=#{owner.email}"
  url += "&checkout[custom][passthrough]=#{owner..passthrough}"

  url
end

#monthly_versionObject



55
56
57
58
# File 'app/models/billy/plan.rb', line 55

def monthly_version
  return self if interval == "month"
  monthly.where(name: name).first
end

#paddle?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'app/models/billy/plan.rb', line 18

def paddle?
  processor == "paddle"
end

#yearly_versionObject



50
51
52
53
# File 'app/models/billy/plan.rb', line 50

def yearly_version
  return self if interval == "year"
  yearly.where(name: name).first
end