assinafy 2.2.0 → 2.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +65 -4
- data/README.en.md +164 -1074
- data/README.md +31 -22
- data/docs/API_REFERENCE.md +189 -111
- data/docs/GUIDE.md +1079 -0
- data/lib/assinafy/client.rb +82 -45
- data/lib/assinafy/configuration.rb +8 -7
- data/lib/assinafy/oauth.rb +12 -15
- data/lib/assinafy/resources/account_resource.rb +13 -10
- data/lib/assinafy/resources/assignment_resource.rb +116 -94
- data/lib/assinafy/resources/base_resource.rb +66 -114
- data/lib/assinafy/resources/contract_resource.rb +17 -33
- data/lib/assinafy/resources/document_resource.rb +140 -57
- data/lib/assinafy/resources/envelope_resource.rb +57 -9
- data/lib/assinafy/resources/field_resource.rb +8 -17
- data/lib/assinafy/resources/oauth_resource.rb +26 -20
- data/lib/assinafy/resources/scheduled_send_resource.rb +127 -0
- data/lib/assinafy/resources/signer_document_resource.rb +24 -14
- data/lib/assinafy/resources/signer_resource.rb +51 -66
- data/lib/assinafy/resources/tag_resource.rb +16 -22
- data/lib/assinafy/resources/template_resource.rb +5 -6
- data/lib/assinafy/resources/user_resource.rb +7 -2
- data/lib/assinafy/resources/webhook_resource.rb +55 -47
- data/lib/assinafy/support/webhook_verifier.rb +2 -2
- data/lib/assinafy/utils.rb +14 -21
- data/lib/assinafy/validation.rb +80 -0
- data/lib/assinafy/version.rb +1 -1
- data/lib/assinafy.rb +2 -1
- data/sig/assinafy.rbs +24 -30
- metadata +7 -5
- data/lib/assinafy/resources/auth_resource.rb +0 -502
|
@@ -19,19 +19,20 @@ module Assinafy
|
|
|
19
19
|
#
|
|
20
20
|
# - `Email` — one-time code sent to the signer's email. Free.
|
|
21
21
|
# - `Whatsapp` — one-time code over WhatsApp. The verification itself is
|
|
22
|
-
# not billed, but it requires the WhatsApp notification channel,
|
|
23
|
-
#
|
|
22
|
+
# not billed, but it requires the WhatsApp notification channel, which
|
|
23
|
+
# costs 0.45 credits per signer (0.4 on Pro; paid subscriptions only).
|
|
24
24
|
# - `DigitalCertificate` — the signer signs with their own ICP-Brasil
|
|
25
25
|
# certificate (A1 or A3), producing a qualified PAdES signature.
|
|
26
26
|
# Requires the Digital Certificate feature, a CPF or CNPJ in the
|
|
27
27
|
# signer's `government_id`, and that the signer is alone in its signing
|
|
28
|
-
# step on a virtual assignment. Charged
|
|
29
|
-
# (breakdown code `SignatureDigitalCertificate`)
|
|
30
|
-
# certificate (an e-CPF, or an e-CNPJ naming them as legal
|
|
28
|
+
# step on a virtual assignment. Charged per certificate signer at the plan's price, on top of its
|
|
29
|
+
# notification (breakdown code `SignatureDigitalCertificate`); {#estimate_cost} returns the exact
|
|
30
|
+
# charge. A CPF requires that person's certificate (an e-CPF, or an e-CNPJ naming them as legal
|
|
31
31
|
# representative); a CNPJ requires an e-CNPJ for that company, from any
|
|
32
32
|
# of its representatives.
|
|
33
33
|
# - `IdDocumentFaceMatchBasic` — government ID photos, face match and liveness.
|
|
34
|
-
# Requires its account feature and a valid CPF in `government_id
|
|
34
|
+
# Requires its account feature and a valid CPF in `government_id`. Priced per signer by plan
|
|
35
|
+
# (Free 1.5, Standard 1, Pro 0.5, others 0.25 credits); use {#estimate_cost} for exact prices.
|
|
35
36
|
VERIFICATION_METHODS = %w[Email Whatsapp DigitalCertificate IdDocumentFaceMatchBasic].freeze
|
|
36
37
|
IDENTITY_REVIEW_IMAGES = %w[document_front document_back document_pdf face].freeze
|
|
37
38
|
|
|
@@ -40,20 +41,28 @@ module Assinafy
|
|
|
40
41
|
# subscriptions. When omitted it is inferred from `verification_method`
|
|
41
42
|
# (`Whatsapp` → `["Whatsapp"]`); when both are omitted it is `["Email"]`.
|
|
42
43
|
NOTIFICATION_METHODS = %w[Email Whatsapp].freeze
|
|
44
|
+
SIGNER_CAPACITIES = %w[
|
|
45
|
+
Sign Approve Acknowledge Party Witness Intervening Receipt IssuerEndorserGuarantor
|
|
46
|
+
IssuerEndorserGuarantorSurety Surety PartySurety JointDebtor PartyJointDebtor ContractingParty
|
|
47
|
+
ContractedParty Landlord Tenant Buyer Seller AttorneyInFact LegalRepresentative Employer Employee
|
|
48
|
+
].freeze
|
|
43
49
|
|
|
44
50
|
SIGN_ITEM_KEY_MAP = {
|
|
45
51
|
'item_id' => 'itemId',
|
|
46
52
|
'field_id' => 'fieldId',
|
|
47
|
-
'page_id' => 'pageId'
|
|
48
|
-
'value' => 'value'
|
|
53
|
+
'page_id' => 'pageId'
|
|
49
54
|
}.freeze
|
|
55
|
+
HOSTED_VERIFICATION_METHODS = %w[DigitalCertificate IdDocumentFaceMatchBasic].freeze
|
|
56
|
+
private_constant :HOSTED_VERIFICATION_METHODS
|
|
50
57
|
|
|
51
58
|
class << self
|
|
59
|
+
include Validation
|
|
60
|
+
|
|
52
61
|
# Normalise a flexible Ruby-side assignment payload into the body
|
|
53
62
|
# shape the API expects. Accepts:
|
|
54
63
|
#
|
|
55
64
|
# - `signers: ['id1', 'id2']` — bare IDs
|
|
56
|
-
# - `signers: [{ id:, verification_method:, notification_methods:, step: }]`
|
|
65
|
+
# - `signers: [{ id:, verification_method:, notification_methods:, step:, embedded:, sign_as: }]`
|
|
57
66
|
# - Legacy `signer_ids:`/`signerIds:` arrays of IDs
|
|
58
67
|
#
|
|
59
68
|
# @note Creation requires top-level `signers` for both methods, and `collect` additionally
|
|
@@ -64,7 +73,8 @@ module Assinafy
|
|
|
64
73
|
# payloads where method-only signer descriptors carry no id
|
|
65
74
|
# @option options [Boolean] :require_signers (true) false for collect estimates without signer IDs
|
|
66
75
|
# @option options [Boolean] :validate_steps (true) false when template role metadata is needed
|
|
67
|
-
# to distinguish signers from copy receivers;
|
|
76
|
+
# to distinguish signers from copy receivers; it also skips the check that a DigitalCertificate
|
|
77
|
+
# signer is alone in its step. Individual steps are always validated
|
|
68
78
|
# @return [Hash] string-keyed body suitable for {#create} / {#estimate_cost}
|
|
69
79
|
# @raise [Assinafy::ValidationError] on missing required fields
|
|
70
80
|
# @example Bare signer IDs are normalised into { id: } hashes (virtual method)
|
|
@@ -138,9 +148,7 @@ module Assinafy
|
|
|
138
148
|
private
|
|
139
149
|
|
|
140
150
|
def validate_method!(method, signers, entries, payload, require_signers)
|
|
141
|
-
|
|
142
|
-
raise ValidationError.new("Assignment method must be one of: #{METHODS.join(', ')}")
|
|
143
|
-
end
|
|
151
|
+
require_one_of(method, METHODS, 'Assignment method')
|
|
144
152
|
if signers.empty? && (require_signers || method == 'virtual')
|
|
145
153
|
raise ValidationError.new(
|
|
146
154
|
'At least one signer is required',
|
|
@@ -157,12 +165,10 @@ module Assinafy
|
|
|
157
165
|
# wrong type here would only fail server-side — after the caller has
|
|
158
166
|
# already uploaded a document and created signers.
|
|
159
167
|
def validate_optional_fields!(payload)
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
next if value.nil? || value.is_a?(String)
|
|
163
|
-
|
|
164
|
-
raise ValidationError.new("#{key} must be a String", { key => value })
|
|
168
|
+
unless payload[:message].nil? || payload[:message].is_a?(String)
|
|
169
|
+
raise ValidationError.new('message must be a String', { message: payload[:message] })
|
|
165
170
|
end
|
|
171
|
+
|
|
166
172
|
Utils.require_expiration(payload[:expires_at])
|
|
167
173
|
Utils.require_credit_ceiling(payload[:max_total_credits])
|
|
168
174
|
|
|
@@ -189,11 +195,9 @@ module Assinafy
|
|
|
189
195
|
end
|
|
190
196
|
|
|
191
197
|
page = Utils.body_params(entry)
|
|
192
|
-
|
|
198
|
+
require_string(page['page_id'], 'Collect page ID')
|
|
193
199
|
fields = page['fields']
|
|
194
|
-
|
|
195
|
-
raise ValidationError.new('Collect fields must be a non-empty Array')
|
|
196
|
-
end
|
|
200
|
+
raise ValidationError.new('Collect fields must be an Array') unless fields.is_a?(Array)
|
|
197
201
|
|
|
198
202
|
fields.map { |field| validate_collect_field!(field, signer_ids) }
|
|
199
203
|
end
|
|
@@ -205,7 +209,7 @@ module Assinafy
|
|
|
205
209
|
def validate_collect_field!(field, signer_ids)
|
|
206
210
|
raise ValidationError.new('Collect field must be a Hash') unless field.is_a?(Hash)
|
|
207
211
|
|
|
208
|
-
|
|
212
|
+
require_string(field['field_id'], 'Collect field ID')
|
|
209
213
|
unless signer_ids.include?(field['signer_id'])
|
|
210
214
|
raise ValidationError.new('Collect field signer must appear in signers')
|
|
211
215
|
end
|
|
@@ -222,12 +226,6 @@ module Assinafy
|
|
|
222
226
|
field['signer_id']
|
|
223
227
|
end
|
|
224
228
|
|
|
225
|
-
def require_payload_id!(value, name)
|
|
226
|
-
return if value.is_a?(String) && !value.strip.empty?
|
|
227
|
-
|
|
228
|
-
raise ValidationError.new("#{name} must be a non-empty String")
|
|
229
|
-
end
|
|
230
|
-
|
|
231
229
|
def extract_signer_refs(payload)
|
|
232
230
|
return payload[:signers] if payload[:signers].is_a?(Array) && !payload[:signers].empty?
|
|
233
231
|
|
|
@@ -236,34 +234,36 @@ module Assinafy
|
|
|
236
234
|
end
|
|
237
235
|
|
|
238
236
|
def normalise_signer_ref(ref, options)
|
|
239
|
-
return
|
|
237
|
+
return { id: require_string(ref, 'Signer ID') } if ref.is_a?(String)
|
|
240
238
|
return hash_signer_ref(ref, options) if ref.is_a?(Hash)
|
|
241
239
|
|
|
242
240
|
raise ValidationError.new('Invalid signer reference', { ref: ref })
|
|
243
241
|
end
|
|
244
242
|
|
|
245
|
-
def string_signer_ref(ref)
|
|
246
|
-
raise ValidationError.new('Signer ID cannot be empty') if ref.strip.empty?
|
|
247
|
-
|
|
248
|
-
{ id: ref }
|
|
249
|
-
end
|
|
250
|
-
|
|
251
243
|
def hash_signer_ref(ref, options)
|
|
252
244
|
r = ref.transform_keys(&:to_sym)
|
|
253
245
|
id = r[:id] || r[:signer_id]
|
|
254
246
|
|
|
247
|
+
normalised = { id: id }.compact.merge(signer_options(r))
|
|
248
|
+
|
|
249
|
+
return normalised if id.is_a?(String) && !id.strip.empty?
|
|
250
|
+
return normalised if id.nil? && options[:allow_signers_without_id]
|
|
251
|
+
|
|
252
|
+
raise ValidationError.new('Invalid signer reference', { ref: ref })
|
|
253
|
+
end
|
|
254
|
+
|
|
255
|
+
def signer_options(r)
|
|
255
256
|
normalised = {}
|
|
256
|
-
normalised[:id] = id if id
|
|
257
257
|
normalised[:verification_method] = verification_method!(r) unless r[:verification_method].nil?
|
|
258
258
|
normalised[:notification_methods] = notification_methods!(r) unless r[:notification_methods].nil?
|
|
259
259
|
normalised[:step] = signer_step!(r[:step]) unless r[:step].nil?
|
|
260
|
-
normalised[:embedded] = embedded_signer!(r)
|
|
260
|
+
normalised[:embedded] = embedded_signer!(r) unless r[:embedded].nil?
|
|
261
|
+
unless r[:sign_as].nil?
|
|
262
|
+
normalised[:sign_as] = require_one_of(r[:sign_as], SIGNER_CAPACITIES, 'sign_as')
|
|
263
|
+
end
|
|
261
264
|
validate_method_pair!(normalised)
|
|
262
265
|
|
|
263
|
-
|
|
264
|
-
return normalised if id.nil? && options[:allow_signers_without_id]
|
|
265
|
-
|
|
266
|
-
raise ValidationError.new('Invalid signer reference', { ref: ref })
|
|
266
|
+
normalised
|
|
267
267
|
end
|
|
268
268
|
|
|
269
269
|
# The API's enums are closed and it reports an unknown value as a 422
|
|
@@ -271,13 +271,7 @@ module Assinafy
|
|
|
271
271
|
# for it already exist. Checking locally keeps the failure cheap and
|
|
272
272
|
# names the accepted values.
|
|
273
273
|
def verification_method!(ref)
|
|
274
|
-
|
|
275
|
-
return value if VERIFICATION_METHODS.include?(value)
|
|
276
|
-
|
|
277
|
-
raise ValidationError.new(
|
|
278
|
-
"verification_method must be one of: #{VERIFICATION_METHODS.join(', ')}",
|
|
279
|
-
{ verification_method: value }
|
|
280
|
-
)
|
|
274
|
+
require_one_of(ref[:verification_method], VERIFICATION_METHODS, 'verification_method')
|
|
281
275
|
end
|
|
282
276
|
|
|
283
277
|
def notification_methods!(ref)
|
|
@@ -293,9 +287,8 @@ module Assinafy
|
|
|
293
287
|
end
|
|
294
288
|
|
|
295
289
|
def embedded_signer!(ref)
|
|
296
|
-
value = ref[:embedded]
|
|
297
|
-
|
|
298
|
-
if value && %w[DigitalCertificate IdDocumentFaceMatchBasic].include?(ref[:verification_method])
|
|
290
|
+
value = require_boolean(ref[:embedded], 'embedded')
|
|
291
|
+
if value && HOSTED_VERIFICATION_METHODS.include?(ref[:verification_method])
|
|
299
292
|
raise ValidationError.new('Embedded signing requires Email or Whatsapp verification')
|
|
300
293
|
end
|
|
301
294
|
|
|
@@ -311,8 +304,7 @@ module Assinafy
|
|
|
311
304
|
def validate_method_pair!(signer)
|
|
312
305
|
verification = signer[:verification_method]
|
|
313
306
|
notification = signer[:notification_methods]&.first
|
|
314
|
-
return if verification.nil? || notification.nil? ||
|
|
315
|
-
%w[DigitalCertificate IdDocumentFaceMatchBasic].include?(verification)
|
|
307
|
+
return if verification.nil? || notification.nil? || HOSTED_VERIFICATION_METHODS.include?(verification)
|
|
316
308
|
return if verification == notification
|
|
317
309
|
|
|
318
310
|
raise ValidationError.new('notification_methods must match the verification_method')
|
|
@@ -353,9 +345,10 @@ module Assinafy
|
|
|
353
345
|
|
|
354
346
|
# List assignments for an account. API keys need accountId; OAuth tokens can infer their workspace.
|
|
355
347
|
#
|
|
356
|
-
# @param params [Hash] documented `page` and `per_page` query parameters
|
|
348
|
+
# @param params [Hash] documented `sort`, `page` and `per_page` query parameters
|
|
357
349
|
# @param account_id_override [String, nil]
|
|
358
|
-
# @return [Hash{Symbol=>Array,Hash}] `{ data: [assignment, ...], meta: {..}
|
|
350
|
+
# @return [Hash{Symbol=>Array,Hash}] `{ data: [assignment, ...], meta: {..} }`; the `meta` key is
|
|
351
|
+
# left out, not nil, when the response carries no pagination headers
|
|
359
352
|
# @raise [Assinafy::ApiError] on an unsuccessful API response
|
|
360
353
|
# @raise [Assinafy::NetworkError] on transport or TLS failure
|
|
361
354
|
# @raise [Assinafy::ValidationError] on invalid required input
|
|
@@ -402,7 +395,8 @@ module Assinafy
|
|
|
402
395
|
# @param payload [Hash]
|
|
403
396
|
# @return [Hash] the assignment object (resource, id, method, expires_at, message, signers[],
|
|
404
397
|
# items[], summary{signer_count, completed_count, signers[]}, signing_urls[], copy_receivers[])
|
|
405
|
-
# @raise [Assinafy::ApiError] on an unsuccessful API response
|
|
398
|
+
# @raise [Assinafy::ApiError] on an unsuccessful API response; `429` (`FreePlanEmailLimit`, with
|
|
399
|
+
# Retry-After) once a free plan reaches its daily signer email limit
|
|
406
400
|
# @raise [Assinafy::NetworkError] on transport or TLS failure
|
|
407
401
|
# @raise [Assinafy::ValidationError] on invalid required input
|
|
408
402
|
# @see POST /documents/{documentId}/assignments
|
|
@@ -429,7 +423,7 @@ module Assinafy
|
|
|
429
423
|
# # "display_settings" => [], "value" => nil, "completed" => false }],
|
|
430
424
|
# # "summary" => { "signer_count" => 1, "completed_count" => 0, "signers" => [{ ... }] },
|
|
431
425
|
# # "signing_urls" => [{ "signer_id" => "signer-id",
|
|
432
|
-
# # "url" => "https://app
|
|
426
|
+
# # "url" => "https://app.assinafy.com.br/sign/document-id?email=signer%40example.com" }]
|
|
433
427
|
# # } # ... (see docs for full shape)
|
|
434
428
|
def create(document_id, payload)
|
|
435
429
|
doc_id = require_id(document_id, 'Document ID')
|
|
@@ -442,6 +436,33 @@ module Assinafy
|
|
|
442
436
|
end
|
|
443
437
|
end
|
|
444
438
|
|
|
439
|
+
# Schedule an assignment without creating or charging it now. Requires documents:write.
|
|
440
|
+
# @param document_id [String]
|
|
441
|
+
# @param payload [Hash] the same assignment payload as create, including sign_as when needed
|
|
442
|
+
# @param send_at [String, Integer] from one hour to 90 days ahead; absent offset means UTC
|
|
443
|
+
# @return [Hash] ScheduledSend; its deadline must be at least two hours after send_at
|
|
444
|
+
# @raise [ValidationError] on invalid IDs, payload or timing
|
|
445
|
+
# @raise [ApiError, NetworkError] on API or transport failure
|
|
446
|
+
# @see POST /documents/{documentId}/scheduled-sends
|
|
447
|
+
# @example
|
|
448
|
+
# client.assignments.schedule('document-id', { signers: ['signer-id'] },
|
|
449
|
+
# send_at: (Time.now + 7200).iso8601)
|
|
450
|
+
# # POST body: { "method": "virtual", "signers": [{ "id": "signer-id" }],
|
|
451
|
+
# # "send_at": "2026-12-01T12:00:00Z" }
|
|
452
|
+
# # => { 'resource' => 'scheduled_send', 'id' => 'send-id', 'type' => 'assignment',
|
|
453
|
+
# # 'document_ids' => ['document-id'], 'status' => 'pending', 'send_at' => '2026-12-01T12:00:00Z',
|
|
454
|
+
# # 'assignment_id' => nil, 'envelope_id' => nil, 'failure_reason' => nil,
|
|
455
|
+
# # 'next_attempt_at' => nil,
|
|
456
|
+
# # 'created_at' => '2026-12-01T10:00:00Z', 'processed_at' => nil }
|
|
457
|
+
def schedule(document_id, payload, send_at:)
|
|
458
|
+
id = require_id(document_id, 'Document ID')
|
|
459
|
+
time = ScheduledSendResource.require_send_at(send_at)
|
|
460
|
+
raw = require_payload(payload).transform_keys(&:to_s)
|
|
461
|
+
raw['expires_at'] = ScheduledSendResource.scheduled_expiration(raw['expires_at'], time)
|
|
462
|
+
body = self.class.build_payload(raw).merge('send_at' => send_at)
|
|
463
|
+
call('Failed to schedule assignment') { http_post("documents/#{id}/scheduled-sends", body) }
|
|
464
|
+
end
|
|
465
|
+
|
|
445
466
|
# Estimate the credit cost of a potential assignment, without creating it.
|
|
446
467
|
# Accepts the same payload as {#create}, but signer descriptors may omit
|
|
447
468
|
# `id`. An empty descriptor (`{}`) defaults both methods to `Email`.
|
|
@@ -533,16 +554,13 @@ module Assinafy
|
|
|
533
554
|
# # (no request body)
|
|
534
555
|
# # => { "is_sent" => true, "document_id" => "document-id", "signer_id" => "signer-id" }
|
|
535
556
|
def resend_notification(document_id, assignment_id, signer_id)
|
|
536
|
-
|
|
537
|
-
asg_id = require_id(assignment_id, 'Assignment ID')
|
|
538
|
-
sid = require_id(signer_id, 'Signer ID')
|
|
557
|
+
path = signer_path(document_id, assignment_id, signer_id)
|
|
539
558
|
|
|
540
|
-
call('Failed to resend signer notification')
|
|
541
|
-
http_put("documents/#{doc_id}/assignments/#{asg_id}/signers/#{sid}/resend")
|
|
542
|
-
end
|
|
559
|
+
call('Failed to resend signer notification') { http_put("#{path}/resend") }
|
|
543
560
|
end
|
|
544
561
|
|
|
545
562
|
# Estimate the credit cost of resending the notification to a signer.
|
|
563
|
+
# Does not check deadline or reminder frequency eligibility.
|
|
546
564
|
#
|
|
547
565
|
# @param document_id [String]
|
|
548
566
|
# @param assignment_id [String]
|
|
@@ -563,13 +581,9 @@ module Assinafy
|
|
|
563
581
|
# # "has_sufficient_credits" => true
|
|
564
582
|
# # }
|
|
565
583
|
def estimate_resend_cost(document_id, assignment_id, signer_id)
|
|
566
|
-
|
|
567
|
-
asg_id = require_id(assignment_id, 'Assignment ID')
|
|
568
|
-
sid = require_id(signer_id, 'Signer ID')
|
|
584
|
+
path = signer_path(document_id, assignment_id, signer_id)
|
|
569
585
|
|
|
570
|
-
call('Failed to estimate resend cost')
|
|
571
|
-
http_post("documents/#{doc_id}/assignments/#{asg_id}/signers/#{sid}/estimate-resend-cost")
|
|
572
|
-
end
|
|
586
|
+
call('Failed to estimate resend cost') { http_post("#{path}/estimate-resend-cost") }
|
|
573
587
|
end
|
|
574
588
|
|
|
575
589
|
# Read the account review of a signer's biometric identity verification.
|
|
@@ -597,7 +611,7 @@ module Assinafy
|
|
|
597
611
|
# # 'ruleset_version' => '2026-10-12.2', 'evidence_sha256' => 'sha256-placeholder',
|
|
598
612
|
# # 'reviewed_by' => nil, 'reviewed_at' => nil, 'review_note' => nil, 'completed_at' => nil }
|
|
599
613
|
def identity_review(document_id, assignment_id, signer_id)
|
|
600
|
-
path =
|
|
614
|
+
path = "#{signer_path(document_id, assignment_id, signer_id)}/identity-verification"
|
|
601
615
|
|
|
602
616
|
call('Failed to fetch signer identity review') { http_get(path) }
|
|
603
617
|
end
|
|
@@ -613,15 +627,14 @@ module Assinafy
|
|
|
613
627
|
# @raise [Assinafy::ApiError] on failure; 404 after a decision or when evidence is unavailable
|
|
614
628
|
# @raise [Assinafy::NetworkError] on transport or TLS failure
|
|
615
629
|
# @raise [Assinafy::ValidationError] on invalid IDs or image name
|
|
616
|
-
# @see GET
|
|
630
|
+
# @see GET
|
|
631
|
+
# /documents/{documentId}/assignments/{assignmentId}/signers/{signerId}/identity-verification/images/{name}
|
|
617
632
|
# @example Read the face image (no request body; workspace credentials)
|
|
618
633
|
# client.assignments.identity_review_image('document-id', 'assignment-id', 'signer-id', 'face')
|
|
619
634
|
# # => "\x89PNG\r\n\x1A\n..." # binary String
|
|
620
635
|
def identity_review_image(document_id, assignment_id, signer_id, name)
|
|
621
|
-
path =
|
|
622
|
-
|
|
623
|
-
raise ValidationError.new("Image name must be one of: #{IDENTITY_REVIEW_IMAGES.join(', ')}")
|
|
624
|
-
end
|
|
636
|
+
path = "#{signer_path(document_id, assignment_id, signer_id)}/identity-verification"
|
|
637
|
+
require_one_of(name, IDENTITY_REVIEW_IMAGES, 'Image name')
|
|
625
638
|
|
|
626
639
|
call_binary('Failed to download signer identity review image') { http_get("#{path}/images/#{name}") }
|
|
627
640
|
end
|
|
@@ -648,10 +661,8 @@ module Assinafy
|
|
|
648
661
|
# # 'reviewed_by' => { 'id' => 'user-id', 'name' => 'Example Reviewer' },
|
|
649
662
|
# # 'reviewed_at' => '2026-10-16T12:00:00Z', 'review_note' => 'Identity checked'
|
|
650
663
|
def decide_identity_review(document_id, assignment_id, signer_id, decision:, note: nil)
|
|
651
|
-
path =
|
|
652
|
-
|
|
653
|
-
raise ValidationError.new('Decision must be Approved or Rejected')
|
|
654
|
-
end
|
|
664
|
+
path = "#{signer_path(document_id, assignment_id, signer_id)}/identity-verification"
|
|
665
|
+
require_one_of(decision, %w[Approved Rejected], 'Decision')
|
|
655
666
|
unless note.nil? || (note.is_a?(String) && note.length <= 2000)
|
|
656
667
|
raise ValidationError.new('Review note must be a String of at most 2000 characters')
|
|
657
668
|
end
|
|
@@ -676,13 +687,9 @@ module Assinafy
|
|
|
676
687
|
# # => { 'url' => 'https://app.assinafy.com.br/embed/session-token',
|
|
677
688
|
# # 'expires_at' => '2026-11-11T12:05:00Z' }
|
|
678
689
|
def create_embed_session(document_id, assignment_id, signer_id)
|
|
679
|
-
|
|
680
|
-
asg_id = require_id(assignment_id, 'Assignment ID')
|
|
681
|
-
sid = require_id(signer_id, 'Signer ID')
|
|
690
|
+
path = signer_path(document_id, assignment_id, signer_id)
|
|
682
691
|
|
|
683
|
-
call('Failed to create embed session')
|
|
684
|
-
http_post("documents/#{doc_id}/assignments/#{asg_id}/signers/#{sid}/embed-sessions")
|
|
685
|
-
end
|
|
692
|
+
call('Failed to create embed session') { http_post("#{path}/embed-sessions") }
|
|
686
693
|
end
|
|
687
694
|
|
|
688
695
|
# Exchange the token on Assinafy's embed page. Integrations normally load the session URL instead.
|
|
@@ -735,12 +742,21 @@ module Assinafy
|
|
|
735
742
|
# # "thumbnail" => "https://.../thumbnail" },
|
|
736
743
|
# # "is_closed" => false, "signing_url" => "%ui_base_url%/sign/doc1",
|
|
737
744
|
# # "decline_reason" => nil, "declined_by" => nil,
|
|
745
|
+
# # "is_signer_access_closed" => false,
|
|
746
|
+
# # "certified_copy" => { "available" => false, "notification_method" => "Email",
|
|
747
|
+
# # "resends_left" => nil },
|
|
738
748
|
# # "current_signer" => { "id" => "signer-id", "full_name" => "Signer Name",
|
|
739
|
-
# # "email" => "signer@example.com", "has_accepted_terms" => false,
|
|
749
|
+
# # "email" => "signer@example.com", "has_accepted_terms" => false, "completed" => false,
|
|
740
750
|
# # "verification_method" => "Email", "notification_methods" => ["Email"] },
|
|
741
751
|
# # "assignment" => { "id" => "1", "method" => "virtual", "expires_at" => nil,
|
|
742
752
|
# # "items" => [{ "id" => "assignment-item-id", "field" => { "type" => "virtual" }, ... }] }
|
|
743
753
|
# # } # ... (see docs for full shape)
|
|
754
|
+
# # Once the signer's access has closed, only the status remains:
|
|
755
|
+
# # => { "id" => "document-id", "name" => "my_document.pdf", "status" => "certificated",
|
|
756
|
+
# # "is_signer_access_closed" => true,
|
|
757
|
+
# # "certified_copy" => { "available" => true, "notification_method" => "Email",
|
|
758
|
+
# # "resends_left" => nil },
|
|
759
|
+
# # "current_signer" => { "completed" => true } }
|
|
744
760
|
def signer_document(signer_access_code:, has_accepted_terms: nil, expand: nil, document_id: nil)
|
|
745
761
|
access_code = require_signer_access_code(signer_access_code)
|
|
746
762
|
accepted = has_accepted_terms.nil? ? nil : require_boolean(has_accepted_terms, 'has_accepted_terms')
|
|
@@ -756,6 +772,8 @@ module Assinafy
|
|
|
756
772
|
end
|
|
757
773
|
|
|
758
774
|
# Submit signatures for an assignment as a signer.
|
|
775
|
+
# Virtual assignments send []; collect requires stored signature and initial images.
|
|
776
|
+
# Omitted read-only/optional collect fields are filled or left empty by the API.
|
|
759
777
|
#
|
|
760
778
|
# The API uses camelCase for this body. Callers may pass snake_case
|
|
761
779
|
# (`item_id`, `field_id`, `page_id`, `value`) — this method maps them
|
|
@@ -763,9 +781,10 @@ module Assinafy
|
|
|
763
781
|
#
|
|
764
782
|
# @param document_id [String]
|
|
765
783
|
# @param assignment_id [String]
|
|
766
|
-
# @param items [Array<Hash>]
|
|
784
|
+
# @param items [Array<Hash>] [] for virtual; the API validates required collect values
|
|
767
785
|
# @param signer_access_code [String]
|
|
768
|
-
# @return [Hash]
|
|
786
|
+
# @return [Hash] signing result: the signer's assignment with only their items,
|
|
787
|
+
# without signing URLs or other parties' contact details and government IDs
|
|
769
788
|
# @raise [Assinafy::ApiError] on an unsuccessful API response
|
|
770
789
|
# @raise [Assinafy::NetworkError] on transport or TLS failure
|
|
771
790
|
# @raise [Assinafy::ValidationError] on invalid required input
|
|
@@ -778,11 +797,14 @@ module Assinafy
|
|
|
778
797
|
# # Request body the SDK sends (snake_case keys mapped to camelCase):
|
|
779
798
|
# # [{ "itemId" => "assignment-item-id", "fieldId" => "field-id",
|
|
780
799
|
# # "pageId" => "page-id", "value" => "Signed by Example Signer" }]
|
|
781
|
-
# # => {
|
|
800
|
+
# # => { 'resource' => 'assignment', 'id' => 'assignment-id', 'document_id' => 'document-id',
|
|
801
|
+
# # 'method' => 'collect', 'items' => [{ 'id' => 'assignment-item-id', 'completed' => true, ... }], ... }
|
|
782
802
|
def sign(document_id, assignment_id, items, signer_access_code:)
|
|
783
803
|
doc_id = require_id(document_id, 'Document ID')
|
|
784
804
|
asg_id = require_id(assignment_id, 'Assignment ID')
|
|
785
|
-
|
|
805
|
+
raise ValidationError.new('Assignment items must be an Array') unless items.is_a?(Array)
|
|
806
|
+
|
|
807
|
+
body = items.map { |item| normalise_sign_item(item) }
|
|
786
808
|
access_code = require_signer_access_code(signer_access_code)
|
|
787
809
|
|
|
788
810
|
call('Failed to sign assignment') do
|
|
@@ -854,11 +876,11 @@ module Assinafy
|
|
|
854
876
|
|
|
855
877
|
private
|
|
856
878
|
|
|
857
|
-
def
|
|
879
|
+
def signer_path(document_id, assignment_id, signer_id)
|
|
858
880
|
doc_id = require_id(document_id, 'Document ID')
|
|
859
881
|
asg_id = require_id(assignment_id, 'Assignment ID')
|
|
860
882
|
sid = require_id(signer_id, 'Signer ID')
|
|
861
|
-
"documents/#{doc_id}/assignments/#{asg_id}/signers/#{sid}
|
|
883
|
+
"documents/#{doc_id}/assignments/#{asg_id}/signers/#{sid}"
|
|
862
884
|
end
|
|
863
885
|
|
|
864
886
|
def normalise_sign_item(item)
|
|
@@ -870,7 +892,7 @@ module Assinafy
|
|
|
870
892
|
%w[itemId fieldId pageId].each do |key|
|
|
871
893
|
require_id(normalised[key], "Assignment item #{key}")
|
|
872
894
|
end
|
|
873
|
-
value =
|
|
895
|
+
value = normalised['value']
|
|
874
896
|
raise ValidationError.new('Assignment item value must be a String') unless value.is_a?(String)
|
|
875
897
|
|
|
876
898
|
normalised
|