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



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

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

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

#planObject



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

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

#save!Object



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

def save!
  raise 'is invalid' unless valid?

  create_customer!
  create_stripe_token!
  save_subscription!
  true
end

#to_sObject



29
30
31
# File 'app/models/effective/subscripter.rb', line 29

def to_s
  'Your Plan'
end

#token_required?Boolean

Returns:

  • (Boolean)


57
58
59
# File 'app/models/effective/subscripter.rb', line 57

def token_required?
  customer.token_required?
end