Class: Effective::Subscripter
- Inherits:
-
Object
- Object
- Effective::Subscripter
- Includes:
- ActiveModel::Model
- Defined in:
- app/models/effective/subscripter.rb
Instance Attribute Summary collapse
-
#customer ⇒ Object
Returns the value of attribute customer.
-
#stripe_plan_id ⇒ Object
Returns the value of attribute stripe_plan_id.
-
#stripe_token ⇒ Object
Returns the value of attribute stripe_token.
-
#subscribable ⇒ Object
Returns the value of attribute subscribable.
-
#user ⇒ Object
Returns the value of attribute user.
Instance Method Summary collapse
- #current_plan ⇒ Object
- #destroy! ⇒ Object
- #plan ⇒ Object
- #reload! ⇒ Object
- #save! ⇒ Object
- #subscribe!(stripe_plan_id) ⇒ Object
- #token_required? ⇒ Boolean
Instance Attribute Details
#customer ⇒ Object
Returns the value of attribute customer.
7 8 9 |
# File 'app/models/effective/subscripter.rb', line 7 def customer @customer end |
#stripe_plan_id ⇒ Object
Returns the value of attribute stripe_plan_id.
8 9 10 |
# File 'app/models/effective/subscripter.rb', line 8 def stripe_plan_id @stripe_plan_id end |
#stripe_token ⇒ Object
Returns the value of attribute stripe_token.
8 9 10 |
# File 'app/models/effective/subscripter.rb', line 8 def stripe_token @stripe_token end |
#subscribable ⇒ Object
Returns the value of attribute subscribable.
7 8 9 |
# File 'app/models/effective/subscripter.rb', line 7 def subscribable @subscribable end |
#user ⇒ Object
Returns the value of attribute user.
7 8 9 |
# File 'app/models/effective/subscripter.rb', line 7 def user @user end |
Instance Method Details
#current_plan ⇒ Object
29 30 31 32 |
# File 'app/models/effective/subscripter.rb', line 29 def current_plan return nil unless subscribable subscribable.subscription.blank? ? EffectiveOrders.stripe_plans['trial'] : subscribable.subscription.plan end |
#destroy! ⇒ Object
62 63 64 65 66 67 68 69 70 71 |
# File 'app/models/effective/subscripter.rb', line 62 def destroy! return true unless subscription && subscription.persisted? && customer.stripe_subscription.present? raise 'is invalid' unless valid? subscription.destroy! customer.subscriptions.reload sync! && customer.save! end |
#plan ⇒ Object
34 35 36 |
# File 'app/models/effective/subscripter.rb', line 34 def plan EffectiveOrders.stripe_plans[stripe_plan_id] end |
#reload! ⇒ Object
73 74 75 76 77 78 |
# File 'app/models/effective/subscripter.rb', line 73 def reload! @stripe_token = nil @stripe_plan_id = nil @customer = nil @subscription = nil end |
#save! ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'app/models/effective/subscripter.rb', line 42 def save! return true if (plan == current_plan) && stripe_token.blank? # No work to do raise 'is invalid' unless valid? begin build! && sync! && customer.save! rescue => e reload! self.errors.add(:base, e.) raise e end end |
#subscribe!(stripe_plan_id) ⇒ Object
57 58 59 60 |
# File 'app/models/effective/subscripter.rb', line 57 def subscribe!(stripe_plan_id) self.stripe_plan_id = stripe_plan_id save! end |
#token_required? ⇒ Boolean
38 39 40 |
# File 'app/models/effective/subscripter.rb', line 38 def token_required? customer.token_required? end |