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



9
10
11
# File 'lib/lago/api/resources/billing_entity.rb', line 9

def api_resource
  'billing_entities'
end

#create(params) ⇒ Object



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

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)


31
32
33
# File 'lib/lago/api/resources/billing_entity.rb', line 31

def destroy(billing_entity_code)
  raise NotImplementedError
end

#root_nameObject



13
14
15
# File 'lib/lago/api/resources/billing_entity.rb', line 13

def root_name
  'billing_entity'
end

#update(params, billing_entity_code) ⇒ Object



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

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



68
69
70
71
72
73
74
75
76
# File 'lib/lago/api/resources/billing_entity.rb', line 68

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

#whitelist_create_params(params) ⇒ Object



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
65
66
# File 'lib/lago/api/resources/billing_entity.rb', line 35

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



78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/lago/api/resources/billing_entity.rb', line 78

def whitelist_update_params(params)
  result_params = whitelist_create_params(params).dup[root_name]

  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