Class: StripeLocal::Customer

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
ObjectAdapter
Defined in:
app/models/stripe_local/customer.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.create(params) ⇒ Object



30
31
32
# File 'app/models/stripe_local/customer.rb', line 30

def create params
  super normalize params
end

.create_each_card(ary) ⇒ Object



47
48
49
50
51
# File 'app/models/stripe_local/customer.rb', line 47

def create_each_card ary
  ary.each do |card|
    StripeLocal::Card.create( card.to_hash )
  end
end

.create_subscription(object) ⇒ Object



53
54
55
# File 'app/models/stripe_local/customer.rb', line 53

def create_subscription object
  StripeLocal::Subscription.create( object.to_hash ) unless object.nil?
end

.normalize(params) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
# File 'app/models/stripe_local/customer.rb', line 34

def normalize params
  params.each_with_object({}) do |(k,v),h|
    key = case k.to_sym
    when :cards        then create_each_card( v.data ) and next
    when :subscription then create_subscription( v )   and next
    when :metadata     then h[:metadata] = MultiJson.dump( v.to_hash ) and next
    when ->(x){attribute_method? x} then k.to_sym
    else next
    end
    h[key] = v
  end
end

Instance Method Details

#metadataObject



58
59
60
# File 'app/models/stripe_local/customer.rb', line 58

def 
  MultiJson.load read_attribute( :metadata ), symbolize_keys: true
end