lib/recurly/invoice.rb in recurly-0.4.16 vs lib/recurly/invoice.rb in recurly-2.0.0
- old
+ new
@@ -1,24 +1,46 @@
module Recurly
- class Invoice < Base
- self.element_name = "invoice"
- self.prefix = "/accounts/:account_code/"
+ # Invoices are created through account objects.
+ #
+ # @example
+ # account = Account.find account_code
+ # account.invoice!
+ class Invoice < Resource
+ # @macro [attach] scope
+ # @scope class
+ # @return [Pager<Invoice>] A pager that yields +$1+ invoices.
+ scope :open, :state => :open
+ scope :collected, :state => :collected
+ scope :failed, :state => :failed
+ scope :past_due, :state => :past_due
- def self.list(account_code)
- find(:all, :params => { :account_code => account_code })
- end
+ # @return [Account]
+ belongs_to :account
- def self.lookup(account_code, id)
- find(id, :params => { :account_code => account_code })
- end
+ define_attribute_methods %w(
+ uuid
+ state
+ invoice_number
+ po_number
+ vat_number
+ subtotal_in_cents
+ tax_in_cents
+ total_in_cents
+ currency
+ created_at
+ line_items
+ transactions
+ )
+ alias to_param uuid
- def self.element_path(id, prefix_options = {}, query_options = nil)
- path = super
+ private
- # postprocess generated element url.
- # changes /accounts/:account_code/invoices/:id to /invoices/:id
- # this breaks update, however I dont believe recurly allows invoice updates anyways
- path.sub("/accounts/#{CGI::escape(prefix_options[:account_code].to_s)}/invoices/", "/invoices/")
+ def initialize attributes = {}
+ super({ :currency => Recurly.default_currency }.merge attributes)
end
+ # Invoices are only writeable through {Account} instances.
+ embedded!
+ undef save
+ undef destroy
end
-end
\ No newline at end of file
+end