-
Notifications
You must be signed in to change notification settings - Fork 12
/
signhost.php
274 lines (241 loc) · 8.3 KB
/
signhost.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
<?php
require_once("response.php");
require_once("DTO/consentverification.php");
require_once("DTO/digidverification.php");
require_once("DTO/eherkenningverification.php");
require_once("DTO/eidasloginverification.php");
require_once("DTO/filemetadata.php");
require_once("DTO/formsetfield.php");
require_once("DTO/formsets.php");
require_once("DTO/idealverification.php");
require_once("DTO/idinverification.php");
require_once("DTO/itsmeidentificationverification.php");
require_once("DTO/itsmesignverification.php");
require_once("DTO/location.php");
require_once("DTO/phonenumberverification.php");
require_once("DTO/receiver.php");
require_once("DTO/scribbleverification.php");
require_once("DTO/signer.php");
require_once("DTO/signingcertificateverification.php");
require_once("DTO/surfnetverification.php");
require_once("DTO/transaction.php");
require_once("DTO/verification.php");
class SignHost {
const API_VERSION = "v1";
const CLIENT_VERSION = "2.0-beta-2";
/** @var string */
public $AppKey;
/** @var string */
public $ApiKey;
/** @var string */
public $SharedSecret;
/** @var string */
public $ApiEndpoint;
/**
* @param string $appKey
* @param string $apiKey
* @param string $sharedSecret
* @param string $apiEndpoint
*/
function __construct(
$appKey,
$apiKey,
$sharedSecret = null,
$apiEndpoint = "https://api.signhost.com/api"
) {
$this->AppKey = $appKey;
$this->ApiKey = $apiKey;
$this->SharedSecret = $sharedSecret;
$this->ApiEndpoint = $apiEndpoint;
}
/**
* Creates a new transaction.
* @param Transaction $transaction
* @return Response
*/
public function CreateTransaction($transaction) {
$ch = curl_init($this->ApiEndpoint."/transaction");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($transaction));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Accept: application/vnd.signhost.".self::API_VERSION."+json",
"User-Agent: Signhost PHP Client/".self::CLIENT_VERSION,
"Content-Type: application/json",
"Application: APPKey ".$this->AppKey,
"Authorization: APIKey ".$this->ApiKey,
));
$response = new Response($ch);
curl_close($ch);
return $response;
}
/**
* Gets an existing transaction by providing a transaction ID.
*
* When the response has a status code of 410, you can still retrieve
* partial historical data from the JSON in the error message property.
* @param string $transactionId
* @return Response
*/
public function GetTransaction($transactionId) {
$ch = curl_init($this->ApiEndpoint."/transaction/".$transactionId);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Accept: application/vnd.signhost.".self::API_VERSION."+json",
"User-Agent: Signhost PHP Client/".self::CLIENT_VERSION,
"Application: APPKey ".$this->AppKey,
"Authorization: APIKey ".$this->ApiKey,
));
$response = new Response($ch);
curl_close($ch);
return $response;
}
/**
* Deletes an existing transaction by providing a transaction ID.
* @param string $transactionId
* @return Response
*/
public function DeleteTransaction($transactionId) {
$ch = curl_init($this->ApiEndpoint."/transaction/".$transactionId);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Content-Length: 0",
"Accept: application/vnd.signhost.".self::API_VERSION."+json",
"User-Agent: Signhost PHP Client/".self::CLIENT_VERSION,
"Application: APPKey ".$this->AppKey,
"Authorization: APIKey ".$this->ApiKey,
));
$response = new Response($ch);
curl_close($ch);
return $response;
}
/**
* Starts an existing transaction by providing a transaction ID.
* @param string $transactionId
* @return Response
*/
public function StartTransaction($transactionId) {
$ch = curl_init($this->ApiEndpoint."/transaction/".$transactionId."/start");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Content-Length: 0",
"Accept: application/vnd.signhost.".self::API_VERSION."+json",
"User-Agent: Signhost PHP Client/".self::CLIENT_VERSION,
"Application: APPKey ".$this->AppKey,
"Authorization: APIKey ".$this->ApiKey,
));
$response = new Response($ch);
curl_close($ch);
return $response;
}
/**
* Add a file to an existing transaction by providing a file path
* and a transaction ID.
* @param string $transactionId
* @param string $fileId
* @param string $filePath
* @return Response
*/
public function AddOrReplaceFile($transactionId, $fileId, $filePath) {
$checksum_file = base64_encode(pack('H*', hash_file('sha256', $filePath)));
$fh = fopen($filePath, 'r');
$ch = curl_init($this->ApiEndpoint."/transaction/".$transactionId."/file/".rawurlencode($fileId));
curl_setopt($ch, CURLOPT_PUT, 1);
curl_setopt($ch, CURLOPT_INFILE, $fh);
curl_setopt($ch, CURLOPT_INFILESIZE, filesize($filePath));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Accept: application/vnd.signhost.".self::API_VERSION."+json",
"User-Agent: Signhost PHP Client/".self::CLIENT_VERSION,
"Content-Type: application/pdf",
"Application: APPKey ".$this->AppKey,
"Authorization: APIKey ".$this->ApiKey,
"Digest: SHA-256=".$checksum_file,
));
$response = new Response($ch);
curl_close($ch);
fclose($fh);
return $response;
}
/**
* Adds file metadata for a file to an existing transaction by providing a transaction ID.
* @param string $transactionId
* @param string $fileId
* @param FileMetadata $metadata
* @return Response
*/
public function AddOrReplaceMetadata($transactionId, $fileId, $metadata) {
$ch = curl_init($this->ApiEndpoint."/transaction/".$transactionId."/file/".rawurlencode($fileId));
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($metadata));
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Accept: application/vnd.signhost.".self::API_VERSION."+json",
"User-Agent: Signhost PHP Client/".self::CLIENT_VERSION,
"Content-Type: application/json",
"Application: APPKey ".$this->AppKey,
"Authorization: APIKey ".$this->ApiKey,
));
$response = new Response($ch);
curl_close($ch);
return $response;
}
/**
* Gets the receipt of a finished transaction by providing a transaction ID.
* @param string $transactionId
* @return Response
*/
public function GetReceipt($transactionId) {
$ch = curl_init($this->ApiEndpoint."/file/receipt/".$transactionId);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Accept: ".
"application/pdf, ".
"application/vnd.signhost.".self::API_VERSION."+json",
"User-Agent: Signhost PHP Client/".self::CLIENT_VERSION,
"Application: APPKey ".$this->AppKey,
"Authorization: APIKey ".$this->ApiKey,
));
$response = new Response($ch);
curl_close($ch);
return $response;
}
/**
* Gets the document of a transaction by providing a transaction ID.
* @param string $transactionId
* @param string $fileId
* @return Response
*/
public function GetDocument($transactionId, $fileId) {
$ch = curl_init($this->ApiEndpoint."/transaction/".$transactionId."/file/".rawurlencode($fileId));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Accept: ".
"application/pdf, ".
"application/vnd.signhost.".self::API_VERSION."+json",
"User-Agent: Signhost PHP Client/".self::CLIENT_VERSION,
"Application: APPKey ".$this->AppKey,
"Authorization: APIKey ".$this->ApiKey,
));
$response = new Response($ch);
curl_close($ch);
return $response;
}
/**
* Generates a checksum and validates it with the remote checksum.
* @param string $masterTransactionId
* @param string $fileId
* @param int $status
* @param string $remoteChecksum
* @return bool
*/
public function ValidateChecksum($masterTransactionId, $fileId, $status, $remoteChecksum) {
$localChecksum = sha1($masterTransactionId."|".$fileId."|".$status."|".$this->SharedSecret);
if (strlen($localChecksum) !== strlen($remoteChecksum)) {
return false;
}
return hash_equals($localChecksum, $remoteChecksum);
}
}