Class: KYCAID::Document

Inherits:
Response
  • Object
show all
Extended by:
Client
Defined in:
lib/kycaid/document.rb

Overview

Document is wrapper for KYCAID Documents endpoints.

Class Method Summary collapse

Methods included from Client

conn, file_payload, file_post, file_put, get, multipart_conn, patch, post, sandbox?

Methods inherited from Response

#handle_error, #initialize, respond

Constructor Details

This class inherits a constructor from KYCAID::Response

Class Method Details

.create(params) ⇒ Object

Creates :front_file and :back_file files (see File) and a document,referring to those files.

  • :applicant_id - required The applicant’s unique identificator that received in response of Applicant#create.

  • :type - required The document type. Valid values are: GOVERNMENT_ID, PASSPORT, DRIVERS_LICENSE, SELFIE_IMAGE,

ADDRESS_DOCUMENT, FINANCIAL_DOCUMENT, TAX_ID_NUMBER, REGISTRATION_COMPANY, COMPANY_LEGAL_ADDRESS, AUTHORISED_PERSON, COMPANY_OWNERSHIP.

  • :document_number - The unique number associated with document (e.g. passport number).

  • :issue_date - The issue date of the document. (ISO 8601, YYYY-MM-DD).

  • :expiry_date - The expiry date of the document. (ISO 8601, YYYY-MM-DD)

  • :front_file - nested param to create a file.

  • :back_file - nested param to create a file.

Front file and Back file are a Hash:

  • :tempfile - file to upload.

  • :file_extension - file’s extensions (f.e., .jpeg)

  • :file_name - filename.

Returns Response object, conatining document_id.



23
24
25
26
27
28
29
30
31
# File 'lib/kycaid/document.rb', line 23

def self.create(params)
  front_file_id = create_file(params[:front_file])
  back_file_id = create_file(params[:back_file])

  protected_params = params.slice(:applicant_id, :type, :document_number, :issue_date, :expiry_date)
                           .merge(front_side_id: front_file_id, back_side_id: back_file_id)

  respond(post("/documents", protected_params.compact))
end

.create_file(file) ⇒ Object



63
64
65
66
67
68
69
70
# File 'lib/kycaid/document.rb', line 63

def self.create_file(file)
  unless file.nil?
    front_file = file_params(file)
    return front_file unless front_file.errors.nil?

    front_file.file_id
  end
end

.file_params(params) ⇒ Object

A helper to create associated file before creating document. Return a File Response object.



55
56
57
58
59
60
61
# File 'lib/kycaid/document.rb', line 55

def self.file_params(params)
  KYCAID::File.create(
    tempfile: params[:tempfile],
    content_type: "image/#{params[:file_extension]}",
    original_filename: params[:file_name]
  )
end

.update(params) ⇒ Object

Update document, params is a Hash.

  • :type - see #create

  • :document_number - see #create

  • :issue_date - see #create

  • :expiry_date - see #create

Front file and Back file are a Hash:

  • :tempfile - file to upload.

  • :file_extension - file’s extensions (f.e., .jpeg)

  • :file_name - filename.

Returns Response object, conatining document_id.



44
45
46
47
48
49
50
51
# File 'lib/kycaid/document.rb', line 44

def self.update(params)
  front_file_id = create_file(params[:front_file])
  back_file_id = create_file(params[:back_file])

  protected_params = params.slice(:type, :document_number, :issue_date, :expiry_date)
                           .merge(front_side_id: front_file_id, back_side_id: back_file_id)
  respond(patch("/documents/#{params[:id]}", protected_params))
end