Class: Wbase::Subscription
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Wbase::Subscription
- Defined in:
- app/models/wbase/subscription.rb
Class Method Summary collapse
Instance Method Summary collapse
- #current? ⇒ Boolean
- #monthly_value ⇒ Object
- #stripe_customer ⇒ Object
- #trial? ⇒ Boolean
- #trial_days_left ⇒ Object
- #update_paid_thru! ⇒ Object
Class Method Details
.current ⇒ Object
30 31 32 |
# File 'app/models/wbase/subscription.rb', line 30 def self.current where('paid_thru > ?', 7.days.ago) end |
Instance Method Details
#current? ⇒ Boolean
61 62 63 |
# File 'app/models/wbase/subscription.rb', line 61 def current? paid_thru && paid_thru > 7.days.ago end |
#monthly_value ⇒ Object
43 44 45 46 47 48 49 |
# File 'app/models/wbase/subscription.rb', line 43 def monthly_value if plan.interval.include?("month") current_price else current_price.fdiv(12) end end |
#stripe_customer ⇒ Object
34 35 36 |
# File 'app/models/wbase/subscription.rb', line 34 def stripe_customer @stripe_customer ||= Stripe::Customer.retrieve(stripe_id) end |
#trial? ⇒ Boolean
65 66 67 |
# File 'app/models/wbase/subscription.rb', line 65 def trial? created_at > 14.days.ago end |
#trial_days_left ⇒ Object
69 70 71 72 |
# File 'app/models/wbase/subscription.rb', line 69 def trial_days_left return 0 unless trial? (conversion_day.to_date - Date.current.to_date).to_i end |
#update_paid_thru! ⇒ Object
51 52 53 54 55 56 57 58 59 |
# File 'app/models/wbase/subscription.rb', line 51 def update_paid_thru! if stripe_customer && stripe_customer.try(:subscriptions).try(:first) remote_paid_thru = Time.at(stripe_customer.subscriptions.first.try(:current_period_end)) if remote_paid_thru > paid_thru return self.update(paid_thru: remote_paid_thru) end end false end |