Module: Saucy::Account::InstanceMethods
- Defined in:
- lib/saucy/account.rb
Instance Method Summary collapse
- #can_change_plan_to?(new_plan) ⇒ Boolean
- #credit_card ⇒ Object
- #customer ⇒ Object
- #has_member?(user) ⇒ Boolean
- #memberships_by_name ⇒ Object
- #past_due? ⇒ Boolean
- #projects_by_name ⇒ Object
- #projects_visible_to(user) ⇒ Object
- #save_braintree!(attributes) ⇒ Object
- #subscription ⇒ Object
- #to_param ⇒ Object
- #users_by_name ⇒ Object
Instance Method Details
#can_change_plan_to?(new_plan) ⇒ Boolean
105 106 107 108 109 |
# File 'lib/saucy/account.rb', line 105 def can_change_plan_to?(new_plan) plan.limits.where(:value_type => :number).all? do |limit| new_plan.limit(limit.name).value >= send(limit.name).count end end |
#credit_card ⇒ Object
75 76 77 |
# File 'lib/saucy/account.rb', line 75 def credit_card customer.credit_cards[0] if customer && customer.credit_cards.any? end |
#customer ⇒ Object
71 72 73 |
# File 'lib/saucy/account.rb', line 71 def customer Braintree::Customer.find(customer_token) if customer_token end |
#has_member?(user) ⇒ Boolean
51 52 53 |
# File 'lib/saucy/account.rb', line 51 def has_member?(user) memberships.exists?(:user_id => user.id) end |
#memberships_by_name ⇒ Object
67 68 69 |
# File 'lib/saucy/account.rb', line 67 def memberships_by_name memberships.by_name end |
#past_due? ⇒ Boolean
111 112 113 |
# File 'lib/saucy/account.rb', line 111 def past_due? subscription_status == Braintree::Subscription::Status::PastDue end |
#projects_by_name ⇒ Object
59 60 61 |
# File 'lib/saucy/account.rb', line 59 def projects_by_name projects.by_name end |
#projects_visible_to(user) ⇒ Object
63 64 65 |
# File 'lib/saucy/account.rb', line 63 def projects_visible_to(user) projects.visible_to(user) end |
#save_braintree!(attributes) ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/saucy/account.rb', line 83 def save_braintree!(attributes) successful = true self.plan = ::Plan.find(attributes[:plan_id]) if attributes[:plan_id].present? if CUSTOMER_ATTRIBUTES.keys.any? { |attribute| attributes[attribute].present? } CUSTOMER_ATTRIBUTES.keys.each do |attribute| send("#{attribute}=", attributes[attribute]) if attributes[attribute].present? end result = Braintree::Customer.update(customer_token, customer_attributes) successful = result.success? handle_customer_result(result) end if successful && attributes[:plan_id].present? if subscription Braintree::Subscription.update(subscription_token, :plan_id => attributes[:plan_id]) else create_subscription end flush_cache :subscription end successful && save end |
#subscription ⇒ Object
79 80 81 |
# File 'lib/saucy/account.rb', line 79 def subscription Braintree::Subscription.find(subscription_token) if subscription_token end |
#to_param ⇒ Object
47 48 49 |
# File 'lib/saucy/account.rb', line 47 def to_param keyword end |
#users_by_name ⇒ Object
55 56 57 |
# File 'lib/saucy/account.rb', line 55 def users_by_name users.by_name end |