if ($jobInfo->result->job_status == "Completed" || $jobInfo->result->job_status == "Archived") { break; //If job status Postponed throw exception with error } elseif ($jobInfo->result->job_status == "Postponed") { throw new Exception("Job is failed"); } } if ($jobInfo->result->job_status == "Pending") { throw new Exception("Job is pending"); } //Get file guid $guid = $jobInfo->result->inputs[0]->outputs[0]->guid; //Get file name $name = $jobInfo->result->inputs[0]->outputs[0]->name; //Create envilope using user id and entered by user name $envelop = $signature->CreateSignatureEnvelope($clientId, $name, null, null, $guid); if ($envelop->status == "Ok") { try { //Get role list for current user $recipient = $signature->GetRolesList($clientId); if ($recipient->status == "Ok") { //Get id of role which can sign for ($i = 0; $i < count($recipient->result->roles); $i++) { if ($recipient->result->roles[$i]->name == "Signer") { $roleId = $recipient->result->roles[$i]->id; } } try { //Add recipient to envelope $addRecipient = $signature->AddSignatureEnvelopeRecipient($clientId, $envelop->result->envelope->id, $firstEmail, $firstName, $lastName, $roleId, null); if ($addRecipient->status == "Ok") {
//Make request to api for get document info by job id $jobInfo = $api->GetJobDocuments($clientId, $job->result->job_id); //Check job status, if status is Completed or Archived exit from cycle if ($jobInfo->result->job_status == "Completed" || $jobInfo->result->job_status == "Archived") { break; //If job status Postponed throw exception with error } elseif ($jobInfo->result->job_status == "Postponed") { throw new Exception("Job is failed"); } } if ($jobInfo->result->job_status == "Pending") { throw new Exception("Job is pending"); } //Get file guid $guid = $jobInfo->result->inputs[0]->outputs[0]->guid; $envelop = $signatureApi->CreateSignatureEnvelope($clientId, $jobInfo->result->inputs[0]->outputs[0]->name); if ($envelop->status == "Ok") { sleep(5); //Add uploaded document to envelope $addDocument = $signatureApi->AddSignatureEnvelopeDocument($clientId, $envelop->result->envelope->id, $guid, null, true); if ($addDocument->status == "Ok") { //Get role list for curent user $recipient = $signatureApi->GetRolesList($clientId); if ($recipient->status == "Ok") { //Get id of role which can sign for ($i = 0; $i < count($recipient->result->roles); $i++) { if ($recipient->result->roles[$i]->name == "Signer") { $roleId = $recipient->result->roles[$i]->id; } } //Add recipient to envelope
} } } else { throw new Exception($uploadResult->error_message); } } catch (Exception $e) { $error = 'ERROR: ' . $e->getMessage() . "\n"; F3::set('error', $error); } } //Create SignatureApi object $signature = new SignatureApi($apiClient); $signature->setBasePath($basePath); //Create envilope using user id and entered by user name try { $envelop = $signature->CreateSignatureEnvelope($clientID, $name); if ($envelop->status == "Ok") { sleep(5); //Add uploaded document to envelope $addDocument = $signature->AddSignatureEnvelopeDocument($clientID, $envelop->result->envelope->id, $fileGuId, null, true); try { if ($addDocument->status == "Ok") { //Get role list for curent user try { $recipient = $signature->GetRolesList($clientID); if ($recipient->status == "Ok") { //Get id of role which can sign for ($i = 0; $i < count($recipient->result->roles); $i++) { if ($recipient->result->roles[$i]->name == "Signer") { $roleId = $recipient->result->roles[$i]->id; }