Class: Voltaria::Accounts::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/voltaria/accounts/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ void



9
10
11
# File 'lib/voltaria/accounts/client.rb', line 9

def initialize(client:)
  @client = client
end

Instance Method Details

#create_client_account(request_options: {}, **params) ⇒ Voltaria::Types::ClientAccountResponse

Create a bank account for one of your clients. The account is registered with the payment provider immediately. Use the status field to create it as active (default; demotes any existing active account in the same currency to passive) or passive.

Parameters:

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):

  • :client_id (String)

Returns:



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/voltaria/accounts/client.rb', line 105

def (request_options: {}, **params)
  params = Voltaria::Internal::Types::Utils.normalize_keys(params)
  request_data = Voltaria::Accounts::Types::PartnerClientAccountCreateRequest.new(params).to_h
  non_body_param_names = ["client_id"]
  body = request_data.except(*non_body_param_names)

  request = Voltaria::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "POST",
    path: "v2/clients/#{URI.encode_uri_component(params[:client_id].to_s)}/accounts",
    body: body,
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Voltaria::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    Voltaria::Types::ClientAccountResponse.load(response.body)
  else
    error_class = Voltaria::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#get_client_account(request_options: {}, **params) ⇒ Voltaria::Types::ClientAccountResponse

Retrieve a specific bank account for one of your clients.

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):

  • :client_id (String)
  • :account_id (String)

Returns:



145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# File 'lib/voltaria/accounts/client.rb', line 145

def (request_options: {}, **params)
  params = Voltaria::Internal::Types::Utils.normalize_keys(params)
  request = Voltaria::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "GET",
    path: "v2/clients/#{URI.encode_uri_component(params[:client_id].to_s)}/accounts/#{URI.encode_uri_component(params[:account_id].to_s)}",
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Voltaria::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    Voltaria::Types::ClientAccountResponse.load(response.body)
  else
    error_class = Voltaria::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#list_client_account_fields(request_options: {}, **params) ⇒ Hash[String, Voltaria::Types::CurrencyFieldSpec]

Return the required and optional bank account fields for each supported currency. Fetch once and cache; use it to build the create-account request.

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):

  • :client_id (String)

Returns:

Raises:

  • (error_class)


26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/voltaria/accounts/client.rb', line 26

def (request_options: {}, **params)
  params = Voltaria::Internal::Types::Utils.normalize_keys(params)
  request = Voltaria::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "GET",
    path: "v2/clients/#{URI.encode_uri_component(params[:client_id].to_s)}/accounts/fields",
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Voltaria::Errors::TimeoutError
  end
  code = response.code.to_i
  return if code.between?(200, 299)

  error_class = Voltaria::Errors::ResponseError.subclass_for_code(code)
  raise error_class.new(response.body, code: code)
end

#list_client_accounts(request_options: {}, **params) ⇒ Voltaria::Types::PaginatedResponseClientAccountResponse

Retrieve all bank accounts for one of your clients.

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):

  • :client_id (String)
  • :page (Integer, nil)
  • :page_size (Integer, nil)
  • :order_by (String, nil)

Returns:



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/voltaria/accounts/client.rb', line 61

def list_client_accounts(request_options: {}, **params)
  params = Voltaria::Internal::Types::Utils.normalize_keys(params)
  query_param_names = %i[page page_size order_by]
  query_params = {}
  query_params["page"] = params[:page] if params.key?(:page)
  query_params["page_size"] = params[:page_size] if params.key?(:page_size)
  query_params["order_by"] = params[:order_by] if params.key?(:order_by)
  params = params.except(*query_param_names)

  request = Voltaria::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "GET",
    path: "v2/clients/#{URI.encode_uri_component(params[:client_id].to_s)}/accounts",
    query: query_params,
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Voltaria::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    Voltaria::Types::PaginatedResponseClientAccountResponse.load(response.body)
  else
    error_class = Voltaria::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end