|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace ViniciusRBezerra\Autentique; |
|
4
|
|
|
|
|
5
|
|
|
use CURLFile; |
|
6
|
|
|
|
|
7
|
|
|
class Document extends Autentique |
|
8
|
|
|
{ |
|
9
|
|
|
|
|
10
|
|
|
public function __construct() |
|
11
|
|
|
{ |
|
12
|
|
|
parent::__construct(); |
|
13
|
|
|
} |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* @param string $name |
|
17
|
|
|
* @param array $signers |
|
18
|
|
|
* @param string $file |
|
19
|
|
|
* @return $this |
|
20
|
|
|
*/ |
|
21
|
|
|
public function createDocument(string $name, array $signers, string $file): Autentique |
|
22
|
|
|
{ |
|
23
|
|
|
$data["query"] = 'mutation CreateDocumentMutation($document: DocumentInput!, $signers: [SignerInput!]!, $file: Upload!) {createDocument(sandbox: '.($this->devMode ? 'true' : 'false').', document: $document, signers: $signers, file: $file) {id name refusable sortable created_at signatures { public_id name email created_at action { name } link { short_link } user { id name email }}}}'; |
|
|
|
|
|
|
24
|
|
|
$data["variables"] = [ |
|
25
|
|
|
"document" => ["name" => $name], |
|
26
|
|
|
"signers" => $signers, |
|
27
|
|
|
"file" => null |
|
28
|
|
|
]; |
|
29
|
|
|
|
|
30
|
|
|
$this->data->operations = json_encode($data); |
|
31
|
|
|
$this->data->map = '{"file": ["variables.file"]}'; |
|
32
|
|
|
$this->data->file = new CURLFile($file); |
|
33
|
|
|
|
|
34
|
|
|
$this->execute(false); |
|
35
|
|
|
return $this; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @param string $documentId |
|
40
|
|
|
* @return object |
|
41
|
|
|
*/ |
|
42
|
|
|
public function document(string $documentId): object |
|
43
|
|
|
{ |
|
44
|
|
|
$this->data->query = "query { document(id: \"{$documentId}\") { id name refusable sortable created_at files { original signed } signatures { public_id name email created_at action { name } link { short_link } user { id name email } email_events { sent opened delivered refused reason } viewed { ...event } signed { ...event } rejected { ...event } } } } fragment event on Event { ipv4 ipv6 reason created_at geolocation { country countryISO state stateISO city zipcode latitude longitude } }"; |
|
45
|
|
|
$this->execute(); |
|
46
|
|
|
return $this->callback(); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* @param int|null $limit |
|
51
|
|
|
* @return object |
|
52
|
|
|
*/ |
|
53
|
|
|
public function documents(?int $limit = null): object |
|
54
|
|
|
{ |
|
55
|
|
|
$limit = empty($limit) ? 60 : $limit; |
|
56
|
|
|
$this->data->query = "query { documents(limit: {$limit}, page: 1) { total data { id name refusable sortable created_at signatures { public_id name email created_at action { name } link { short_link } user { id name email } viewed { created_at } signed { created_at } rejected { created_at } } files { original signed } } } }"; |
|
57
|
|
|
$this->execute(); |
|
58
|
|
|
return $this->callback(); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* @param string $documentId |
|
63
|
|
|
* @return $this |
|
64
|
|
|
*/ |
|
65
|
|
|
public function deleteDocument(string $documentId): Autentique |
|
66
|
|
|
{ |
|
67
|
|
|
$this->data->query = "mutation { deleteDocument(id: \"{$documentId}\") }"; |
|
68
|
|
|
$this->execute(); |
|
69
|
|
|
return $this; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* @param string $document |
|
74
|
|
|
* @return $this |
|
75
|
|
|
*/ |
|
76
|
|
|
public function signDocument(string $document): Autentique |
|
77
|
|
|
{ |
|
78
|
|
|
$this->data->query = "mutation { signDocument(id: \"{$document}\") }"; |
|
79
|
|
|
$this->execute(); |
|
80
|
|
|
return $this; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
} |