|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Sausin\Signere; |
|
4
|
|
|
|
|
5
|
|
|
use Carbon\Carbon; |
|
6
|
|
|
|
|
7
|
|
|
class Form extends BaseClass |
|
8
|
|
|
{ |
|
9
|
|
|
/** The URI of the action */ |
|
10
|
|
|
const URI = 'https://api.signere.no/api/Form'; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Gets all forms to the authenticated documentprovider. |
|
14
|
|
|
* |
|
15
|
|
|
* @return object |
|
16
|
|
|
*/ |
|
17
|
1 |
|
public function get() |
|
18
|
|
|
{ |
|
19
|
|
|
// make the URL for this request |
|
20
|
1 |
|
$url = $this->transformUrl(sprintf('%s/GetForms', self::URI)); |
|
21
|
|
|
|
|
22
|
|
|
// get the headers for this request |
|
23
|
1 |
|
$headers = $this->headers->make('GET', $url); |
|
24
|
|
|
|
|
25
|
|
|
// get the response |
|
26
|
1 |
|
$response = $this->client->get($url, [ |
|
27
|
1 |
|
'headers' => $headers, |
|
28
|
|
|
]); |
|
29
|
|
|
|
|
30
|
|
|
// return the response |
|
31
|
1 |
|
return $response; |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Gets all signed forms to the authenticated documentprovider |
|
36
|
|
|
* filtered by the input parameters provided. |
|
37
|
|
|
* |
|
38
|
|
|
* @param string|null $formId |
|
39
|
|
|
* @param Carbon|null $from |
|
40
|
|
|
* @param Carbon|null $to |
|
41
|
|
|
* @return object |
|
42
|
|
|
*/ |
|
43
|
1 |
|
public function getAllSigned(string $formId = null, Carbon $from = null, Carbon $to = null) |
|
44
|
|
|
{ |
|
45
|
|
|
// make the URL for this request |
|
46
|
1 |
|
$url = $this->transformUrl(sprintf( |
|
47
|
1 |
|
'%s/GetSignedForms?formId=%s&fromDate=%s&toDate=%s', |
|
48
|
1 |
|
self::URI, |
|
49
|
|
|
$formId, |
|
50
|
1 |
|
$from ? $from->toDateString() : null, |
|
51
|
1 |
|
$to ? $to->toDateString() : null |
|
52
|
|
|
)); |
|
53
|
|
|
|
|
54
|
|
|
// get the headers for this request |
|
55
|
1 |
|
$headers = $this->headers->make('GET', $url); |
|
56
|
|
|
|
|
57
|
|
|
// get the response |
|
58
|
1 |
|
$response = $this->client->get($url, [ |
|
59
|
1 |
|
'headers' => $headers, |
|
60
|
|
|
]); |
|
61
|
|
|
|
|
62
|
|
|
// return the response |
|
63
|
1 |
|
return $response; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* Gets the attachements to the form. |
|
68
|
|
|
* |
|
69
|
|
|
* @param string $formId |
|
70
|
|
|
* @param string $formSignId |
|
71
|
|
|
* @param string $attachReference |
|
72
|
|
|
* @return object |
|
73
|
|
|
*/ |
|
74
|
1 |
|
public function getAttachments(string $formId, string $formSignId, string $attachReference) |
|
75
|
|
|
{ |
|
76
|
|
|
// make the URL for this request |
|
77
|
1 |
|
$url = $this->transformUrl(sprintf( |
|
78
|
1 |
|
'%s/GetFormAttachment?formId=%s&FormSignatureId=%s&AttatchmentReference=%s', |
|
79
|
1 |
|
self::URI, |
|
80
|
|
|
$formId, |
|
81
|
|
|
$formSignId, |
|
82
|
|
|
$attachReference |
|
83
|
|
|
)); |
|
84
|
|
|
|
|
85
|
|
|
// get the headers for this request |
|
86
|
1 |
|
$headers = $this->headers->make('GET', $url); |
|
87
|
|
|
|
|
88
|
|
|
// get the response |
|
89
|
1 |
|
$response = $this->client->get($url, [ |
|
90
|
1 |
|
'headers' => $headers, |
|
91
|
|
|
]); |
|
92
|
|
|
|
|
93
|
|
|
// return the response |
|
94
|
1 |
|
return $response; |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* Gets a signed form from DocumentID. |
|
99
|
|
|
* |
|
100
|
|
|
* @param string $documentId |
|
101
|
|
|
* @return object |
|
102
|
|
|
*/ |
|
103
|
1 |
|
public function getSignedByDocId(string $documentId) |
|
104
|
|
|
{ |
|
105
|
|
|
// make the URL for this request |
|
106
|
1 |
|
$url = $this->transformUrl(sprintf('%s/GetSignedForm?documentid=%s', self::URI, $documentId)); |
|
107
|
|
|
|
|
108
|
|
|
// get the headers for this request |
|
109
|
1 |
|
$headers = $this->headers->make('GET', $url); |
|
110
|
|
|
|
|
111
|
|
|
// get the response |
|
112
|
1 |
|
$response = $this->client->get($url, [ |
|
113
|
1 |
|
'headers' => $headers, |
|
114
|
|
|
]); |
|
115
|
|
|
|
|
116
|
|
|
// return the response |
|
117
|
1 |
|
return $response; |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
/** |
|
121
|
|
|
* Gets a signed form from formId and formSessionId. |
|
122
|
|
|
* |
|
123
|
|
|
* @param string $formId |
|
124
|
|
|
* @param string $formSessionId |
|
125
|
|
|
* @return object |
|
126
|
|
|
*/ |
|
127
|
1 |
|
public function getSignedBySessionId(string $formId, string $formSessionId) |
|
128
|
|
|
{ |
|
129
|
|
|
// make the URL for this request |
|
130
|
1 |
|
$url = $this->transformUrl(sprintf( |
|
131
|
1 |
|
'%s/GetSignedFormByFormSessionId?formId=%s&formSessionId=%s', |
|
132
|
1 |
|
self::URI, |
|
133
|
|
|
$formId, |
|
134
|
|
|
$formSessionId |
|
135
|
|
|
)); |
|
136
|
|
|
|
|
137
|
|
|
// get the headers for this request |
|
138
|
1 |
|
$headers = $this->headers->make('GET', $url); |
|
139
|
|
|
|
|
140
|
|
|
// get the response |
|
141
|
1 |
|
$response = $this->client->get($url, [ |
|
142
|
1 |
|
'headers' => $headers, |
|
143
|
|
|
]); |
|
144
|
|
|
|
|
145
|
|
|
// return the response |
|
146
|
1 |
|
return $response; |
|
147
|
|
|
} |
|
148
|
|
|
|
|
149
|
|
|
/** |
|
150
|
|
|
* Enables the form. |
|
151
|
|
|
* |
|
152
|
|
|
* @param string $formId |
|
153
|
|
|
* @return object |
|
154
|
|
|
*/ |
|
155
|
1 |
|
public function enable(string $formId) |
|
156
|
|
|
{ |
|
157
|
|
|
// make the URL for this request |
|
158
|
1 |
|
$url = $this->transformUrl(sprintf('%s/EnableForm?formId=%s', self::URI, $formId)); |
|
159
|
|
|
|
|
160
|
|
|
// get the headers for this request |
|
161
|
1 |
|
$headers = $this->headers->make('PUT', $url, []); |
|
162
|
|
|
|
|
163
|
|
|
// get the response |
|
164
|
1 |
|
$response = $this->client->put($url, [ |
|
165
|
1 |
|
'headers' => $headers, |
|
166
|
|
|
'json' => [], |
|
167
|
|
|
]); |
|
168
|
|
|
|
|
169
|
|
|
// return the response |
|
170
|
1 |
|
return $response; |
|
171
|
|
|
} |
|
172
|
|
|
|
|
173
|
|
|
/** |
|
174
|
|
|
* Disables the form. |
|
175
|
|
|
* |
|
176
|
|
|
* @param string $formId |
|
177
|
|
|
* @return object |
|
178
|
|
|
*/ |
|
179
|
1 |
|
public function disable(string $formId) |
|
180
|
|
|
{ |
|
181
|
|
|
// make the URL for this request |
|
182
|
1 |
|
$url = $this->transformUrl(sprintf('%s/DisableForm?formId=%s', self::URI, $formId)); |
|
183
|
|
|
|
|
184
|
|
|
// get the headers for this request |
|
185
|
1 |
|
$headers = $this->headers->make('PUT', $url, []); |
|
186
|
|
|
|
|
187
|
|
|
// get the response |
|
188
|
1 |
|
$response = $this->client->put($url, [ |
|
189
|
1 |
|
'headers' => $headers, |
|
190
|
|
|
'json' => [], |
|
191
|
|
|
]); |
|
192
|
|
|
|
|
193
|
|
|
// return the response |
|
194
|
1 |
|
return $response; |
|
195
|
|
|
} |
|
196
|
|
|
} |
|
197
|
|
|
|