Class: Billy::Account
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Billy::Account
- Defined in:
- app/models/billy/account.rb
Instance Method Summary collapse
- #deleted? ⇒ Boolean
-
#discord(kind:, desc: nil) ⇒ Object
Send a Discord event for this Account.
- #free? ⇒ Boolean
-
#lemon_squeezy? ⇒ Boolean
Lemon Squeezy accounts.
-
#make_default! ⇒ Object
Makes this the default Account.
-
#migrated? ⇒ Boolean
Migrated accounts - from old payment processors.
-
#paddle? ⇒ Boolean
Paddle accounts - the main usage of this library.
-
#passthrough ⇒ Object
Generates a GlobalID for the Account owner.
-
#subscribe(plan:, **options) ⇒ Object
Create a Subscription for this Account subscribe(plan: Billy::Plan.first, trial_ends_at: 14.days.from_now, ends_at: 14.days.from_now).
-
#trial? ⇒ Boolean
Trial accounts - e.g.
Instance Method Details
#deleted? ⇒ Boolean
64 65 66 |
# File 'app/models/billy/account.rb', line 64 def deleted? deleted_at.present? end |
#discord(kind:, desc: nil) ⇒ Object
Send a Discord event for this Account
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'app/models/billy/account.rb', line 89 def discord(kind:, desc: nil) return if Billy.discord_path.nil? case kind when :new_account Billy::DiscordJob.perform_now title: "π New Account", description: ["Account: #{owner.name}", desc].join("\n") when :payment_succeeded Billy::DiscordJob.perform_now title: "πΈ Payment Succeeded", description: "Account: #{owner.name}\n#{desc}" when :subscription_created Billy::DiscordJob.perform_now title: "π° Subscription Created", description: "Account: #{owner.name}\n#{desc}" when :subscription_cancelled Billy::DiscordJob.perform_now title: "π« Subscription Cancelled", description: "Account: #{owner.name}" when :subscription_paused Billy::DiscordJob.perform_now title: "βΈοΈ Subscription Paused", description: "Account: #{owner.name}" end end |
#free? ⇒ Boolean
20 21 22 |
# File 'app/models/billy/account.rb', line 20 def free? processor == "free" end |
#lemon_squeezy? ⇒ Boolean
Lemon Squeezy accounts
35 36 37 |
# File 'app/models/billy/account.rb', line 35 def lemon_squeezy? processor == "lemon_squeezy" end |
#make_default! ⇒ Object
Makes this the default Account
47 48 49 50 51 52 |
# File 'app/models/billy/account.rb', line 47 def make_default! return if default? owner.billy_accounts.update_all(default: false) update!(default: true) end |
#migrated? ⇒ Boolean
Migrated accounts - from old payment processors
40 41 42 |
# File 'app/models/billy/account.rb', line 40 def migrated? processor == "migrated" end |
#paddle? ⇒ Boolean
Paddle accounts - the main usage of this library
30 31 32 |
# File 'app/models/billy/account.rb', line 30 def paddle? processor == "paddle" end |
#passthrough ⇒ Object
Generates a GlobalID for the Account owner
70 71 72 |
# File 'app/models/billy/account.rb', line 70 def passthrough owner.to_sgid.to_s end |
#subscribe(plan:, **options) ⇒ Object
Create a Subscription for this Account subscribe(plan: Billy::Plan.first, trial_ends_at: 14.days.from_now, ends_at: 14.days.from_now)
77 78 79 80 81 82 83 84 85 86 |
# File 'app/models/billy/account.rb', line 77 def subscribe(plan:, **) attributes = .merge( processor: processor, status: "active", plan: plan, default: true ) subscriptions.create!(attributes) end |
#trial? ⇒ Boolean
Trial accounts - e.g. 14 day trials
25 26 27 |
# File 'app/models/billy/account.rb', line 25 def trial? processor == "trial" end |