This topic contains 3 replies, has 2 voices, and was last updated by  Duo_Liang 1 week, 3 days ago.

  • Author
    Posts
  • Participant
    sanketr43
    Newbie
    Member since: 06.08.2018
    Number of posts: 2

    Hello,

    I want to create a package from an already created template with sign field & assign to the signer and show in an iframe to sign the fields. I am using PHP. I tried using simple web application PHP code given in the forum. but not working.

    Please help me with that.

    Keymaster
    Duo_Liang
    Guru
    Member since: 14.06.2018
    Number of posts: 183
    Approved answer

    Score

    0

    Hi sanket,

    Just for my information, which code example are you using and what exact problem are you encountering? If possible, can you share your code snippet here or send to developer@esignlive.com so that I can look into the code and find out what’s the problem.

    Duo


    Duo Liang
    OneSpan Junior Technical Evangelist
    Participant
    sanketr43
    Newbie
    Member since: 06.08.2018
    Number of posts: 2

    Score

    0

    Hello, I managed to create a package from template & updated the placeholder details with new signer details to sign in an iframe.
    Now I just need two things in the script as,
    1. While creating signer role, I want to add attachment field for the recipient (optional)
    2. After signer sign or decline the package, it should redirect to the next page in our web application for further process. means how to redirect to perticular URL after user sign the document.? redirect URL.

    Below is my whole code for it attached

    <?php
    
    define("MULTIPART_BOUNDARY", "----WebKitFormBoundary7MA4YWxkTrZu0gW");
    
    class ESLPackageCreation
    
    {
    	//Define api key and api url
    	private $url = "https://sandbox.esignlive.com/api";
    	private $key = "API-KEY";
    	private $packageAppend = "/packages/";
    	private $tokenAppend = "/signerAuthenticationTokens/";
    
    	//Constructor method for ESLPackageCreation
    	public function __construct()
    	{
    
    	}
    
    	//Clone package
    	public function clonePackage($templateId, $placeholderId, $firstName, $lastName, $email)
    	{
    		$build = array (
    		  'name' => 'Package created from template through REST API',
    		  'description' => 'Package created with the eSignLive REST API',
    		  'emailMessage' => 'This message should be delivered to all signers',
    		  'autocomplete' => true,
    		  'type' => 'PACKAGE',
    		  'visibility' => 'ACCOUNT',
    		  'due' => NULL,
    		  'language' => 'en',
    		  'status' => 'DRAFT',
    		  'roles' => 
    		  array (
    		    0 => 
    		    array (
    		      'id' => $placeholderId,
    		      'type' => 'SIGNER',
    		      'signers' => 
    		      array (
    		        0 => 
    		        array (
    		          'id' => $placeholderId,
    		          'firstName' => $firstName,
    		          'lastName' => $lastName,
    		          'email' => $email,
    		        ),
    		      ),
    		      'name' => 'Signer',
    		    ),
    		  ),
    		);
    		$packageJSON = json_encode($build);
    		$packageId = json_decode($this->sendRequest($this->packageAppend . $templateId . '/clone', $packageJSON, NULL, 'application/json'), true);
    		return $packageId;
    	}
    
    
    	//Send Package
    	public function buildSend($packageId)
    	{
    		$build = array(
    			'status' => 'SENT'
    		);
    		$sendJSON = json_encode($build);
    		$this->sendRequest($this->packageAppend . $packageId['id'], $sendJSON, NULL, 'application/json');
    		return NULL;
    	}
    
    	//Sender signs consent and contract documents
    	public function buildSign($packageId)
    	{
    		$build = array(
    			'documents' => array(
    				array(
    					'id' => 'contract',
    					'name' => 'GRENKE Contract'
    				)
    			)
    		);
    		$signJSON = json_encode($build);
    		$signatureAppend = $this->packageAppend . $packageId['id'] . '/documents/signed_documents';
    		$this->sendRequest($signatureAppend, $signJSON, NULL, 'application/json');
    		return NULL;
    	}
    
    	//Get a session token
    	public function buildToken($packageId,$placeholderId)
    	{
    		$build = array(
    			'packageId' => $packageId['id'],
    			'signerId' => $placeholderId
    		);
    		$tokenJSON = json_encode($build);
    		$token = json_decode($this->sendRequest($this->tokenAppend, $tokenJSON, NULL, 'application/json'), true);
    		return $token;
    	}
    
    	//cURL function to send requests to eSignLive
    	private function sendRequest($type, $json, $document, $contentType)
    	{
    		if (is_null($document) && is_null($contentType))
    		{
    			$postfields = array(
    				"payload" => $json
    			);
    		}
    		else if (is_null($document) && !is_null($contentType))
    		{
    			$postfields = $json;
    		}
    		else
    		{
    			$postfields = $document;
    		}
    
    		$headerOptions = array(
    			'Authorization: Basic ' . $this->key,
    			'Accept: application/json,application/zip,text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8'
    		);
    		if (!is_null($contentType))
    		{
    			$headerOptions[] = "Content-Type: $contentType";
    		}
    
    		$ch = curl_init();
    		curl_setopt($ch, CURLOPT_URL, $this->url . $type);
    		curl_setopt($ch, CURLOPT_POST, true);
    		curl_setopt($ch, CURLOPT_FAILONERROR, true);
    		curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    		curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
    		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    
    		if (!is_null($postfields))
    		{
    			curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
    			if (!is_array($postfields))
    			{
    				$headerOptions[] = 'Content-Length: ' . strlen($postfields);
    			}
    		}
    
    		curl_setopt($ch, CURLOPT_HTTPHEADER, $headerOptions);
    		$response = curl_exec($ch);
    		$err = curl_error($ch);
    		curl_close($ch);
    		
    		if ($err)
    		{
    			return $err;
    		}
    		else
    		{
    			return $response;
    		};
    	}
    }
    
    ?>
    
    • This reply was modified 1 week, 3 days ago by  sanketr43.
    • This reply was modified 1 week, 3 days ago by  sanketr43.
    Keymaster
    Duo_Liang
    Guru
    Member since: 14.06.2018
    Number of posts: 183

    Score

    0

    Hi Sanket,

    1. To add attachment field for the recipient with required of “false”, you can use following JSON in your clonePackage() function:

    "roles":[
          {
             "id":"PlaceholderId1",
             "type":"SIGNER",
             "attachmentRequirements":[
                {
                   "description":"Please upload a scanned copy of your driver's license.",
                   "required":false,
                   "id":"attachment1",
                   "status":"INCOMPLETE",
                   "comment":"",
                   "name":"Driver's license"
                }
             ],
             "signers":[
                {
                   "id":"PlaceholderId1",
                   "firstName":"1.firstname",
                   "lastName":"1.lastname",
                   "email":"signer1@mailinator.com"
                }
             ],
             "name":"Signer1"
          }
       ]

    The guidance for Attachment Feature is here.

    2. And to redirect or to dispatch your request, you can take a look at the attachment code where some JS code is used to monitor the front-end events including “ESL:MESSAGE:SUCCESS:PACKAGE_OPT_OUT” and “ESL:MESSAGE:STARTED:DOCUMENT_ACCEPT”, the document for this example is here.

    Hope this could help you!

    Duo


    Duo Liang
    OneSpan Junior Technical Evangelist
    • This reply was modified 1 week, 3 days ago by  Duo_Liang.
    Attachments:
    You must be logged in to view attached files.

You must be logged in to reply to this topic.