/** * Create a library document from a local file, then create a widget for that document. If successful it returns the * url to the widget. You can use $this->getResponse() to get the widget object. * @param $fileName * @param $widgetName * @return bool|string */ public function createLibraryDocumentWidgetFromLocalFile($fileName, $widgetName) { $libraryDocument = new LibraryDocument($this->getToken(), $this->getTransport()); $libraryDocumentId = $libraryDocument->createFromLocalFile($fileName, basename($fileName), 'DOCUMENT'); if ($libraryDocumentId === false) { $this->response = $libraryDocument->getResponse(); $this->errorMessages = $libraryDocument->getErrorMessages(); return false; } $this->widget = new Widgets($this->getToken(), $this->getTransport()); $fileInfo = new WidgetFileInfo(); $fileInfo->setLibraryDocumentId($libraryDocumentId); $widgetCreationInfo = new WidgetCreationInfo($widgetName, $this->getSignatureFlow(), $fileInfo); $widgetRequest = new WidgetCreationRequest($widgetCreationInfo, new InteractiveOptions()); try { $this->response = $this->widget->create($widgetRequest); } catch (JsonApiResponseException $e) { $this->errorMessages[$e->getCode()] = sprintf('%s - %s', $e->getApiCode(), $e->getMessage()); return false; } catch (\Exception $e) { $this->errorMessages[$e->getCode()] = $e->getMessage(); return false; } return $this->response->getUrl(); }
public function testCreateFromLocalFile() { $json = ['{ "transientDocumentId":"123asdf809"}', '{ "embeddedCode": "<script type=\'text/javascript\' language=\'JavaScript\' src=\'https://poweresq.echosign.com/embed/account/sendProgress?aid=XJ28WY42H5E2T6M&noChrome=true\'></script>", "libraryDocumentId": "2AAABLblqZhCLqOm1s_gWpTxax3wK6csrs22iQOYyLOZHLLnOl2FeL3IxFEkgO09JYWczAt_57Lw*", "url": "https://test.echosign.com/account/sendProgress?aid=XJ28WY42H5E2T6M" }']; $file = tempnam(sys_get_temp_dir(), 'TMP'); $fp = fopen($file, 'w+'); fwrite($fp, "hey look, I just work here okay?"); fclose($fp); $libraryDocument = new LibraryDocument($this->token, $this->getMockTransport($json)); $libraryDocumentId = $libraryDocument->createFromLocalFile($file, 'test', 'DOCUMENT'); $this->assertEquals("2AAABLblqZhCLqOm1s_gWpTxax3wK6csrs22iQOYyLOZHLLnOl2FeL3IxFEkgO09JYWczAt_57Lw*", $libraryDocumentId); }
/** * Create an agreement from a local file, for specified signerEmail with message. It first creates a library * document, then creates the agreement. You can use $this->getResponse() to get created agreement. If successful * it returns the agreementId. * @param $signerEmail * @param $message * @param $filename * @param $agreementName * @return bool|string */ public function createLibraryDocumentAgreement($signerEmail, $message, $filename, $agreementName) { $libraryDocument = new LibraryDocument($this->getToken(), $this->getTransport()); $libraryDocumentId = $libraryDocument->createFromLocalFile($filename, basename($filename), 'DOCUMENT'); if ($libraryDocumentId === false) { $this->response = $libraryDocument->getResponse(); $this->errorMessages = $libraryDocument->getErrorMessages(); return false; } return $this->createFromLibraryDocumentId($signerEmail, $message, $libraryDocumentId, $agreementName); }