'PHP DocuSign: getting empty document when downloading the completed signed document

I integrated Docusing with a PHP Laravel App using JWT Auth. It's working perfectly, could send the email to recipients for signing. Now after all signing is done we would like to download the complete signed document with CoC.

I'm using following code to get the signed document for a specific Envelope:

$envelope_api = new EnvelopesApi($apiClient);

$tmpFile = $envelope_api->getDocument($account_id, 'combined', $envelope_id);

$savCert = file_put_contents("signed_document.pdf", file_get_contents($tmpFile->getPathname()));

But I'm getting the empty document when the file is downloaded. It would very helpful if you could give a hint how to resolve the issue.

json payload for a $tmpfile:

object(SplFileObject)#418 (5) 
{
 ["pathName":"SplFileInfo":private]=> string(44) "C:\Users\AppData\Local\Temp\19F.tmp" 
 ["fileName":"SplFileInfo":private]=> string(7) "19F.tmp" 
 ["openMode":"SplFileObject":private]=> string(1) "r" 
 ["delimiter":"SplFileObject":private]=> string(1) "," 
 ["enclosure":"SplFileObject":private]=> string(1) """ 
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source