Class: BillForward::Invoice

Inherits:
MutableEntity show all
Defined in:
lib/bill_forward/entities/invoice.rb

Overview

This entity exposes the following child entities via method_missing:

InvoiceLine[] .invoiceLines TaxLine[] .taxLines InvoicePayment[] .invoicePayments Refund[] .invoiceRefunds CreditNote[] .invoiceCreditNotes SubscriptionCharge[] .charges

Instance Attribute Summary

Attributes inherited from BillingEntity

#_client

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from MutableEntity

#delete, #initialize, #save

Methods inherited from InsertableEntity

#initialize

Methods inherited from BillingEntity

#[], #[]=, #_dump, _load, build_entity, build_entity_array, #camel_case_lower, get_all, get_by_id, #initialize, #method_missing, request_ambiguous, request_first_heterotyped, request_many_heterotyped, #serialize, #serialize_field, singleton_client, #state_params, #to_json, #to_ordered_hash, #to_s, #to_unordered_hash

Constructor Details

This class inherits a constructor from BillForward::MutableEntity

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class BillForward::BillingEntity

Class Method Details

.add_charge(id, request_object = {}, custom_client = nil) ⇒ Object

Raises:

  • (ArgumentError)


77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/bill_forward/entities/invoice.rb', line 77

def add_charge(id, request_object = {}, custom_client = nil)
  raise ArgumentError.new("id cannot be nil") if id.nil?

  endpoint = sprintf('%s/charges',
                     ERB::Util.url_encode(id)
  )

  request_entity = BillForward::GenericEntity.new(
      request_object
  )

  self.request_many_heterotyped(BillForward::SubscriptionCharge, 'post', endpoint, request_entity, nil, custom_client)
end

.create(entity = nil) ⇒ Object



14
15
16
17
# File 'lib/bill_forward/entities/invoice.rb', line 14

def create(entity = nil)
  raise DenyMethod.new 'Create support is denied for this entity; '+
    'Invoices are generated instead by the BillForward Engines.'
end

.execute(id, request_object = {}, custom_client = nil) ⇒ Object

Raises:

  • (ArgumentError)


53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/bill_forward/entities/invoice.rb', line 53

def execute(id, request_object = {}, custom_client = nil)
  raise ArgumentError.new("id cannot be nil") if id.nil?

  endpoint = sprintf('%s/execute',
                     ERB::Util.url_encode(id)
  )

  request_entity = BillForward::GenericEntity.new(
      request_object
  )

  self.request_first('post', endpoint, request_entity, nil, custom_client)
end

.get_by_account_id(id, query_params = {}, custom_client = nil) ⇒ Object

Raises:

  • (ArgumentError)


29
30
31
32
33
34
35
36
37
# File 'lib/bill_forward/entities/invoice.rb', line 29

def (id, query_params = {}, custom_client = nil)
  raise ArgumentError.new("id cannot be nil") if id.nil?

  endpoint = sprintf('account/%s',
    ERB::Util.url_encode(id)
    )

  self.request_many('get', endpoint, query_params, custom_client)
end

.get_by_subscription_id(id, query_params = {}, custom_client = nil) ⇒ Object

Raises:

  • (ArgumentError)


19
20
21
22
23
24
25
26
27
# File 'lib/bill_forward/entities/invoice.rb', line 19

def get_by_subscription_id(id, query_params = {}, custom_client = nil)
  raise ArgumentError.new("id cannot be nil") if id.nil?

  endpoint = sprintf('subscription/%s',
    ERB::Util.url_encode(id)
    )

  self.request_many('get', endpoint, query_params, custom_client)
end

.get_charges(id, query_params = {}, custom_client = nil) ⇒ Object

Raises:

  • (ArgumentError)


67
68
69
70
71
72
73
74
75
# File 'lib/bill_forward/entities/invoice.rb', line 67

def get_charges(id, query_params = {}, custom_client = nil)
  raise ArgumentError.new("id cannot be nil") if id.nil?

  endpoint = sprintf('%s/charges',
                     ERB::Util.url_encode(id)
  )

  self.request_many_heterotyped(BillForward::SubscriptionCharge, 'get', endpoint, query_params, custom_client)
end

.recalculate(id, request_object = {}, custom_client = nil) ⇒ Object

Raises:

  • (ArgumentError)


39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/bill_forward/entities/invoice.rb', line 39

def recalculate(id, request_object = {}, custom_client = nil)
  raise ArgumentError.new("id cannot be nil") if id.nil?

  endpoint = sprintf('%s/recalculate',
                     ERB::Util.url_encode(id)
  )

  request_entity = BillForward::GenericEntity.new(
      request_object
  )

  self.request_first('post', endpoint, request_entity, nil, custom_client)
end

Instance Method Details

#add_charge(request_object = {}, custom_client = nil) ⇒ Object



92
93
94
# File 'lib/bill_forward/entities/invoice.rb', line 92

def add_charge(request_object = {}, custom_client = nil)
  self.class.add_charge(self.id, request_object, custom_client)
end