Class: Voltaria::Loans::Client
- Inherits:
-
Object
- Object
- Voltaria::Loans::Client
- Defined in:
- lib/voltaria/loans/client.rb
Instance Method Summary collapse
-
#create_bulk_loans(request_options: {}, **params) ⇒ Voltaria::Types::BulkLoanTaskResponse
Create multiple loans in a single request.
-
#create_loan(request_options: {}, **params) ⇒ Voltaria::Types::LoanResponseWithInstallments
Create a new loan for an approved client with an active credit limit.
-
#delete_loan(request_options: {}, **params) ⇒ Hash[String, Object]?
Delete a loan by ID.
-
#get_bulk_loan_status(request_options: {}, **params) ⇒ Voltaria::Types::BulkLoanTaskStatus
Check the status of a bulk loan creation task and retrieve results when completed.
-
#get_loan_by_id(request_options: {}, **params) ⇒ Voltaria::Types::LoanResponseWithInstallments
Retrieve detailed information about a specific loan by its loan ID.
- #initialize(client:) ⇒ void constructor
-
#list_loans(request_options: {}, **params) ⇒ Voltaria::Types::PaginatedResponseLoanResponseWithClientInfo
Retrieve all loans associated with your partner account.
-
#set_loan_default(request_options: {}, **params) ⇒ Voltaria::Types::LoanResponseWithInstallments
Mark a loan as defaulted, recording the default date and the amount recovered from selling it.
Constructor Details
#initialize(client:) ⇒ void
9 10 11 |
# File 'lib/voltaria/loans/client.rb', line 9 def initialize(client:) @client = client end |
Instance Method Details
#create_bulk_loans(request_options: {}, **params) ⇒ Voltaria::Types::BulkLoanTaskResponse
Create multiple loans in a single request. Processing happens asynchronously. Returns a task ID for tracking progress.
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 |
# File 'lib/voltaria/loans/client.rb', line 173 def create_bulk_loans(request_options: {}, **params) params = Voltaria::Internal::Types::Utils.normalize_keys(params) request = Voltaria::Internal::JSON::Request.new( base_url: [:base_url], method: "POST", path: "v2/loans/bulk", body: Voltaria::Loans::Types::BulkLoanCreatePayload.new(params).to_h, 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::BulkLoanTaskResponse.load(response.body) else error_class = Voltaria::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |
#create_loan(request_options: {}, **params) ⇒ Voltaria::Types::LoanResponseWithInstallments
Create a new loan for an approved client with an active credit limit.
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/voltaria/loans/client.rb', line 72 def create_loan(request_options: {}, **params) params = Voltaria::Internal::Types::Utils.normalize_keys(params) request = Voltaria::Internal::JSON::Request.new( base_url: [:base_url], method: "POST", path: "v2/loans", body: Voltaria::Loans::Types::LoanCreatePayload.new(params).to_h, 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::LoanResponseWithInstallments.load(response.body) else error_class = Voltaria::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |
#delete_loan(request_options: {}, **params) ⇒ Hash[String, Object]?
Delete a loan by ID. Only loans with 'pending' status can be deleted.
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/voltaria/loans/client.rb', line 141 def delete_loan(request_options: {}, **params) params = Voltaria::Internal::Types::Utils.normalize_keys(params) request = Voltaria::Internal::JSON::Request.new( base_url: [:base_url], method: "DELETE", path: "v2/loans/#{URI.encode_uri_component(params[:loan_id].to_s)}", 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 |
#get_bulk_loan_status(request_options: {}, **params) ⇒ Voltaria::Types::BulkLoanTaskStatus
Check the status of a bulk loan creation task and retrieve results when completed.
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 |
# File 'lib/voltaria/loans/client.rb', line 208 def get_bulk_loan_status(request_options: {}, **params) params = Voltaria::Internal::Types::Utils.normalize_keys(params) request = Voltaria::Internal::JSON::Request.new( base_url: [:base_url], method: "GET", path: "v2/loans/bulk/#{URI.encode_uri_component(params[:task_id].to_s)}", 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::BulkLoanTaskStatus.load(response.body) else error_class = Voltaria::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |
#get_loan_by_id(request_options: {}, **params) ⇒ Voltaria::Types::LoanResponseWithInstallments
Retrieve detailed information about a specific loan by its loan ID.
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/voltaria/loans/client.rb', line 107 def get_loan_by_id(request_options: {}, **params) params = Voltaria::Internal::Types::Utils.normalize_keys(params) request = Voltaria::Internal::JSON::Request.new( base_url: [:base_url], method: "GET", path: "v2/loans/#{URI.encode_uri_component(params[:loan_id].to_s)}", 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::LoanResponseWithInstallments.load(response.body) else error_class = Voltaria::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |
#list_loans(request_options: {}, **params) ⇒ Voltaria::Types::PaginatedResponseLoanResponseWithClientInfo
Retrieve all loans associated with your partner account. Supports optional filtering by client ID.
29 30 31 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 |
# File 'lib/voltaria/loans/client.rb', line 29 def list_loans(request_options: {}, **params) params = Voltaria::Internal::Types::Utils.normalize_keys(params) query_param_names = %i[page page_size client_id order_by q] 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["client_id"] = params[:client_id] if params.key?(:client_id) query_params["order_by"] = params[:order_by] if params.key?(:order_by) query_params["q"] = params[:q] if params.key?(:q) params.except(*query_param_names) request = Voltaria::Internal::JSON::Request.new( base_url: [:base_url], method: "GET", path: "v2/loans", query: query_params, 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::PaginatedResponseLoanResponseWithClientInfo.load(response.body) else error_class = Voltaria::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |
#set_loan_default(request_options: {}, **params) ⇒ Voltaria::Types::LoanResponseWithInstallments
Mark a loan as defaulted, recording the default date and the amount recovered from selling it. Defaults the loan's active and overdue installments and updates the loan status accordingly.
243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 |
# File 'lib/voltaria/loans/client.rb', line 243 def set_loan_default(request_options: {}, **params) params = Voltaria::Internal::Types::Utils.normalize_keys(params) request_data = Voltaria::Loans::Types::LoanDefaultPayload.new(params).to_h non_body_param_names = ["loan_id"] body = request_data.except(*non_body_param_names) request = Voltaria::Internal::JSON::Request.new( base_url: [:base_url], method: "POST", path: "v2/loans/#{URI.encode_uri_component(params[:loan_id].to_s)}/set-default", body: body, 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::LoanResponseWithInstallments.load(response.body) else error_class = Voltaria::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |