Class: Lago::Api::Resources::BillingEntity

Inherits:
Base
  • Object
show all
Defined in:
lib/lago/api/resources/billing_entity.rb

Instance Attribute Summary

Attributes inherited from Base

#client

Instance Method Summary collapse

Methods inherited from Base

#get, #get_all, #initialize, #whitelist_params

Constructor Details

This class inherits a constructor from Lago::Api::Resources::Base

Instance Method Details

#api_resourceObject



7
8
9
# File 'lib/lago/api/resources/billing_entity.rb', line 7

def api_resource
  'billing_entities'
end

#create(params) ⇒ Object



15
16
17
18
19
20
# File 'lib/lago/api/resources/billing_entity.rb', line 15

def create(params)
  payload = whitelist_create_params(params)
  response = connection.post(payload)[root_name]

  JSON.parse(response.to_json, object_class: OpenStruct)
end

#destroy(billing_entity_code) ⇒ Object

Raises:

  • (NotImplementedError)


29
30
31
# File 'lib/lago/api/resources/billing_entity.rb', line 29

def destroy(billing_entity_code)
  raise NotImplementedError
end

#root_nameObject



11
12
13
# File 'lib/lago/api/resources/billing_entity.rb', line 11

def root_name
  'billing_entity'
end

#update(params, billing_entity_code) ⇒ Object



22
23
24
25
26
27
# File 'lib/lago/api/resources/billing_entity.rb', line 22

def update(params, billing_entity_code)
  payload = whitelist_update_params(params)
  response = connection.put(identifier: billing_entity_code, body: payload)[root_name]

  JSON.parse(response.to_json, object_class: OpenStruct)
end

#whitelist_billing_configuration(billing_params) ⇒ Object



66
67
68
69
70
71
72
# File 'lib/lago/api/resources/billing_entity.rb', line 66

def whitelist_billing_configuration(billing_params)
  (billing_params || {}).slice(
    :invoice_footer,
    :invoice_grace_period,
    :document_locale,
  )
end

#whitelist_create_params(params) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/lago/api/resources/billing_entity.rb', line 33

def whitelist_create_params(params)
  result_params = params.slice(
    :code,
    :name,
    :address_line1,
    :address_line2,
    :city,
    :state,
    :zipcode,
    :country,
    :email,
    :phone,
    :default_currency,
    :timezone,
    :document_numbering,
    :document_number_prefix,
    :finalize_zero_amount_invoice,
    :net_payment_term,
    :eu_tax_management,
    :logo,
    :legal_name,
    :legal_number,
    :tax_identification_number,
    :email_settings
  ).compact

  whitelist_billing_configuration(params[:billing_configuration]).tap do |config|
    result_params[:billing_configuration] = config unless config.empty?
  end

  { root_name => result_params }
end

#whitelist_update_params(params) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/lago/api/resources/billing_entity.rb', line 74

def whitelist_update_params(params)
  result_params = whitelist_create_params(params).dup

  result_params.delete(:code)
  result_params[:tax_codes] = params[:tax_codes] if params.key?(:tax_codes)

  if params.key?(:invoice_custom_section_codes)
    result_params[:invoice_custom_section_codes] = params[:invoice_custom_section_codes]
  end

  { root_name => result_params }
end