Class: KillBillClient::Model::Invoice

Inherits:
InvoiceAttributes show all
Includes:
AuditLogWithHistoryHelper, CustomFieldHelper, TagHelper
Defined in:
lib/killbill_client/models/invoice.rb

Constant Summary collapse

KILLBILL_API_INVOICES_PREFIX =
"#{KILLBILL_API_PREFIX}/invoices"
KILLBILL_API_DRY_RUN_INVOICES_PREFIX =
"#{KILLBILL_API_INVOICES_PREFIX}/dryRun"

Constants included from TagHelper

TagHelper::AUTO_INVOICING_OFF_ID, TagHelper::AUTO_PAY_OFF_ID, TagHelper::MANUAL_PAY_ID, TagHelper::OVERDUE_ENFORCEMENT_OFF_ID, TagHelper::TEST_ID, TagHelper::WRITTEN_OFF_ID

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 included from AuditLogWithHistoryHelper

included

Methods included from TagHelper

#add_tag, #add_tag_from_definition_id, #control_tag?, included, #remove_tag, #remove_tag_from_definition_id, #set_tags

Methods included from CustomFieldHelper

included

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, require_multi_tenant_options!, #to_hash, #to_json

Constructor Details

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

Class Method Details

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



67
68
69
70
71
72
73
# File 'lib/killbill_client/models/invoice.rb', line 67

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

.cancel_subscription_dry_run(account_id, bundle_id, subscription_id, target_date, effective_date, billing_policy, options = {}) ⇒ Object



183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
# File 'lib/killbill_client/models/invoice.rb', line 183

def cancel_subscription_dry_run(, bundle_id, subscription_id, target_date,
                                effective_date, billing_policy,  options = {})
  query_map              = {:accountId => }
  query_map[:targetDate] = target_date if !target_date.nil?

  dry_run = InvoiceDryRunAttributes.new
  dry_run.dry_run_type = 'SUBSCRIPTION_ACTION'
  dry_run.dry_run_action = 'STOP_BILLING'
  dry_run.effective_date = effective_date
  dry_run.billing_policy = billing_policy
  dry_run.bundle_id = bundle_id
  dry_run.subscription_id = subscription_id


  res = post "#{KILLBILL_API_DRY_RUN_INVOICES_PREFIX}",
             dry_run.to_json,
             query_map,
             {
                 :user    => 'cancel_subscription_dry_run',
                 :reason  => '',
                 :comment => '',
             }.merge(options),
             Invoice

  nothing_to_generate?(res) ? nil : res.refresh(options)

end

.change_plan_dry_run(account_id, bundle_id, subscription_id, target_date, product_name, product_category, billing_period, price_list_name, effective_date, billing_policy, options = {}) ⇒ Object



150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
# File 'lib/killbill_client/models/invoice.rb', line 150

def change_plan_dry_run(, bundle_id, subscription_id, target_date, product_name, product_category, billing_period, price_list_name,
                        effective_date, billing_policy, options = {})
  query_map              = {:accountId => }
  query_map[:targetDate] = target_date if !target_date.nil?

  dry_run = InvoiceDryRunAttributes.new
  dry_run.dry_run_type = 'SUBSCRIPTION_ACTION'
  dry_run.dry_run_action = 'CHANGE'
  dry_run.product_name = product_name
  dry_run.product_category = product_category
  dry_run.billing_period = billing_period
  dry_run.price_list_name = price_list_name
  dry_run.effective_date = effective_date
  dry_run.billing_policy = billing_policy
  dry_run.bundle_id = bundle_id
  dry_run.subscription_id = subscription_id


  res = post "#{KILLBILL_API_DRY_RUN_INVOICES_PREFIX}",
             dry_run.to_json,
             query_map,
             {
                 :user    => 'change_plan_dry_run',
                 :reason  => '',
                 :comment => '',
             }.merge(options),
             Invoice

  nothing_to_generate?(res) ? nil : res.refresh(options)

end

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



310
311
312
313
314
315
316
317
318
319
320
321
322
# File 'lib/killbill_client/models/invoice.rb', line 310

def create_migration_invoice(, invoices, target_date, user = nil, reason = nil, comment = nil, options = {})

  params = {}
  params[:targetDate] = target_date
  post "#{KILLBILL_API_INVOICES_PREFIX}/migration/#{}",
       invoices.to_json,
       params,
       {
           :user    => user,
           :reason  => reason,
           :comment => comment,
       }.merge(options)
end

.create_subscription_dry_run(account_id, bundle_id, target_date, product_name, product_category, billing_period, price_list_name, options = {}) ⇒ Object



122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/killbill_client/models/invoice.rb', line 122

def create_subscription_dry_run(, bundle_id, target_date, product_name, product_category,
                                billing_period, price_list_name,  options = {})
  query_map              = {:accountId => }
  query_map[:targetDate] = target_date if !target_date.nil?

  dry_run = InvoiceDryRunAttributes.new
  dry_run.dry_run_type = 'SUBSCRIPTION_ACTION'
  dry_run.dry_run_action = 'START_BILLING'
  dry_run.product_name = product_name
  dry_run.product_category = product_category
  dry_run.billing_period = billing_period
  dry_run.price_list_name = price_list_name
  dry_run.bundle_id = bundle_id

  res = post "#{KILLBILL_API_DRY_RUN_INVOICES_PREFIX}",
             dry_run.to_json,
             query_map,
             {
                 :user    => 'create_subscription_dry_run',
                 :reason  => '',
                 :comment => '',
             }.merge(options),
             Invoice

  nothing_to_generate?(res) ? nil : res.refresh(options)

end

.find_by_id(invoice_id, with_children_items = false, audit = "NONE", options = {}) ⇒ Object



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

def find_by_id(invoice_id, with_children_items = false, audit = "NONE", options = {})
  get "#{KILLBILL_API_INVOICES_PREFIX}/#{invoice_id}",
      {
          :withChildrenItems => with_children_items,
          :audit     => audit
      },
      options
end

.find_by_invoice_item_id(invoice_item_id, with_children_items = false, audit = "NONE", options = {}) ⇒ Object



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

def find_by_invoice_item_id(invoice_item_id, with_children_items = false, audit = "NONE", options = {})
  get "#{KILLBILL_API_INVOICES_PREFIX}/byItemId/#{invoice_item_id}",
      {
          :withChildrenItems => with_children_items,
          :audit     => audit
      },
      options
end

.find_by_number(number, with_children_items = false, audit = "NONE", options = {}) ⇒ Object



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

def find_by_number(number, with_children_items = false, audit = "NONE", options = {})
  get "#{KILLBILL_API_INVOICES_PREFIX}/byNumber/#{number}",
      {
          :withChildrenItems => with_children_items,
          :audit     => audit
      },
      options
end

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



49
50
51
52
53
54
55
56
# File 'lib/killbill_client/models/invoice.rb', line 49

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



58
59
60
61
62
63
64
65
# File 'lib/killbill_client/models/invoice.rb', line 58

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

.get_catalog_translation(locale, options = {}) ⇒ Object



279
280
281
282
283
284
285
286
287
288
# File 'lib/killbill_client/models/invoice.rb', line 279

def get_catalog_translation(locale, options = {})

  require_multi_tenant_options!(options, "Retrieving a catalog translation is only supported in multi-tenant mode")

  get "#{KILLBILL_API_INVOICES_PREFIX}/catalogTranslation/#{locale}",
      {},
      {
          :head => {'Accept' => 'text/plain'},
      }.merge(options)
end

.get_invoice_template(is_manual_pay, locale = nil, options = {}) ⇒ Object



212
213
214
215
216
217
218
219
220
221
222
# File 'lib/killbill_client/models/invoice.rb', line 212

def get_invoice_template(is_manual_pay, locale = nil, options = {})

  require_multi_tenant_options!(options, "Retrieving an invoice template supported in multi-tenant mode")


  get "#{KILLBILL_API_INVOICES_PREFIX}/#{is_manual_pay ? "manualPayTemplate/#{locale}" : "template"}",
      {},
      {
          :head => {'Accept' => 'text/html'},
      }.merge(options)
end

.get_invoice_translation(locale, options = {}) ⇒ Object



245
246
247
248
249
250
251
252
253
254
255
# File 'lib/killbill_client/models/invoice.rb', line 245

def get_invoice_translation(locale, options = {})

  require_multi_tenant_options!(options, "Retrieving an invoice translation supported in multi-tenant mode")


  get "#{KILLBILL_API_INVOICES_PREFIX}/translation/#{locale}",
      {},
      {
          :head => {'Accept' => 'text/plain'},
      }.merge(options)
end

.retrieve_invoice_group(account_id, group_id, with_children_items = false, audit = "NONE", options = {}) ⇒ Object



339
340
341
342
343
344
345
346
347
# File 'lib/killbill_client/models/invoice.rb', line 339

def retrieve_invoice_group(, group_id, with_children_items = false, audit = "NONE", options = {})
  res = get "#{KILLBILL_API_INVOICES_PREFIX}/#{group_id}/group",
              {
                :accountId => ,
                :withChildrenItems => with_children_items,
                :audit => audit
              },
              options
end

.retrieve_payments_for_invoice(invoice_id, with_plugin_info = false, with_attempts = false, audit = "NONE", options = {}) ⇒ Object



349
350
351
352
353
354
355
356
357
# File 'lib/killbill_client/models/invoice.rb', line 349

def retrieve_payments_for_invoice(invoice_id, with_plugin_info = false, with_attempts = false, audit = "NONE", options = {})
  res = get "#{KILLBILL_API_INVOICES_PREFIX}/#{invoice_id}/payments",
              {
                :withPluginInfo => with_plugin_info,
                :withAttempts => with_attempts,
                :audit => audit
              },
              options
end

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



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/killbill_client/models/invoice.rb', line 75

def trigger_invoice(, target_date, user = nil, reason = nil, comment = nil, options = {})
  query_map              = {:accountId => }
  query_map[:targetDate] = target_date if !target_date.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
    # No invoice to generate : TODO parse json to verify this is indeed the case
  end
end

.trigger_invoice_dry_run(account_id, target_date, upcoming_invoice_target_date, plugin_property = [], user = nil, reason = nil, comment = nil, options = {}) ⇒ Object



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/killbill_client/models/invoice.rb', line 97

def trigger_invoice_dry_run(, target_date, upcoming_invoice_target_date, plugin_property = [], user = nil, reason = nil, comment = nil, options = {})

  dry_run = InvoiceDryRunAttributes.new
  dry_run.dry_run_type = upcoming_invoice_target_date ? 'UPCOMING_INVOICE' : 'TARGET_DATE'

  query_map = {:accountId => }
  query_map[:targetDate] = target_date if target_date != nil
  query_map[:pluginProperty] = plugin_property unless plugin_property.empty?

  res = post "#{KILLBILL_API_DRY_RUN_INVOICES_PREFIX}",
             dry_run.to_json,
             query_map,
             {
                 :user => user || 'trigger_invoice_dry_run',
                 :reason => reason,
                 :comment => comment,
             }.merge(options),
             Invoice


  nothing_to_generate?(res) ? nil : res.refresh(options)

end

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



324
325
326
327
328
329
330
331
332
333
334
335
336
337
# File 'lib/killbill_client/models/invoice.rb', line 324

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

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

.upload_catalog_translation(catalog_translation, locale, delete_if_exists, user = nil, reason = nil, comment = nil, options = {}) ⇒ Object



290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
# File 'lib/killbill_client/models/invoice.rb', line 290

def upload_catalog_translation(catalog_translation, locale, delete_if_exists, user = nil, reason = nil, comment = nil, options = {})

  require_multi_tenant_options!(options, "Uploading a catalog translation is only supported in multi-tenant mode")

  params                  = {}
  params[:deleteIfExists] = delete_if_exists if delete_if_exists

  post "#{KILLBILL_API_INVOICES_PREFIX}/catalogTranslation/#{locale}",
       catalog_translation,
       params,
       {
           :head => {'Accept' => 'text/plain'},
           :content_type => 'text/plain',
           :user => user,
           :reason => reason,
           :comment => comment,
       }.merge(options)
  get_catalog_translation(locale, options)
end

.upload_invoice_template(invoice_template, is_manual_pay, delete_if_exists, user = nil, reason = nil, comment = nil, options = {}) ⇒ Object



224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
# File 'lib/killbill_client/models/invoice.rb', line 224

def upload_invoice_template(invoice_template, is_manual_pay, delete_if_exists, user = nil, reason = nil, comment = nil, options = {})

  require_multi_tenant_options!(options, "Uploading a invoice template is only supported in multi-tenant mode")


  params                  = {}
  params[:deleteIfExists] = delete_if_exists if delete_if_exists

  post "#{KILLBILL_API_INVOICES_PREFIX}/#{is_manual_pay ? "manualPayTemplate" : "template"}",
       invoice_template,
       params,
       {
           :head => {'Accept' => 'text/html'},
           :content_type => 'text/html',
           :user => user,
           :reason => reason,
           :comment => comment,
       }.merge(options)
  get_invoice_template(is_manual_pay, nil, options)
end

.upload_invoice_translation(invoice_translation, locale, delete_if_exists, user = nil, reason = nil, comment = nil, options = {}) ⇒ Object



257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
# File 'lib/killbill_client/models/invoice.rb', line 257

def upload_invoice_translation(invoice_translation, locale, delete_if_exists, user = nil, reason = nil, comment = nil, options = {})

  require_multi_tenant_options!(options, "Uploading a invoice translation is only supported in multi-tenant mode")


  params                  = {}
  params[:deleteIfExists] = delete_if_exists if delete_if_exists

  post "#{KILLBILL_API_INVOICES_PREFIX}/translation/#{locale}",
       invoice_translation,
       params,
       {
           :head => {'Accept' => 'text/plain'},
           :content_type => 'text/plain',
           :user => user,
           :reason => reason,
           :comment => comment,
       }.merge(options)
  get_invoice_translation(locale, options)
end

Instance Method Details

#commit(user = nil, reason = nil, comment = nil, options = {}) ⇒ Object



360
361
362
363
364
365
366
367
368
369
370
371
# File 'lib/killbill_client/models/invoice.rb', line 360

def commit(user = nil, reason = nil, comment = nil, options = {})

  self.class.put "#{Invoice::KILLBILL_API_INVOICES_PREFIX}/#{invoice_id}/commitInvoice",
                 nil,
                 {},
                 {
                     :user => user,
                     :reason => reason,
                     :comment => comment,
                 }.merge(options)

end

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



386
387
388
389
390
391
392
393
394
395
# File 'lib/killbill_client/models/invoice.rb', line 386

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

#trigger_email_notifications(user = nil, reason = nil, comment = nil, options = {}) ⇒ Object



397
398
399
400
401
402
403
404
405
406
# File 'lib/killbill_client/models/invoice.rb', line 397

def trigger_email_notifications(user = nil, reason = nil, comment = nil, options = {})
  self.class.post "#{KILLBILL_API_INVOICES_PREFIX}/#{invoice_id}/emailNotifications",
                  {},
                  {},
                  {
                      :user    => user,
                      :reason  => reason,
                      :comment => comment,
                  }.merge(options)
end

#void(user = nil, reason = nil, comment = nil, options = {}) ⇒ Object



373
374
375
376
377
378
379
380
381
382
383
384
# File 'lib/killbill_client/models/invoice.rb', line 373

def void(user = nil, reason = nil, comment = nil, options = {})

  self.class.put "#{Invoice::KILLBILL_API_INVOICES_PREFIX}/#{invoice_id}/voidInvoice",
                 nil,
                 {},
                 {
                     :user => user,
                     :reason => reason,
                     :comment => comment,
                 }.merge(options)

end