class ChartMogul::Invoice
Public Class Methods
all(options = {})
click to toggle source
# File lib/chartmogul/invoice.rb, line 31 def self.all(options = {}) Invoices.all(options) end
Public Instance Methods
serialize_line_items()
click to toggle source
# File lib/chartmogul/invoice.rb, line 23 def serialize_line_items line_items.map(&:serialize_for_write) end
serialize_transactions()
click to toggle source
# File lib/chartmogul/invoice.rb, line 27 def serialize_transactions transactions.map(&:serialize_for_write) end
Private Instance Methods
line_item_class(type)
click to toggle source
# File lib/chartmogul/invoice.rb, line 63 def line_item_class(type) case type when 'subscription' then ChartMogul::LineItems::Subscription when 'one_time' then ChartMogul::LineItems::OneTime end end
set_line_items(line_items_attributes)
click to toggle source
# File lib/chartmogul/invoice.rb, line 37 def set_line_items(line_items_attributes) @line_items = line_items_attributes.map.with_index do |line_item_attributes, index| existing_line_item = line_items[index] if existing_line_item existing_line_item.assign_all_attributes(line_item_attributes) else line_item_class(line_item_attributes[:type]) .new_from_json(line_item_attributes.merge(invoice_uuid: uuid)) end end end
set_transactions(transactions_attributes)
click to toggle source
# File lib/chartmogul/invoice.rb, line 50 def set_transactions(transactions_attributes) @transactions = transactions_attributes.map.with_index do |transaction_attributes, index| existing_transaction = transactions[index] if existing_transaction existing_transaction.assign_all_attributes(transaction_attributes) else transaction_class(transaction_attributes[:type]) .new_from_json(transaction_attributes.merge(invoice_uuid: uuid)) end end end
transaction_class(type)
click to toggle source
# File lib/chartmogul/invoice.rb, line 70 def transaction_class(type) case type when 'payment' then ChartMogul::Transactions::Payment when 'refund' then ChartMogul::Transactions::Refund end end