/** * 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 testCreate() { $json = '{ "javascript": "<script type=\'text/javascript\' language=\'JavaScript\' src=\'https://secure.echosign.com/public/widget?f=2AAABLblqZhC8ueu0-qMHimIHkeGtB39bIneHcv5F5Kx0gbz21gQ27A3AnMlsKaKKrTKQYTXl8I0*\'></script>", "url": "https://poweresq.echosign.com/public/hostedForm?formid=2AAABLblqZhC8ueu0-qMHimIHkeGtB39bIneHcv5F5Kx0gbz21gQ27A3AnMlsKaKKrTKQYTXl8I0*", "widgetId": "2AAABLblqZhCF9yZRdsh0_3RbujXEoIDbBC0PG9_BUT1sTEWC4xw7OCstLx4vKpqF9086p-lhcoI*" }'; $transport = new \Echosign\Transports\GuzzleTransport(); $client = $transport->getClient(); $stream = Stream::factory($json); $mock = new Mock([new Response(200, ['content-type' => 'application/json'], $stream)]); $client->getEmitter()->attach($mock); $widget = new Widgets('1234', $transport); $fileInfo = new \Echosign\RequestBuilders\Widget\WidgetFileInfo(); $fileInfo->setLibraryDocumentId("balls"); $docCreationinfo = new \Echosign\RequestBuilders\Widget\WidgetCreationInfo('test', 'SENDER_SIGNATURE_NOT_REQUIRED', $fileInfo); $docCreate = new \Echosign\RequestBuilders\WidgetCreationRequest($docCreationinfo, new \Echosign\RequestBuilders\Agreement\InteractiveOptions()); $response = $widget->create($docCreate); $this->assertInstanceOf('Echosign\\Responses\\WidgetCreationResponse', $response); $this->assertEquals("2AAABLblqZhCF9yZRdsh0_3RbujXEoIDbBC0PG9_BUT1sTEWC4xw7OCstLx4vKpqF9086p-lhcoI*", $response->getWidgetId()); }