sanketr43 | Posts: 14

create package from already created template with sign field & assign to signer

0 votes
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.

Approved Answer
Duo_Liang | Posts: 3776

Reply to: create package from already created template with sign field & assign to signer

0 votes
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 [email protected] so that I can look into the code and find out what's the problem. Duo

sanketr43 | Posts: 14

Reply to: create package from already created template with sign field & assign to signer

0 votes
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
 '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;
		};
	}
}

?>

Duo_Liang | Posts: 3776

Reply to: create package from already created template with sign field & assign to signer

0 votes
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":"[email protected]"
            }
         ],
         "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

Attachments
iframe-1.zip755 bytes

Hello! Looks like you're enjoying the discussion, but haven't signed up for an account.

When you create an account, we remember exactly what you've read, so you always come right back where you left off