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.
-
#create_loan_review_request(request_options: {}, **params) ⇒ Voltaria::Types::LoanReviewRequestResponse
Ask Voltaria to review a not-yet-disbursed (pending or pre-approved) loan before disbursement.
-
#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.
-
#get_loan_review_request(request_options: {}, **params) ⇒ Voltaria::Types::LoanReviewRequestResponse
Retrieve a specific loan review request by its ID.
- #initialize(client:) ⇒ void constructor
-
#list_loan_review_requests(request_options: {}, **params) ⇒ Voltaria::Types::PaginatedResponseLoanReviewRequestResponse
List loan review requests for your partner account, optionally filtered by loan ID or client ID.
-
#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.
291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 |
# File 'lib/voltaria/loans/client.rb', line 291 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.
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 |
# File 'lib/voltaria/loans/client.rb', line 190 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 |
#create_loan_review_request(request_options: {}, **params) ⇒ Voltaria::Types::LoanReviewRequestResponse
Ask Voltaria to review a not-yet-disbursed (pending or pre-approved) loan before disbursement.
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/voltaria/loans/client.rb', line 74 def create_loan_review_request(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/review-requests", body: Voltaria::Loans::Types::LoanReviewRequestCreatePayload.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::LoanReviewRequestResponse.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.
259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 |
# File 'lib/voltaria/loans/client.rb', line 259 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.
326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 |
# File 'lib/voltaria/loans/client.rb', line 326 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.
225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 |
# File 'lib/voltaria/loans/client.rb', line 225 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 |
#get_loan_review_request(request_options: {}, **params) ⇒ Voltaria::Types::LoanReviewRequestResponse
Retrieve a specific loan review request by its ID.
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/voltaria/loans/client.rb', line 109 def get_loan_review_request(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/review-requests/#{URI.encode_uri_component(params[:request_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::LoanReviewRequestResponse.load(response.body) else error_class = Voltaria::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |
#list_loan_review_requests(request_options: {}, **params) ⇒ Voltaria::Types::PaginatedResponseLoanReviewRequestResponse
List loan review requests for your partner account, optionally filtered by loan ID or client ID.
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 60 61 |
# File 'lib/voltaria/loans/client.rb', line 30 def list_loan_review_requests(request_options: {}, **params) params = Voltaria::Internal::Types::Utils.normalize_keys(params) query_param_names = %i[loan_id client_id page page_size order_by q] query_params = {} query_params["loan_id"] = params[:loan_id] if params.key?(:loan_id) query_params["client_id"] = params[:client_id] if params.key?(:client_id) 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) 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/review-requests", 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::PaginatedResponseLoanReviewRequestResponse.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.
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'lib/voltaria/loans/client.rb', line 147 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.
361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 |
# File 'lib/voltaria/loans/client.rb', line 361 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 |