Class: StripeLocal::LineItem
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- StripeLocal::LineItem
- Includes:
- ObjectAdapter
- Defined in:
- app/models/stripe_local/line_item.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.create(attr_hash) ⇒ Object
19 20 21 |
# File 'app/models/stripe_local/line_item.rb', line 19 def create attr_hash super normalize( attr_hash ) end |
.normalize(attrs) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'app/models/stripe_local/line_item.rb', line 23 def normalize attrs attrs.each_with_object({}) do |(k,v),h| key = case k.to_sym when :invoice then :invoice_id when :plan then h[:plan_id] = ( v.nil? ? "" : v.id ) and next # will be nil if this is a one off charge when :metadata then h[:metadata] = MultiJson.dump( v.try :to_hash ) and next when :type then h[:subscription] = (v == "subscription" ? true : false) and next when :period then h[:period_start] = Time.at(v.start) and h[:period_end] = Time.at(v.end) and next when ->(x){attribute_method? x} then k.to_sym else next end h[key] = v end end |
Instance Method Details
#metadata ⇒ Object
14 15 16 |
# File 'app/models/stripe_local/line_item.rb', line 14 def MultiJson.load read_attribute( :metadata ), symbolize_keys: true end |