Skip to content

Commit 196a161

Browse files
new: add the function downloadFinalDocument() (#68)
* new: add the function downloadFinalDocument() * fix: Config::DOCUMENT_FINAL_URL instead of string Co-authored-by: Julien SCHERMANN <[email protected]>
1 parent 328d556 commit 196a161

File tree

3 files changed

+86
-1
lines changed

3 files changed

+86
-1
lines changed

sdk/Eversign/ApiRequest.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,16 @@ public function startRequest() {
202202
}
203203
]);
204204
}
205+
else if($this->payLoad && is_array($this->payLoad) && array_key_exists("stream", $this->payLoad)) {
206+
$response = $this->guzzleClient->request($this->httpType, $this->endPoint, [
207+
'timeout' => $this->guzzleRequestTimeout,
208+
'query' => $this->createQuery(),
209+
'stream' => $this->payLoad["stream"],
210+
'on_stats' => function (TransferStats $stats) use (&$effectiveUrl) {
211+
$effectiveUrl = $stats->getEffectiveUri();
212+
}
213+
]);
214+
}
205215
else {
206216
$requestOptions = [
207217
'timeout' => $this->guzzleRequestTimeout,
@@ -236,7 +246,10 @@ public function startRequest() {
236246
$body = $response->getBody();
237247

238248
if($this->payLoad && is_array($this->payLoad) && array_key_exists("sink", $this->payLoad)) {
239-
return file_exists($this->payLoad["sink"]);
249+
return file_exists($this->payLoad["sink"]);
250+
251+
} else if($this->payLoad && is_array($this->payLoad) && array_key_exists("stream", $this->payLoad)) {
252+
return $body;
240253
} else {
241254
$responseJson = json_decode($body, true);
242255
if(json_last_error() !== JSON_ERROR_NONE) {

sdk/Eversign/Client.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,32 @@ public function downloadDocumentToPath(Document $document, $path, $auditTrail =
572572
return $request->startRequest();
573573
}
574574

575+
public function downloadFinalDocument(Document $document, $auditTrail = 0, $onlyUrl = false, $documentId = "") {
576+
577+
$parameters = [
578+
"business_id" => $this->selectedBusiness->getBusinessId(),
579+
"document_hash" => $document->getDocumentHash(),
580+
"audit_trail" => $auditTrail,
581+
"document_id" => $documentId,
582+
"url_only" => $onlyUrl
583+
];
584+
585+
$payLoad = $onlyUrl ? null : ["stream" => false];
586+
587+
$request = new ApiRequest(
588+
"GET",
589+
$this->accessKey,
590+
Config::DOCUMENT_FINAL_URL,
591+
$onlyUrl ? "Eversign\Url" : "",
592+
$parameters,
593+
$payLoad,
594+
$this->apiBaseUrl,
595+
$this->apiRequestTimeout
596+
);
597+
598+
return $request->startRequest();
599+
}
600+
575601
/**
576602
* Deletes the specified Document. Only works on Drafts and canceled Documents
577603
* @param \Eversign\Document $document

sdk/Eversign/Url.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
/*
4+
* The MIT License
5+
*
6+
* Copyright 2017 Patrick Leeb.
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in
16+
* all copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*/
26+
27+
namespace Eversign;
28+
29+
use JMS\Serializer\Annotation\Type;
30+
31+
class Url {
32+
33+
/**
34+
* @var boolean $success
35+
* @Type("boolean")
36+
*/
37+
public $success;
38+
39+
/**
40+
* @var boolean $success
41+
* @Type("string")
42+
*/
43+
public $url;
44+
45+
46+
}

0 commit comments

Comments
 (0)