Class: StripeLocal::Invoice
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- StripeLocal::Invoice
- Includes:
- ObjectAdapter
- Defined in:
- app/models/stripe_local/invoice.rb
Class Method Summary collapse
- .create(object) ⇒ Object
- .fail(inv) ⇒ Object
- .normalize(attrs) ⇒ Object
- .paid ⇒ Object
- .succeed(inv) ⇒ Object
- .unpaid ⇒ Object (also: failed)
Class Method Details
.create(object) ⇒ Object
14 15 16 |
# File 'app/models/stripe_local/invoice.rb', line 14 def create object super normalize( object ) end |
.fail(inv) ⇒ Object
41 42 43 |
# File 'app/models/stripe_local/invoice.rb', line 41 def fail inv find( inv.id ).update_attributes paid: false end |
.normalize(attrs) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'app/models/stripe_local/invoice.rb', line 18 def normalize attrs attrs.each_with_object({}) do |(k,v),h| key = case k.to_sym when :customer then :customer_id when :charge then :charge_id when :lines then v.data.each do |item| StripeLocal::LineItem.create item.to_hash.merge({invoice_id: attrs.id}) end and next when ->(x){attribute_method? x} then k.to_sym else next end if v.is_a?(Numeric) && v > 1000000000 h[key] = Time.at( v ) else h[key] = v end end end |
.paid ⇒ Object
45 46 47 |
# File 'app/models/stripe_local/invoice.rb', line 45 def paid where paid: true end |
.succeed(inv) ⇒ Object
37 38 39 |
# File 'app/models/stripe_local/invoice.rb', line 37 def succeed inv find( inv.id ).update_attributes closed: true, paid: true, next_payment_attempt: nil end |
.unpaid ⇒ Object Also known as: failed
49 50 51 |
# File 'app/models/stripe_local/invoice.rb', line 49 def unpaid where paid: false end |