Class: Payabli::Billing::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/payabli/billing/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ void

Parameters:



9
10
11
# File 'lib/payabli/billing/client.rb', line 9

def initialize(client:)
  @client = client
end

Instance Method Details

#get_profile(request_options: {}, **params) ⇒ Payabli::Types::BillingProfileResponse

Returns the billing profile currently assigned to an entity, including its billable events and fee schedules. Use it to read the pricing terms in effect for an organization, paypoint, template, or application.

Requires a token with the billing_profile_read permission and access to the requested entity; otherwise the call gets 403 Forbidden.

If the entity exists but has no profile assigned, the call returns 404 Not Found.

Examples:

client.billing.get_profile(
  service_group: "PayIn",
  entity_type: "Organization",
  entity_id: 123
)

Parameters:

  • request_options (Hash) (defaults to: {})
  • params (Hash)

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Options Hash (**params):

Returns:



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/payabli/billing/client.rb', line 104

def get_profile(request_options: {}, **params)
  params = Payabli::Internal::Types::Utils.normalize_keys(params)
  headers = @client.auth_headers_for_endpoint(security: [{ "BearerAuth" => [] }, { "APIKeyAuth" => [] }])
  request = Payabli::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "GET",
    path: "billing/configuration/#{URI.encode_uri_component(params[:service_group].to_s)}/#{URI.encode_uri_component(params[:entity_type].to_s)}/#{URI.encode_uri_component(params[:entity_id].to_s)}",
    headers: headers,
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Payabli::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    Payabli::Types::BillingProfileResponse.load(response.body)
  else
    error_class = Payabli::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#list_profiles(request_options: {}, **params) ⇒ Payabli::Types::BillingProfileQueryResponse

Returns every billing profile that belongs to an organization. This is the data behind the Profile Library table in the Payabli Portal.

Requires a token with the billing_profile_read permission; a token without it gets 403 Forbidden.

Examples:

client.billing.list_profiles(
  org_id: 123,
  limit_record: 20,
  from_record: 0
)

Parameters:

  • request_options (Hash) (defaults to: {})
  • params (Hash)

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Options Hash (**params):

  • :org_id (Integer)
  • :profile_name (String, nil)
  • :fee_type (Integer, nil)
  • :service_vertical (Integer, nil)
  • :profile_id (Integer, nil)
  • :limit_record (Integer, nil)
  • :from_record (Integer, nil)

Returns:



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
67
68
69
70
71
72
73
# File 'lib/payabli/billing/client.rb', line 42

def list_profiles(request_options: {}, **params)
  params = Payabli::Internal::Types::Utils.normalize_keys(params)
  query_params = {}
  query_params["profileName"] = params[:profile_name] if params.key?(:profile_name)
  query_params["feeType"] = params[:fee_type] if params.key?(:fee_type)
  query_params["serviceVertical"] = params[:service_vertical] if params.key?(:service_vertical)
  query_params["profileId"] = params[:profile_id] if params.key?(:profile_id)
  query_params["limitRecord"] = params[:limit_record] if params.key?(:limit_record)
  query_params["fromRecord"] = params[:from_record] if params.key?(:from_record)

  headers = @client.auth_headers_for_endpoint(security: [{ "BearerAuth" => [] }, { "APIKeyAuth" => [] }])
  request = Payabli::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "GET",
    path: "billing/configuration/org/#{URI.encode_uri_component(params[:org_id].to_s)}",
    headers: headers,
    query: query_params,
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Payabli::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    Payabli::Types::BillingProfileQueryResponse.load(response.body)
  else
    error_class = Payabli::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end