Module: Saucy::Subscription::InstanceMethods
- Defined in:
- lib/saucy/subscription.rb
Instance Method Summary collapse
- #billing_address ⇒ Object
- #can_change_plan_to?(new_plan) ⇒ Boolean
- #credit_card ⇒ Object
- #customer ⇒ Object
- #most_recent_transaction ⇒ Object
- #past_due? ⇒ Boolean
- #save_customer_and_subscription!(attributes) ⇒ Object
- #subscription ⇒ Object
Instance Method Details
#billing_address ⇒ Object
54 55 56 |
# File 'lib/saucy/subscription.rb', line 54 def billing_address credit_card.billing_address if credit_card end |
#can_change_plan_to?(new_plan) ⇒ Boolean
78 79 80 |
# File 'lib/saucy/subscription.rb', line 78 def can_change_plan_to?(new_plan) within_limits_for?(new_plan) && !past_trial_for?(new_plan) end |
#credit_card ⇒ Object
50 51 52 |
# File 'lib/saucy/subscription.rb', line 50 def credit_card customer.credit_cards[0] if customer && customer.credit_cards.any? end |
#customer ⇒ Object
46 47 48 |
# File 'lib/saucy/subscription.rb', line 46 def customer Braintree::Customer.find(customer_token) if customer_token end |
#most_recent_transaction ⇒ Object
86 87 88 |
# File 'lib/saucy/subscription.rb', line 86 def most_recent_transaction subscription.transactions.sort_by(&:created_at).last end |
#past_due? ⇒ Boolean
82 83 84 |
# File 'lib/saucy/subscription.rb', line 82 def past_due? subscription_status == Braintree::Subscription::Status::PastDue end |
#save_customer_and_subscription!(attributes) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/saucy/subscription.rb', line 62 def save_customer_and_subscription!(attributes) successful = true self.plan = ::Plan.find(attributes[:plan_id]) if changing_plan?(attributes) if changing_customer_attributes?(attributes) successful = update_customer(attributes) end if successful && past_due? successful = retry_subscription_charge! end if successful && changing_plan?(attributes) save_subscription flush_cache :subscription end successful && save end |
#subscription ⇒ Object
58 59 60 |
# File 'lib/saucy/subscription.rb', line 58 def subscription Braintree::Subscription.find(subscription_token) if subscription_token end |