Class: Effective::Subscripter

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Model
Defined in:
app/models/effective/subscripter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#include_trial ⇒ Object

Returns the value of attribute include_trial.



8
9
10
# File 'app/models/effective/subscripter.rb', line 8

def include_trial
  @include_trial
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

#subscribable_global_id ⇒ Object

Returns the value of attribute subscribable_global_id.



8
9
10
# File 'app/models/effective/subscripter.rb', line 8

def subscribable_global_id
  @subscribable_global_id
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



36
37
38
# File 'app/models/effective/subscripter.rb', line 36

def current_plan
  subscribable&.subscription&.plan
end

#destroy! ⇒ Object



64
65
66
67
68
69
70
71
# File 'app/models/effective/subscripter.rb', line 64

def destroy!
  return true unless plan

  subscribable.subscription.destroy!
  subscribable.update_column(:subscription_status, nil)
  sync_subscription!
  true
end

#plan ⇒ Object



40
41
42
# File 'app/models/effective/subscripter.rb', line 40

def plan
  EffectiveOrders.stripe_plans[stripe_plan_id]
end

#save! ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
# File 'app/models/effective/subscripter.rb', line 52

def save!
  return true if (plan == current_plan) && stripe_token.blank?  # No work to do

  raise 'is invalid' unless valid?

  create_customer!
  create_stripe_token!
  build_subscription!
  sync_subscription!
  true
end

#token_required? ⇒ Boolean

Returns:

  • (Boolean)


48
49
50
# File 'app/models/effective/subscripter.rb', line 48

def token_required?
  customer.token_required?
end

#user_id=(id) ⇒ Object



32
33
34
# File 'app/models/effective/subscripter.rb', line 32

def user_id=(id)
  @user = User.find(id)
end