Class: Lago::Api::Resources::Customer

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

Instance Attribute Summary

Attributes inherited from Base

#client

Instance Method Summary collapse

Methods inherited from Base

#create, #destroy, #get, #get_all, #initialize, #update

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/customer.rb', line 7

def api_resource
  'customers'
end

#current_usage(external_customer_id, external_subscription_id) ⇒ Object



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

def current_usage(external_customer_id, external_subscription_id)
  uri = URI(
    "#{client.base_api_url}#{api_resource}/#{external_customer_id}/current_usage?external_subscription_id=#{external_subscription_id}"
  )
  connection.get(uri, identifier: nil)
end

#portal_url(external_customer_id) ⇒ Object



22
23
24
25
26
27
28
29
30
# File 'lib/lago/api/resources/customer.rb', line 22

def portal_url(external_customer_id)
  uri = URI(
    "#{client.base_api_url}#{api_resource}/#{external_customer_id}/portal_url"
  )

  response = connection.get(uri, identifier: nil)[root_name]

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

#root_nameObject



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

def root_name
  'customer'
end

#whitelist_billing_configuration(billing_params) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
# File 'lib/lago/api/resources/customer.rb', line 63

def whitelist_billing_configuration(billing_params)
  (billing_params || {}).slice(
    :invoice_grace_period,
    :payment_provider,
    :provider_customer_id,
    :sync,
    :sync_with_provider,
    :vat_rate,
    :document_locale,
  )
end

#whitelist_metadata(metadata) ⇒ Object



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

def ()
   = []

  ( || []).each do |m|
    result = (m || {}).slice(:id, :key, :value, :display_in_invoice)

     << result unless result.empty?
  end

  
end

#whitelist_params(params) ⇒ Object



32
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
# File 'lib/lago/api/resources/customer.rb', line 32

def whitelist_params(params)
  result_hash = {
    external_id: params[:external_id],
    address_line1: params[:address_line1],
    address_line2: params[:address_line2],
    city: params[:city],
    country: params[:country],
    email: params[:email],
    legal_name: params[:legal_name],
    legal_number: params[:legal_number],
    tax_identification_number: params[:tax_identification_number],
    logo_url: params[:logo_url],
    name: params[:name],
    phone: params[:phone],
    state: params[:state],
    url: params[:url],
    zipcode: params[:zipcode],
    currency: params[:currency],
    timezone: params[:timezone],
  }

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

   = (params[:metadata])
  result_hash[:metadata] =  unless .empty?

  { root_name => result_hash }
end