module AT::Stripe::Customer
Constants
- REQUIRED_ACCESSORS
Public Class Methods
included(base)
click to toggle source
# File lib/at-stripe/customer.rb, line 8 def self.included(base) self.enforce_attributes(base) end
Private Class Methods
enforce_attributes(base)
click to toggle source
# File lib/at-stripe/customer.rb, line 65 def self.enforce_attributes(base) lookup = self.method_lookup(base) REQUIRED_ACCESSORS.each do |attribute| unless base.send(lookup, attribute) raise "receiving class must have \##{attribute}" end end end
method_lookup(base)
click to toggle source
# File lib/at-stripe/customer.rb, line 74 def self.method_lookup(base) # more stupid special cases coming soon key = base.superclass.to_s { 'ActiveRecord::Base' => :attribute_method? }.fetch(key, :public_method_defined?) end
Public Instance Methods
create_card(card_token)
click to toggle source
# File lib/at-stripe/customer.rb, line 28 def create_card(card_token) customer.sources.create(source: card_token) end
create_charge(options)
click to toggle source
# File lib/at-stripe/customer.rb, line 50 def create_charge(options) unless options.key?(:source) || options.key?(:customer) options[:customer] = self.stripe_id end ::Stripe::Charge.create(options) end
create_customer(options={})
click to toggle source
# File lib/at-stripe/customer.rb, line 14 def create_customer(options={}) options[:email] ||= self.email if @customer = ::Stripe::Customer.create(options) (self.stripe_id = @customer.id) and @customer end end
list_cards(limit=100)
click to toggle source
# File lib/at-stripe/customer.rb, line 44 def list_cards(limit=100) customer.sources.all(object: 'card', limit: limit) end
list_charges(limit=100)
click to toggle source
# File lib/at-stripe/customer.rb, line 57 def list_charges(limit=100) ::Stripe::Charge.all(customer: customer, limit: limit) end
purge_cards()
click to toggle source
# File lib/at-stripe/customer.rb, line 40 def purge_cards list_cards.map(&:delete) end
retrieve_card(card_token=nil)
click to toggle source
# File lib/at-stripe/customer.rb, line 32 def retrieve_card(card_token=nil) card_token ||= unless (card = list_cards.data.first).nil? card.id end return if card_token.nil? customer.sources.retrieve(card_token) end
retrieve_customer()
click to toggle source
# File lib/at-stripe/customer.rb, line 21 def retrieve_customer @customer ||= ::Stripe::Customer.retrieve(self.stripe_id) end
Also aliased as: customer