1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace DigitalCz\DigiSign\Endpoint; |
6
|
|
|
|
7
|
|
|
use DigitalCz\DigiSign\DigiSign; |
8
|
|
|
use DigitalCz\DigiSign\Endpoint\Traits\CRUDEndpointTrait; |
9
|
|
|
use DigitalCz\DigiSign\Resource\BaseResource; |
10
|
|
|
use DigitalCz\DigiSign\Resource\Envelope; |
11
|
|
|
use DigitalCz\DigiSign\Resource\EnvelopeTemplate; |
12
|
|
|
use DigitalCz\DigiSign\Stream\FileResponse; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @extends ResourceEndpoint<Envelope> |
16
|
|
|
* @method Envelope get(string $id) |
17
|
|
|
* @method Envelope create(array $body) |
18
|
|
|
* @method Envelope update(string $id, array $body) |
19
|
|
|
*/ |
20
|
|
|
final class EnvelopesEndpoint extends ResourceEndpoint |
21
|
|
|
{ |
22
|
|
|
/** @use CRUDEndpointTrait<Envelope> */ |
23
|
|
|
use CRUDEndpointTrait; |
24
|
|
|
|
25
|
|
|
public function __construct(DigiSign $parent) |
26
|
|
|
{ |
27
|
|
|
parent::__construct($parent, '/api/envelopes', Envelope::class); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @param Envelope|string $envelope |
32
|
|
|
*/ |
33
|
|
|
public function documents($envelope): EnvelopeDocumentsEndpoint |
34
|
|
|
{ |
35
|
|
|
return new EnvelopeDocumentsEndpoint($this, $envelope); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @param Envelope|string $envelope |
40
|
|
|
*/ |
41
|
|
|
public function recipients($envelope): EnvelopeRecipientsEndpoint |
42
|
|
|
{ |
43
|
|
|
return new EnvelopeRecipientsEndpoint($this, $envelope); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @param Envelope|string $envelope |
48
|
|
|
*/ |
49
|
|
|
public function tags($envelope): EnvelopeTagsEndpoint |
50
|
|
|
{ |
51
|
|
|
return new EnvelopeTagsEndpoint($this, $envelope); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @param Envelope|string $envelope |
56
|
|
|
*/ |
57
|
|
|
public function notifications($envelope): EnvelopeNotificationsEndpoint |
58
|
|
|
{ |
59
|
|
|
return new EnvelopeNotificationsEndpoint($this, $envelope); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @param Envelope|string $envelope |
64
|
|
|
*/ |
65
|
|
|
public function labels($envelope): EnvelopeLabelsEndpoint |
66
|
|
|
{ |
67
|
|
|
return new EnvelopeLabelsEndpoint($this, $envelope); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function cancel(string $id): BaseResource |
71
|
|
|
{ |
72
|
|
|
return $this->createResource($this->postRequest('/{id}/cancel', ['id' => $id])); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
public function count(): BaseResource |
76
|
|
|
{ |
77
|
|
|
return $this->createResource($this->getRequest('/count')); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @param mixed[] $query |
82
|
|
|
*/ |
83
|
|
|
public function download(string $id, array $query = []): FileResponse |
84
|
|
|
{ |
85
|
|
|
return $this->stream(self::METHOD_GET, '/{id}/download', ['id' => $id, 'query' => $query]); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @param mixed[] $body |
90
|
|
|
*/ |
91
|
|
|
public function embedEdit(string $id, array $body = []): BaseResource |
92
|
|
|
{ |
93
|
|
|
return $this->createResource($this->postRequest('/{id}/embed/edit', ['id' => $id, 'json' => $body])); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @param mixed[] $body |
98
|
|
|
*/ |
99
|
|
|
public function embedSigning(string $id, array $body = []): BaseResource |
100
|
|
|
{ |
101
|
|
|
return $this->createResource($this->postRequest('/{id}/embed/signing', ['id' => $id, 'json' => $body])); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* @param mixed[] $body |
106
|
|
|
*/ |
107
|
|
|
public function extend(string $id, array $body): Envelope |
108
|
|
|
{ |
109
|
|
|
return $this->makeResource($this->putRequest('/{id}/extend', ['id' => $id, 'json' => $body])); |
|
|
|
|
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
public function send(string $id): BaseResource |
113
|
|
|
{ |
114
|
|
|
return $this->createResource($this->postRequest('/{id}/send', ['id' => $id])); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
public function resend(string $id): BaseResource |
118
|
|
|
{ |
119
|
|
|
return $this->createResource($this->postRequest('/{id}/resend', ['id' => $id])); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* @param Envelope|string $id |
124
|
|
|
*/ |
125
|
|
|
public function template($id): EnvelopeTemplate |
126
|
|
|
{ |
127
|
|
|
return $this->createResource($this->getRequest('/{id}/template', ['id' => $id]), EnvelopeTemplate::class); |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* @param Envelope|string $id |
132
|
|
|
*/ |
133
|
|
|
public function clone($id): Envelope |
134
|
|
|
{ |
135
|
|
|
return $this->makeResource($this->postRequest('/{id}/clone', ['id' => $id])); |
|
|
|
|
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* @param Envelope|string $id |
140
|
|
|
*/ |
141
|
|
|
public function discard($id): Envelope |
142
|
|
|
{ |
143
|
|
|
return $this->makeResource($this->postRequest('/{id}/discard', ['id' => $id])); |
|
|
|
|
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* @param Envelope|string $id |
148
|
|
|
*/ |
149
|
|
|
public function restore($id): Envelope |
150
|
|
|
{ |
151
|
|
|
return $this->makeResource($this->postRequest('/{id}/restore', ['id' => $id])); |
|
|
|
|
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* @param Envelope|string $id |
156
|
|
|
*/ |
157
|
|
|
public function validate($id): void |
158
|
|
|
{ |
159
|
|
|
$this->getRequest('/{id}/validate', ['id' => $id]); |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
/** |
163
|
|
|
* @param Envelope|string $id |
164
|
|
|
*/ |
165
|
|
|
public function startCorrection($id): void |
166
|
|
|
{ |
167
|
|
|
$this->postRequest('/{id}/start-correction', ['id' => $id]); |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
/** |
171
|
|
|
* @param Envelope|string $id |
172
|
|
|
*/ |
173
|
|
|
public function finishCorrection($id): void |
174
|
|
|
{ |
175
|
|
|
$this->postRequest('/{id}/finish-correction', ['id' => $id]); |
176
|
|
|
} |
177
|
|
|
} |
178
|
|
|
|