Class: Effective::Customer
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Effective::Customer
- Defined in:
- app/models/effective/customer.rb
Instance Attribute Summary collapse
-
#token ⇒ Object
This is a convenience method so we have a place to store StripeConnect temporary access tokens.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#token ⇒ Object
This is a convenience method so we have a place to store StripeConnect temporary access tokens
5 6 7 |
# File 'app/models/effective/customer.rb', line 5 def token @token end |
Class Method Details
Instance Method Details
#is_stripe_connect_seller? ⇒ Boolean
60 61 62 |
# File 'app/models/effective/customer.rb', line 60 def is_stripe_connect_seller? stripe_connect_access_token.present? end |
#stripe_customer ⇒ Object
31 32 33 34 35 36 37 38 39 |
# File 'app/models/effective/customer.rb', line 31 def stripe_customer @stripe_customer ||= if stripe_customer_id.present? ::Stripe::Customer.retrieve(stripe_customer_id) else ::Stripe::Customer.create(:email => user.email, :description => user.id.to_s).tap do |stripe_customer| self.update_attributes(:stripe_customer_id => stripe_customer.id) end end end |
#update_card!(token) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'app/models/effective/customer.rb', line 41 def update_card!(token) if token.present? # Oh, so they want to use a new credit card... if stripe_customer.respond_to?(:cards) stripe_customer.card = token # This sets the default_card to the new card elsif stripe_customer.respond_to?(:sources) stripe_customer.source = token end if stripe_customer.save && default_card.present? card = cards.retrieve(default_card) self.stripe_active_card = "**** **** **** #{card.last4} #{card.brand} #{card.exp_month}/#{card.exp_year}" self.save! else raise Exception.new('unable to update stripe customer with new card') end end end |