module StripeLocal class Invoice < ActiveRecord::Base include ObjectAdapter has_many :lines, inverse_of: :invoice, class_name: "LineItem" belongs_to :charge, inverse_of: :invoice belongs_to :customer, inverse_of: :invoices self.primary_key = :id time_writer :date, :period_start, :period_end, :next_payment_attempt class<(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 def succeed inv find( inv.id ).update_attributes closed: true, paid: true, next_payment_attempt: nil end def fail inv find( inv.id ).update_attributes paid: false end def paid where paid: true end def unpaid where paid: false end alias :failed :unpaid end end #=!=# # ==Database Schema # # string :id # string :customer_id # integer :amount_due # integer :subtotal # integer :total # boolean :attempted # integer :attempt_count # boolean :paid # boolean :closed # datetime :date # datetime :period_start # datetime :period_end # string :currency # integer :starting_balance # integer :ending_balance # string :charge_id # integer :discount # datetime :next_payment_attempt #=ยก=# end