1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace DigitalCz\DigiSign\Endpoint; |
6
|
|
|
|
7
|
|
|
use DigitalCz\DigiSign\Endpoint\Traits\CRUDEndpointTrait; |
8
|
|
|
use DigitalCz\DigiSign\Resource\Collection; |
9
|
|
|
use DigitalCz\DigiSign\Resource\Envelope; |
10
|
|
|
use DigitalCz\DigiSign\Resource\EnvelopeRecipient; |
11
|
|
|
use DigitalCz\DigiSign\Resource\EnvelopeRecipientAttachment; |
12
|
|
|
use DigitalCz\DigiSign\Resource\EnvelopeRecipientIdentifications; |
13
|
|
|
use DigitalCz\DigiSign\Resource\EnvelopeTag; |
14
|
|
|
use DigitalCz\DigiSign\Resource\ListResource; |
15
|
|
|
use DigitalCz\DigiSign\Resource\ResourceInterface; |
16
|
|
|
use DigitalCz\DigiSign\Resource\VerifiedClaims; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @extends ResourceEndpoint<EnvelopeRecipient> |
20
|
|
|
* @method EnvelopeRecipient get(string $id) |
21
|
|
|
* @method EnvelopeRecipient create(array $body) |
22
|
|
|
* @method EnvelopeRecipient update(string $id, array $body) |
23
|
|
|
*/ |
24
|
|
|
final class EnvelopeRecipientsEndpoint extends ResourceEndpoint |
25
|
|
|
{ |
26
|
|
|
/** @use CRUDEndpointTrait<EnvelopeRecipient> */ |
27
|
|
|
use CRUDEndpointTrait; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @param Envelope|string $envelope |
31
|
|
|
*/ |
32
|
|
|
public function __construct(EnvelopesEndpoint $parent, $envelope) |
33
|
|
|
{ |
34
|
|
|
parent::__construct($parent, '/{envelope}/recipients', EnvelopeRecipient::class, ['envelope' => $envelope]); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @param EnvelopeRecipient|string $recipient |
39
|
|
|
*/ |
40
|
|
|
public function block($recipient): RecipientBlockEndpoint |
41
|
|
|
{ |
42
|
|
|
return new RecipientBlockEndpoint($this, $recipient); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @param EnvelopeRecipient|string $recipient |
47
|
|
|
*/ |
48
|
|
|
public function attachments($recipient): EnvelopeRecipientAttachmentsEndpoint |
49
|
|
|
{ |
50
|
|
|
return new EnvelopeRecipientAttachmentsEndpoint($this, $recipient); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @param mixed[] $body |
55
|
|
|
* @return array<EnvelopeRecipient> |
56
|
|
|
*/ |
57
|
|
|
public function createMany(array $body): array |
58
|
|
|
{ |
59
|
|
|
$response = $this->patchRequest('', ['json' => $body]); |
60
|
|
|
$result = $this->parseResponse($response); |
61
|
|
|
|
62
|
|
|
return array_map(static function (array $recipientResult): EnvelopeRecipient { |
63
|
|
|
return new EnvelopeRecipient($recipientResult); |
64
|
|
|
}, $result); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @param mixed[] $body |
69
|
|
|
*/ |
70
|
|
|
public function embed(string $id, array $body): ResourceInterface |
71
|
|
|
{ |
72
|
|
|
return $this->createResource( |
73
|
|
|
$this->postRequest('/{id}/embed', ['id' => $id, 'json' => $body]) |
74
|
|
|
); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @param mixed[] $query |
79
|
|
|
* @return ListResource<EnvelopeTag> |
80
|
|
|
*/ |
81
|
|
|
public function tags(string $id, array $query = []): ListResource |
82
|
|
|
{ |
83
|
|
|
return $this->createListResource( |
84
|
|
|
$this->getRequest('/{id}/tags', ['id' => $id, 'query' => $query]), |
85
|
|
|
EnvelopeTag::class |
86
|
|
|
); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
public function resend(string $id): ResourceInterface |
90
|
|
|
{ |
91
|
|
|
return $this->createResource($this->postRequest('/{id}/resend', ['id' => $id])); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
public function verifiedClaims(string $id): ResourceInterface |
95
|
|
|
{ |
96
|
|
|
return $this->createResource($this->getRequest('/{id}/verified-claims', ['id' => $id]), VerifiedClaims::class); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @param mixed[] $body |
101
|
|
|
*/ |
102
|
|
|
public function signingOrder(array $body): void |
103
|
|
|
{ |
104
|
|
|
$this->putRequest('/signing-order', ['json' => $body]); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* @return Collection<EnvelopeRecipientAttachment> |
109
|
|
|
*/ |
110
|
|
|
public function listAttachments(): Collection |
111
|
|
|
{ |
112
|
|
|
return $this->createCollectionResource($this->getRequest('/attachments'), EnvelopeRecipientAttachment::class); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* @param EnvelopeRecipient|string $recipient |
117
|
|
|
*/ |
118
|
|
|
public function listIdentifications($recipient): EnvelopeRecipientIdentifications |
119
|
|
|
{ |
120
|
|
|
return $this->createResource( |
121
|
|
|
$this->getRequest('/{id}/identifications', ['id' => $recipient]), |
122
|
|
|
EnvelopeRecipientIdentifications::class |
123
|
|
|
); |
124
|
|
|
} |
125
|
|
|
} |
126
|
|
|
|