Class: Revo::LoansApi::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/revo/loans_api/client.rb

Defined Under Namespace

Classes: Result

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base_url:, login: nil, password: nil, session_token: nil, application_source: nil, timeouts: nil) ⇒ Client

Returns a new instance of Client.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/revo/loans_api/client.rb', line 15

def initialize(
  base_url:,
  login: nil,
  password: nil,
  session_token: nil,
  application_source: nil,
  timeouts: nil
)
  @base_url = base_url
  @login = 
  @password = password
  @session_token = session_token
  @application_source = application_source
  @timeouts = timeouts
end

Instance Attribute Details

#loan_request_tokenObject (readonly)

Returns the value of attribute loan_request_token.



11
12
13
# File 'lib/revo/loans_api/client.rb', line 11

def loan_request_token
  @loan_request_token
end

#session_tokenObject (readonly)

Returns the value of attribute session_token.



11
12
13
# File 'lib/revo/loans_api/client.rb', line 11

def session_token
  @session_token
end

Instance Method Details

#billing_shift_document(client_id:, billing_chain: nil, billing_shift_id: nil) ⇒ Object



295
296
297
298
299
300
301
302
# File 'lib/revo/loans_api/client.rb', line 295

def billing_shift_document(client_id:, billing_chain: nil, billing_shift_id: nil)
  if billing_shift_id
    make_request(:get, "clients/#{client_id}/billing_shift/#{billing_shift_id}")
  else
    make_request(:get, "clients/#{client_id}/billing_shift/agreement",
                 params: { billing_chain: billing_chain })
  end
end

#billing_shift_info(client_id:) ⇒ Object



291
292
293
# File 'lib/revo/loans_api/client.rb', line 291

def billing_shift_info(client_id:)
  make_request(:get, "clients/#{client_id}/billing_shift/info")
end

#buy_credit_report(client_id:, report_id:) ⇒ Object



370
371
372
# File 'lib/revo/loans_api/client.rb', line 370

def buy_credit_report(client_id:, report_id:)
  make_request(:post, "clients/#{client_id}/credit_ratings/#{report_id}/buy")
end

#cancel_return(return_id:) ⇒ Object



195
196
197
# File 'lib/revo/loans_api/client.rb', line 195

def cancel_return(return_id:)
  make_request(:post, "returns/#{return_id}/cancel")
end

#certificate(loan_application_id:, kind:) ⇒ Object



362
363
364
365
366
367
368
# File 'lib/revo/loans_api/client.rb', line 362

def certificate(loan_application_id:, kind:)
  make_request(
    :post,
    "loan_applications/#{loan_application_id}/certificate",
    params: { kind: kind }
  )
end

#check_client_code(token:, code:) ⇒ Object



207
208
209
210
211
212
213
# File 'lib/revo/loans_api/client.rb', line 207

def check_client_code(token:, code:)
  make_request(
    :post,
    "loan_requests/#{token}/client/check_code",
    params: { code: code }
  )
end

#client_loan_documents(client_id:, loan_application_id:) ⇒ Object



339
340
341
# File 'lib/revo/loans_api/client.rb', line 339

def client_loan_documents(client_id:, loan_application_id:)
  make_request(:get, "clients/#{client_id}/loans/#{loan_application_id}")
end

#complete_loan_request(token:, code: nil, session_id: nil) ⇒ Object



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/revo/loans_api/client.rb', line 107

def complete_loan_request(token:, code: nil, session_id: nil)
  complete_params = {}

  if session_id
    complete_params[:session_id] = session_id
  else
    complete_params[:code] = code
  end

  make_request(
    :post,
    "loan_requests/#{token}/confirmation",
    params: complete_params,
    headers: { 'Application-Source': application_source }
  )
end

#confirm_billing_shift(client_id:, billing_chain:, code: nil, session_id: nil) ⇒ Object



276
277
278
279
280
281
282
283
284
285
286
287
288
289
# File 'lib/revo/loans_api/client.rb', line 276

def confirm_billing_shift(client_id:, billing_chain:, code: nil, session_id: nil)
  confirmation_params = {
    billing_chain: billing_chain
  }

  confirmation_params[:code] = code if code
  confirmation_params[:session_id] = session_id if session_id

  make_request(
    :post,
    "clients/#{client_id}/billing_shift/confirmation",
    params: confirmation_params
  )
end

#confirm_loan(token:, bill:) ⇒ Object



154
155
156
157
158
159
160
161
162
163
164
# File 'lib/revo/loans_api/client.rb', line 154

def confirm_loan(token:, bill:)
  response = make_request(
    :put,
    "loan_requests/#{token}/loan/bill",
    params: { loan: { bill: bill } }
  )

  return response unless response.success?

  Result.new(success?: true, response: response.response)
end

#confirm_restructuring(client_id:, code:, product:) ⇒ Object



312
313
314
315
316
317
318
# File 'lib/revo/loans_api/client.rb', line 312

def confirm_restructuring(client_id:, code:, product:)
  make_request(
    :post,
    "clients/#{client_id}/restructuring/#{product}/confirmation",
    params: { code: code }
  )
end

#confirm_return(return_id:) ⇒ Object



191
192
193
# File 'lib/revo/loans_api/client.rb', line 191

def confirm_return(return_id:)
  make_request(:post, "returns/#{return_id}/confirm")
end

#create_card_loan(token:, term_id:, force_approve: false) ⇒ Object



255
256
257
258
259
260
261
262
# File 'lib/revo/loans_api/client.rb', line 255

def create_card_loan(token:, term_id:, force_approve: false)
  make_request(
    :post,
    "loan_requests/#{token}/virtual_card_loan",
    params: { term_id: term_id, force_approve: force_approve },
    headers: { 'Application-Source': application_source }
  )
end

#create_client(token:, client_params:, provider_data: {}, skip_email_confirmation: false) ⇒ Object



215
216
217
218
219
220
221
222
223
# File 'lib/revo/loans_api/client.rb', line 215

def create_client(token:, client_params:, provider_data: {}, skip_email_confirmation: false)
  make_request(
    :post,
    "loan_requests/#{token}/client",
    params: { client: client_params, provider_data: provider_data,
              skip_email_confirmation: skip_email_confirmation },
    headers: { 'Application-Source': application_source }
  )
end

#create_loan(token:, term_id:) ⇒ Object



124
125
126
127
128
129
130
131
# File 'lib/revo/loans_api/client.rb', line 124

def create_loan(token:, term_id:)
  make_request(
    :post,
    "loan_requests/#{token}/loan",
    params: { term_id: term_id },
    headers: { 'Application-Source': application_source }
  )
end

#create_loan_request(options) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/revo/loans_api/client.rb', line 40

def create_loan_request(options)
  response = make_request(
    :post,
    'loan_requests',
    params: loan_request_params(options)
  )
  return response unless response.success?

  @loan_request_token = response.response.dig(:loan_request, :token)
  terms = loan_request_terms
  return terms unless terms.success?

  Result.new(success?: true,
             response: {
               token: loan_request_token,
               insurance_available: response.response.dig(:loan_request, :insurance_available),
               terms: terms.response[:loan_request]
             })
end

#create_return(order_id:, code:, amount:, store_id:) ⇒ Object



179
180
181
182
183
184
185
186
187
188
189
# File 'lib/revo/loans_api/client.rb', line 179

def create_return(order_id:, code:, amount:, store_id:)
  params = {
    return: {
      order_id: order_id,
      confirmation_code: code,
      amount: amount,
      store_id: store_id
    }
  }
  make_request(:post, 'returns', params: params)
end

#create_sessionObject



31
32
33
34
35
36
37
38
# File 'lib/revo/loans_api/client.rb', line 31

def create_session
  make_request(
    :post, 'sessions',
    params: { user: { login: , password: password } }
  ).tap do |result|
    @session_token = result.response.dig(:user, :authentication_token) if result&.success?
  end
end

#create_stretch_document(id:, payload:) ⇒ Object



398
399
400
# File 'lib/revo/loans_api/client.rb', line 398

def create_stretch_document(id:, payload:)
  make_request(:post, "offer/stretch/#{id}", params: { payload: payload })
end

#create_virtual_card(token:, term_id:, force_approve: false) ⇒ Object



237
238
239
240
241
242
243
244
# File 'lib/revo/loans_api/client.rb', line 237

def create_virtual_card(token:, term_id:, force_approve: false)
  make_request(
    :post,
    "loan_requests/#{token}/virtual_card",
    params: { term_id: term_id, force_approve: force_approve },
    headers: { 'Application-Source': application_source }
  )
end

#credit_report(client_id:, report_id:) ⇒ Object



378
379
380
# File 'lib/revo/loans_api/client.rb', line 378

def credit_report(client_id:, report_id:)
  make_request(:get, "clients/#{client_id}/credit_ratings/#{report_id}")
end

#credit_report_document(client_id:, report_id:) ⇒ Object



382
383
384
# File 'lib/revo/loans_api/client.rb', line 382

def credit_report_document(client_id:, report_id:)
  make_request(:get, "clients/#{client_id}/credit_ratings/#{report_id}/document")
end

#credit_report_set_free(client_id:) ⇒ Object



386
387
388
# File 'lib/revo/loans_api/client.rb', line 386

def credit_report_set_free(client_id:)
  make_request(:post, "clients/#{client_id}/credit_ratings/set_free")
end

#credit_reports_list(client_id:) ⇒ Object



374
375
376
# File 'lib/revo/loans_api/client.rb', line 374

def credit_reports_list(client_id:)
  make_request(:get, "clients/#{client_id}/credit_ratings")
end

#document(token:, type:, format: 'html') ⇒ Object

prerequisite: a client with the LR’s phone number should already exist



99
100
101
# File 'lib/revo/loans_api/client.rb', line 99

def document(token:, type:, format: 'html')
  make_request(:get, "loan_requests/#{token}/documents/#{type}.#{format}")
end

#finalize_loan(token:, code: nil, sms_info: '0', skip_confirmation: false, session_id: nil) ⇒ Object



133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# File 'lib/revo/loans_api/client.rb', line 133

def finalize_loan(token:, code: nil, sms_info: '0', skip_confirmation: false, session_id: nil)
  loan_params = {
    agree_processing: '1',
    agree_sms_info: sms_info
  }

  loan_params[:confirmation_code] = code if code
  loan_params[:session_id] = session_id if session_id

  if skip_confirmation
    loan_params[:skip_confirmation] = true
    loan_params.delete(:confirmation_code)
  end

  make_request(
    :post,
    "loan_requests/#{token}/loan/finalization",
    params: { loan: loan_params }
  )
end

#get_client(guid:) ⇒ Object



229
230
231
# File 'lib/revo/loans_api/client.rb', line 229

def get_client(guid:)
  make_request(:get, "clients/#{guid}")
end

#get_client_additional_services(client_id:) ⇒ Object



343
344
345
# File 'lib/revo/loans_api/client.rb', line 343

def get_client_additional_services(client_id:)
  make_request(:get, "clients/#{client_id}/additional_services")
end

#get_client_info(guid:) ⇒ Object



233
234
235
# File 'lib/revo/loans_api/client.rb', line 233

def get_client_info(guid:)
  make_request(:get, "clients/#{guid}/informers")
end

#get_client_limit(client_id:) ⇒ Object



335
336
337
# File 'lib/revo/loans_api/client.rb', line 335

def get_client_limit(client_id:)
  make_request(:get, "clients/#{client_id}/limit")
end

#get_loan_request_attributes(token:) ⇒ Object



88
89
90
91
92
93
94
95
96
# File 'lib/revo/loans_api/client.rb', line 88

def get_loan_request_attributes(token:)
  result = make_request(:get, "loan_requests/#{token}")
  return result unless result.success?

  Result.new(
    success?: true,
    response: result.response[:loan_request_attributes]
  )
end

#get_loan_request_info(token:, amount:) ⇒ Object



82
83
84
85
86
# File 'lib/revo/loans_api/client.rb', line 82

def get_loan_request_info(token:, amount:)
  result = make_request(:get, "loan_requests/#{token}?amount=#{amount}")

  result.success? ? result.response[:loan_request] : []
end

#increase_client_limit(client_id:, amount:) ⇒ Object



327
328
329
330
331
332
333
# File 'lib/revo/loans_api/client.rb', line 327

def increase_client_limit(client_id:, amount:)
  make_request(
    :patch,
    "clients/#{client_id}/limit",
    params: { amount: amount }
  )
end

#nethone(params: {}) ⇒ Object



406
407
408
# File 'lib/revo/loans_api/client.rb', line 406

def nethone(params: {})
  make_request(:post, "nethone", params: params)
end

#orders(store_id:, filters: {}) ⇒ Object

returns



167
168
169
170
171
172
173
# File 'lib/revo/loans_api/client.rb', line 167

def orders(store_id:, filters: {})
  make_request(
    :get,
    'orders',
    params: { store_id: store_id, filters: filters }
  )
end

#restructing_forms_send_sms(id:, client_guid:) ⇒ Object



416
417
418
# File 'lib/revo/loans_api/client.rb', line 416

def restructing_forms_send_sms(id:, client_guid:)
  make_request(:post, "restructuring_forms", params: { id: id, client_guid: client_guid})
end

#restructings_form_update(id:, client_guid:, sign_code:, payload:) ⇒ Object



410
411
412
413
414
# File 'lib/revo/loans_api/client.rb', line 410

def restructings_form_update(id:, client_guid:, sign_code:, payload:)
  make_request(:patch,
               "restructuring_forms",
               params: { id: id, client_guid: client_guid, sign_code: sign_code, payload: payload})
end

#restructuring_document(client_id:, product:, format: 'pdf') ⇒ Object



320
321
322
323
324
325
# File 'lib/revo/loans_api/client.rb', line 320

def restructuring_document(client_id:, product:, format: 'pdf')
  make_request(
    :get,
    "clients/#{client_id}/restructuring/#{product}/document.#{format}"
  )
end

#restructuring_info(client_id:, product:) ⇒ Object



308
309
310
# File 'lib/revo/loans_api/client.rb', line 308

def restructuring_info(client_id:, product:)
  make_request(:get, "clients/#{client_id}/restructuring/#{product}/info")
end

#send_billing_shift(client_id:, billing_chain:) ⇒ Object



264
265
266
267
268
269
270
# File 'lib/revo/loans_api/client.rb', line 264

def send_billing_shift(client_id:, billing_chain:)
  make_request(
    :post,
    "clients/#{client_id}/billing_shift",
    params: { billing_chain: billing_chain }
  )
end

#send_billing_shift_confirmation_code(client_id:) ⇒ Object



272
273
274
# File 'lib/revo/loans_api/client.rb', line 272

def send_billing_shift_confirmation_code(client_id:)
  make_request(:post, "clients/#{client_id}/billing_shift")
end

#send_loan_confirmation_message(token:) ⇒ Object



103
104
105
# File 'lib/revo/loans_api/client.rb', line 103

def send_loan_confirmation_message(token:)
  make_request(:post, "loan_requests/#{token}/client/confirmation")
end

#send_restructuring_confirmation_code(client_id:, product:) ⇒ Object



304
305
306
# File 'lib/revo/loans_api/client.rb', line 304

def send_restructuring_confirmation_code(client_id:, product:)
  make_request(:post, "clients/#{client_id}/restructuring/#{product}")
end

#send_return_confirmation_code(order_id:) ⇒ Object



175
176
177
# File 'lib/revo/loans_api/client.rb', line 175

def send_return_confirmation_code(order_id:)
  make_request(:post, "orders/#{order_id}/send_return_confirmation_code")
end

#start_self_registration(token:, mobile_phone:, skip_message: false, mobile_meta_info: {}) ⇒ Object



199
200
201
202
203
204
205
# File 'lib/revo/loans_api/client.rb', line 199

def start_self_registration(token:, mobile_phone:, skip_message: false, mobile_meta_info: {})
  make_request(
    :post,
    "loan_requests/#{token}/client/self_registration",
    params: { mobile_phone: mobile_phone, skip_message: skip_message, mobile_meta_info: mobile_meta_info }
  )
end

#store_document(store_id:, kind:, format: :pdf) ⇒ Object



355
356
357
358
359
360
# File 'lib/revo/loans_api/client.rb', line 355

def store_document(store_id:, kind:, format: :pdf)
  make_request(
    :get,
    "stores/#{store_id}/documents/#{kind}.#{format}"
  )
end

#suggest_address(id:, address:) ⇒ Object



394
395
396
# File 'lib/revo/loans_api/client.rb', line 394

def suggest_address(id:, address:)
  make_request(:get, "clients/#{id}/address", params: { address: address })
end

#update_client(id:, client_params:) ⇒ Object



225
226
227
# File 'lib/revo/loans_api/client.rb', line 225

def update_client(id:, client_params:)
  make_request(:patch, "clients/#{id}", params: { client: client_params })
end

#update_client_additional_services(client_id:, additional_services:) ⇒ Object



347
348
349
350
351
352
353
# File 'lib/revo/loans_api/client.rb', line 347

def update_client_additional_services(client_id:, additional_services:)
  make_request(
    :patch,
    "clients/#{client_id}/additional_services",
    params: additional_services
  )
end

#update_client_address(id:, address:) ⇒ Object



390
391
392
# File 'lib/revo/loans_api/client.rb', line 390

def update_client_address(id:, address:)
  make_request(:post, "clients/#{id}/address", params: { address: address })
end

#update_credit_facility(id:, fields:) ⇒ Object



402
403
404
# File 'lib/revo/loans_api/client.rb', line 402

def update_credit_facility(id:, fields:)
  make_request(:patch, "credit_facilities/#{id}", params: { fields: fields })
end

#update_loan_request(token:, options:) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/revo/loans_api/client.rb', line 60

def update_loan_request(token:, options:)
  update_params = { loan_request: options }
  response = make_request(
    :put,
    "loan_requests/#{token}",
    params: update_params
  )

  return response unless response.success?

  @loan_request_token = token
  terms = loan_request_terms
  return terms unless terms.success?

  Result.new(
    success?: true,
    response: {
      terms: terms.response[:loan_request]
    }
  )
end

#update_virtual_card(token:, term_id:) ⇒ Object



246
247
248
249
250
251
252
253
# File 'lib/revo/loans_api/client.rb', line 246

def update_virtual_card(token:, term_id:)
  make_request(
    :patch,
    "loan_requests/#{token}/virtual_card",
    params: { term_id: term_id },
    headers: { 'Application-Source': application_source }
  )
end