Class: Sumsub::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/sumsub/request.rb

Constant Summary collapse

PRODUCTION_URL =
"https://api.sumsub.com"
TEST_URL =
"https://test-api.sumsub.com"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(token: Sumsub.configuration.token, secret_key: Sumsub.configuration.secret_key, production: Sumsub.configuration.production) ⇒ Request

Returns a new instance of Request.



10
11
12
13
14
15
16
17
18
# File 'lib/sumsub/request.rb', line 10

def initialize(
  token: Sumsub.configuration.token, 
  secret_key: Sumsub.configuration.secret_key,
  production: Sumsub.configuration.production
)
  @token = token
  @secret_key = secret_key
  @url = production ? PRODUCTION_URL : TEST_URL
end

Instance Attribute Details

#secret_keyObject (readonly)

Returns the value of attribute secret_key.



8
9
10
# File 'lib/sumsub/request.rb', line 8

def secret_key
  @secret_key
end

#tokenObject (readonly)

Returns the value of attribute token.



8
9
10
# File 'lib/sumsub/request.rb', line 8

def token
  @token
end

#urlObject (readonly)

Returns the value of attribute url.



8
9
10
# File 'lib/sumsub/request.rb', line 8

def url
  @url
end

Instance Method Details

#add_id_doc(applicant_id, metadata, file_path: nil) ⇒ Object

API docs: developers.sumsub.com/api-reference/#adding-an-id-document To understand how the body was build manually bellow: roytuts.com/boundary-in-multipart-form-data/ Sumsub::Struct::DocumentMetadata can be used as metadata.



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
62
63
64
65
66
67
68
69
# File 'lib/sumsub/request.rb', line 34

def add_id_doc(applicant_id, , file_path: nil)
  resource = "applicants/#{applicant_id}/info/idDoc"

  boundary = '----XYZ'

  body = + '--' + boundary + "\r\n"
  body += 'Content-Disposition: form-data; name="metadata"'
  body += "\r\nContent-type: application/json; charset=utf-8\r\n\r\n"
  body += .to_json
  body += "\r\n"
  body += '--' + boundary

  if file_path
    content = File.read(file_path)
    file_name = File.basename(file_path)
    content_type = MIME::Types.type_for(file_name).first.content_type

    body += "\r\n" 
    body += 'Content-Disposition: form-data; name="content"; filename="' + file_name + '"'
    body += "\r\nContent-type: #{content_type}; charset=utf-8\r\n\r\n"
    body += content + "\r\n"
    body += '--' + boundary + '--'
  else
    body += '--'
  end

  headers = build_header(
    resource, 
    body: body, 
    content_type: 'multipart/form-data; boundary=' + boundary
  ).merge({ "X-Return-Doc-Warnings": true })
  response = HTTP.headers(headers)
                 .post("#{@url}/resources/#{resource}", body: body)

  parse_response(response)
end

#change_applicant_top_level_info(applicant_new_values) ⇒ Object

API docs: developers.sumsub.com/api-reference/#changing-top-level-info Sumsub::Struct::ApplicantUpdate can be used as applicant_new_values.



135
136
137
138
139
140
141
142
# File 'lib/sumsub/request.rb', line 135

def change_applicant_top_level_info(applicant_new_values)
  resource = "applicants/"
  headers = build_header(resource, method: 'PATCH', body: applicant_new_values.to_json)
  response = HTTP.headers(headers)
                 .patch("#{@url}/resources/#{resource}", json: applicant_new_values)

  parse_response(response)
end

#create_applicant(level_name, applicant) ⇒ Object

API docs: developers.sumsub.com/api-reference/#creating-an-applicant Sumsub::Struct::Applicant can be used as applicant.



22
23
24
25
26
27
28
29
# File 'lib/sumsub/request.rb', line 22

def create_applicant(level_name, applicant)
  resource = "applicants?levelName=#{level_name}"
  headers = build_header(resource, body: applicant.to_json)
  response = HTTP.headers(headers)
                 .post("#{@url}/resources/#{resource}", json: applicant)
  
  parse_response(response)
end


185
186
187
188
189
190
191
192
193
# File 'lib/sumsub/request.rb', line 185

def generate_external_link(level_name, ttl_in_seconds, external_user_id, locale: nil, body: {})
  resource = "sdkIntegrations/levels/#{level_name}/websdkLink?ttlInSecs=#{ttl_in_seconds}&externalUserId=#{external_user_id}&lang=#{locale}"
  headers = build_header(resource, method: 'POST', body: body.to_json)

  response = HTTP.headers(headers)
                 .post("#{@url}/resources/#{resource}", json: body)

  parse_response(response)
end

#get_access_token(user_id, level_name, ttl_in_seconds: nil, external_action_id: nil) ⇒ Object



145
146
147
148
149
150
151
152
# File 'lib/sumsub/request.rb', line 145

def get_access_token(user_id, level_name, ttl_in_seconds: nil, external_action_id: nil)
  resource = "accessTokens?userId=#{user_id}&levelName=#{level_name}&ttlInSecs=#{ttl_in_seconds}&external_action_id=#{external_action_id}"
  headers = build_header(resource, method: 'POST')
  response = HTTP.headers(headers)
                 .post("#{@url}/resources/#{resource}")

  parse_response(response)
end

#get_applicant_data(applicant_id, as_external_user_id: false) ⇒ Object



82
83
84
85
86
87
88
89
90
91
# File 'lib/sumsub/request.rb', line 82

def get_applicant_data(applicant_id, as_external_user_id: false) 
  resource = as_external_user_id ? 
    "applicants/-;externalUserId=#{applicant_id}/one" : 
    "applicants/#{applicant_id}/one"
  headers = build_header(resource, method: 'GET')
  response = HTTP.headers(headers)
                 .get("#{@url}/resources/#{resource}")

  parse_response(response)
end

#get_applicant_detailed_status(applicant_id) ⇒ Object



72
73
74
75
76
77
78
79
# File 'lib/sumsub/request.rb', line 72

def get_applicant_detailed_status(applicant_id)
  resource = "applicants/#{applicant_id}/requiredIdDocsStatus"
  headers = build_header(resource, method: 'GET')
  response = HTTP.headers(headers)
                 .get("#{@url}/resources/#{resource}")

  parse_response(response)
end

#get_applicant_status(applicant_id) ⇒ Object



94
95
96
97
98
99
100
101
# File 'lib/sumsub/request.rb', line 94

def get_applicant_status(applicant_id) 
  resource = "applicants/#{applicant_id}/status"
  headers = build_header(resource, method: 'GET')
  response = HTTP.headers(headers)
                 .get("#{@url}/resources/#{resource}")
  
  parse_response(response)
end

#get_document_image(inspection_id, image_id) ⇒ Object



114
115
116
117
118
119
120
121
# File 'lib/sumsub/request.rb', line 114

def get_document_image(inspection_id, image_id)
  resource = "inspections/#{inspection_id}/resources/#{image_id}"
  headers = build_header(resource, method: 'GET')
  response = HTTP.headers(headers)
                 .get("#{@url}/resources/#{resource}")

  parse_response(response)
end

#request_applicant_check(applicant_id, reason: nil) ⇒ Object



104
105
106
107
108
109
110
111
# File 'lib/sumsub/request.rb', line 104

def request_applicant_check(applicant_id, reason: nil)
  resource = "applicants/#{applicant_id}/status/pending?reason=#{reason}"
  headers = build_header(resource)
  response = HTTP.headers(headers)
                 .post("#{@url}/resources/#{resource}")
  
  parse_response(response)
end

#reset_applicant(applicant_id) ⇒ Object



124
125
126
127
128
129
130
131
# File 'lib/sumsub/request.rb', line 124

def reset_applicant(applicant_id)
  resource = "applicants/#{applicant_id}/reset"
  headers = build_header(resource)
  response = HTTP.headers(headers)
                 .post("#{@url}/resources/#{resource}")

  parse_response(response)
end

#testing_on_test_environment(applicant_id, review_result) ⇒ Object

API docs: developers.sumsub.com/api-reference/#testing-on-the-test-environment Sumsub::Struct::Applicant can be used as review_result.



156
157
158
159
160
161
162
163
# File 'lib/sumsub/request.rb', line 156

def testing_on_test_environment(applicant_id, review_result)
  resource = "applicants/#{applicant_id}/status/testCompleted"
  headers = build_header(resource, body: review_result.to_json)
  response = HTTP.headers(headers)
                 .post("#{@url}/resources/#{resource}", json: review_result)

  parse_response(response)
end

#verify_webhook_sender(webhook_secret_key, payload) ⇒ Object

API docs: developers.sumsub.com/api-reference/#verifying-webhook-sender Your payload need to be informed as a string.



167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
# File 'lib/sumsub/request.rb', line 167

def verify_webhook_sender(webhook_secret_key, payload)
  resource = "inspectionCallbacks/testDigest?secretKey=#{webhook_secret_key}"
  headers = build_header(
    resource, 
    method: 'POST', 
    content_type: 'text/plain',
    accept: 'text/plain',
    body: payload
  )

  response = HTTP.headers(headers)
                 .post("#{@url}/resources/#{resource}", body: payload)

  parse_response(response)
end