eversign / eversign-php-sdk

The official eversign PHP SDK
https://eversign.com
MIT License
17 stars 24 forks source link

Add possibility to download specific final PDF file #57

Closed Trimasel closed 2 years ago

Trimasel commented 2 years ago

No possibility to download specific final PDF file in sdk, however functional exist in API document_id parameter is usable to get specific file inside https://api.eversign.com/api/download_final_document https://eversign.com/api/documentation/methods#download-final-pdf

Solution I would like to see, change inside \Eversign\Client::downloadFinalDocumentToPath method

    /**
     * Downloads the completed Document. Only works on Documents that have
     * been completed. If you want the Audit Trail on the downloaded File
     * as well, set the auditTrail Parameter to true
     * @param \Eversign\Document $document
     * @param string $path
     * @param boolean $auditTrail
+    * @param string $documentId
     * @return boolean success
     */
-    public function downloadFinalDocumentToPath(Document $document, $path, $auditTrail = false) {
+    public function downloadFinalDocumentToPath(Document $document, $path, $auditTrail = false, string $documentId = "") {
        if (!$document->getIsCompleted()) {
            throw new \Exception('To Download the final File the Document needs to be completed first');
        }
-        return $this->downloadDocumentToPath($document, $path, $auditTrail);
+        return $this->downloadDocumentToPath($document, $path, $auditTrail, Config::DOCUMENT_FINAL_URL, $documentId);
    }

Possible alternatives Change method \Eversign\Client::downloadDocumentToPath to public or add different public method that would work with specific file id

Additional information Additionally could be added the same functional for raw files method \Eversign\Client::downloadRawDocumentToPath due to it also exist in api https://eversign.com/api/documentation/methods#download-original-pdf

archivelm commented 2 years ago

Dear @Trimasel,

Thank you for reporting this. I have examined this code and I think that function downloadDocumentToPath is a nice candidate for public function. It has clear input parameters, nice exception in the case of non-existing document or missing path.

I will make one short release where I will implement this (alternative 1).

Cheers, Milan

archivelm commented 2 years ago

I published a minor release for this https://github.com/eversign/eversign-php-sdk/releases/tag/v1.24.4