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

#current_userObject

Returns the value of attribute current_user.



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

def current_user
  @current_user
end

#customerObject

Returns the value of attribute customer.



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

def customer
  @customer
end

#quantityObject

Returns the value of attribute quantity.



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

def quantity
  @quantity
end

#stripe_plan_idObject

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_tokenObject

Returns the value of attribute stripe_token.



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

def stripe_token
  @stripe_token
end

#subscribableObject

Returns the value of attribute subscribable.



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

def subscribable
  @subscribable
end

#subscribable_global_idObject

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

#userObject

Returns the value of attribute user.



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

def user
  @user
end

Instance Method Details

#destroy!Object



68
69
70
71
72
73
74
75
# File 'app/models/effective/subscripter.rb', line 68

def destroy!
  subscription = subscribable.subscription
  return true if subscription.blank?

  Rails.logger.info " -> [STRIPE] delete subscription"
  subscription.stripe_subscription.delete
  subscription.destroy!
end

#planObject



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

def plan
  EffectiveOrders.stripe_plans.find { |plan| plan[:id] == stripe_plan_id }
end

#save!Object



59
60
61
62
63
64
65
66
# File 'app/models/effective/subscripter.rb', line 59

def save!
  raise 'is invalid' unless valid?

  create_customer!
  create_stripe_token!
  save_subscription!
  true
end

#to_sObject



27
28
29
# File 'app/models/effective/subscripter.rb', line 27

def to_s
  'Your Plan'
end

#token_required?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'app/models/effective/subscripter.rb', line 55

def token_required?
  customer.token_required?
end