Class: KillBillClient::Model::Invoice

Inherits:
InvoiceAttributes show all
Defined in:
lib/killbill_client/models/invoice.rb

Constant Summary collapse

KILLBILL_API_INVOICES_PREFIX =
"#{KILLBILL_API_PREFIX}/invoices"

Constants inherited from Resource

Resource::KILLBILL_API_PAGINATION_PREFIX, Resource::KILLBILL_API_PREFIX

Instance Attribute Summary

Attributes inherited from Resource

#clazz, #etag, #response, #session_id, #uri

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Resource

#==, #_to_hash, attribute, create_alias, delete, extract_session_id, from_json, from_response, get, has_many, has_one, #hash, head, #initialize, instantiate_record_from_json, post, put, #refresh, #to_hash, #to_json

Constructor Details

This class inherits a constructor from KillBillClient::Model::Resource

Class Method Details

.as_html(invoice_id, options = {}) ⇒ Object



40
41
42
43
44
45
46
# File 'lib/killbill_client/models/invoice.rb', line 40

def as_html(invoice_id, options = {})
  get "#{KILLBILL_API_INVOICES_PREFIX}/#{invoice_id}/html",
      {},
      {
          :accept => 'text/html'
      }.merge(options)
end

.find_by_id_or_number(id_or_number, with_items = true, audit = "NONE", options = {}) ⇒ Object



13
14
15
16
17
18
19
20
# File 'lib/killbill_client/models/invoice.rb', line 13

def find_by_id_or_number(id_or_number, with_items = true, audit = "NONE", options = {})
  get "#{KILLBILL_API_INVOICES_PREFIX}/#{id_or_number}",
      {
          :withItems => with_items,
          :audit     => audit
      },
      options
end

.find_in_batches(offset = 0, limit = 100, options = {}) ⇒ Object



22
23
24
25
26
27
28
29
# File 'lib/killbill_client/models/invoice.rb', line 22

def find_in_batches(offset = 0, limit = 100, options = {})
  get "#{KILLBILL_API_INVOICES_PREFIX}/#{Resource::KILLBILL_API_PAGINATION_PREFIX}",
      {
          :offset => offset,
          :limit  => limit
      },
      options
end

.find_in_batches_by_search_key(search_key, offset = 0, limit = 100, options = {}) ⇒ Object



31
32
33
34
35
36
37
38
# File 'lib/killbill_client/models/invoice.rb', line 31

def find_in_batches_by_search_key(search_key, offset = 0, limit = 100, options = {})
  get "#{KILLBILL_API_INVOICES_PREFIX}/search/#{search_key}",
      {
          :offset => offset,
          :limit  => limit
      },
      options
end

.trigger_invoice(account_id, target_date, dry_run, user = nil, reason = nil, comment = nil, options = {}) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/killbill_client/models/invoice.rb', line 48

def trigger_invoice(, target_date, dry_run, user = nil, reason = nil, comment = nil, options = {})
  query_map              = {:accountId => }
  query_map[:targetDate] = target_date if !target_date.nil?
  query_map[:dryRun]     = dry_run if !dry_run.nil?

  begin
    res = post "#{KILLBILL_API_INVOICES_PREFIX}",
               {},
               query_map,
               {
                   :user    => user,
                   :reason  => reason,
                   :comment => comment,
               }.merge(options),
               Invoice

    res.refresh(options)

  rescue KillBillClient::API::BadRequest => e
    # No invoice to generate : TODO parse json to verify this is indeed the case
  end
end

Instance Method Details

#payments(with_plugin_info = false, audit = 'NONE', options = {}) ⇒ Object



72
73
74
75
76
77
78
79
80
# File 'lib/killbill_client/models/invoice.rb', line 72

def payments(with_plugin_info = false, audit = 'NONE', options = {})
  self.class.get "#{KILLBILL_API_INVOICES_PREFIX}/#{invoice_id}/payments",
                 {
                     :withPluginInfo => with_plugin_info,
                     :audit          => audit
                 },
                 options,
                 InvoicePayment
end