Class: MangoPay::KycDocument
- Defined in:
- lib/mangopay/kyc_document.rb
Overview
Class Method Summary collapse
- .consult_url(document_id) ⇒ Object
- .create(user_id, params, idempotency_key = nil) ⇒ Object
-
.create_documents_consult(document_id) ⇒ Object
Creates temporary URLs where each page of a KYC document can be viewed.
-
.create_page(user_id, document_id, file_content_base64, file_path = nil, idempotency_key = nil) ⇒ Object
Adds the file page (attachment) to the given document.
-
.fetch(user_id, document_id, idempotency_key = nil) ⇒ Object
Fetches the KYC document belonging to the given
user_id
, with the givendocument_id
. -
.fetch_all(user_id = nil, filters = {}) ⇒ Object
Fetches list of KYC documents: - for the particular user if
user_id
is provided (not nil) - or for all users otherwise. - .update(user_id, document_id, params = {}, idempotency_key = nil) ⇒ Object
- .url(user_id, document_id = nil) ⇒ Object
Methods inherited from Resource
Class Method Details
.consult_url(document_id) ⇒ Object
78 79 80 |
# File 'lib/mangopay/kyc_document.rb', line 78 def consult_url(document_id) "#{MangoPay.api_path}/KYC/documents/#{document_id}/consult" end |
.create(user_id, params, idempotency_key = nil) ⇒ Object
8 9 10 |
# File 'lib/mangopay/kyc_document.rb', line 8 def create(user_id, params, idempotency_key = nil) MangoPay.request(:post, url(user_id), params, {}, idempotency_key) end |
.create_documents_consult(document_id) ⇒ Object
Creates temporary URLs where each page of a KYC document can be viewed.
74 75 76 |
# File 'lib/mangopay/kyc_document.rb', line 74 def create_documents_consult(document_id) MangoPay.request(:post, consult_url(document_id), {}, {}) end |
.create_page(user_id, document_id, file_content_base64, file_path = nil, idempotency_key = nil) ⇒ Object
Adds the file page (attachment) to the given document.
See docs.mangopay.com/api-references/kyc/pages/ :
-
Document have to be in ‘CREATED’ Status
-
You can create as many pages as needed
-
Change Status to ‘VALIDATION_ASKED’ to submit KYC documents
The file_content_base64 param may be:
-
Base64 encoded file content
-
or nil: in this case pass the file path in the next param
48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/mangopay/kyc_document.rb', line 48 def create_page(user_id, document_id, file_content_base64, file_path = nil, idempotency_key = nil) if file_content_base64.nil? && !file_path.nil? bts = File.open(file_path, 'rb') { |f| f.read } file_content_base64 = Base64.encode64(bts) end # normally it returns 204 HTTP code on success begin MangoPay.request(:post, url(user_id, document_id) + '/pages', {'File' => file_content_base64}, {}, idempotency_key) rescue ResponseError => ex raise ex unless ex.code == '204' end end |
.fetch(user_id, document_id, idempotency_key = nil) ⇒ Object
Fetches the KYC document belonging to the given user_id
, with the given document_id
.
17 18 19 20 |
# File 'lib/mangopay/kyc_document.rb', line 17 def fetch(user_id, document_id, idempotency_key = nil) url = (user_id) ? url(user_id, document_id) : "#{MangoPay.api_path}/KYC/documents/#{CGI.escape(document_id.to_s)}" MangoPay.request(:get, url, {}, {}, idempotency_key) end |
.fetch_all(user_id = nil, filters = {}) ⇒ Object
Fetches list of KYC documents:
-
for the particular user if
user_id
is provided (not nil) -
or for all users otherwise.
Optional filters
is a hash accepting following keys:
-
page
,per_page
,sort
: pagination and sorting params (see MangoPay::HTTPCalls::Fetch::ClassMethods#fetch) -
filters such as
Type
(e.g. ‘IDENTITY_PROOF’) andStatus
(e.g. ‘VALIDATED’) -
BeforeDate
(timestamp): filters documents with CreationDate before this date -
AfterDate
(timestamp): filters documents with CreationDate after this date
32 33 34 35 |
# File 'lib/mangopay/kyc_document.rb', line 32 def fetch_all(user_id = nil, filters = {}) url = (user_id) ? url(user_id) : "#{MangoPay.api_path}/KYC/documents" MangoPay.request(:get, url, {}, filters) end |
.update(user_id, document_id, params = {}, idempotency_key = nil) ⇒ Object
12 13 14 |
# File 'lib/mangopay/kyc_document.rb', line 12 def update(user_id, document_id, params = {}, idempotency_key = nil) MangoPay.request(:put, url(user_id, document_id), params, {}, idempotency_key) end |
.url(user_id, document_id = nil) ⇒ Object
61 62 63 64 65 66 67 |
# File 'lib/mangopay/kyc_document.rb', line 61 def url(user_id, document_id = nil) if document_id "#{MangoPay.api_path}/users/#{CGI.escape(user_id.to_s)}/KYC/documents/#{CGI.escape(document_id.to_s)}" else "#{MangoPay.api_path}/users/#{CGI.escape(user_id.to_s)}/KYC/documents" end end |