I am using Docuisign for my client to use it as digital signature. I am using php rest API and i have 5 template roles and everything is working perfect.
So i want to get a request on my server from Docusign when the envelope status is completed. So that i can update the status on my side as well.
I have one solution in my mind
1) Solution 1
I can create a cron job to check the status of envelope but 4 crones are already running on my server so i am avoiding this solution
My Code is
$envelopeApi = new DocuSign\eSign\Api\EnvelopesApi($apiClient);
// Add a document to the envelope
$document = new DocuSign\eSign\Model\Document();
$document->setDocumentBase64(base64_encode(file_get_contents($documentFileName)));
$document->setName($documentName);
$document->setDocumentId("1");
// assign recipient to template role by setting name, email, and role name. Note that the
// template role name must match the placeholder role name saved in your account template.
$templateRole = new DocuSign\eSign\Model\TemplateRole();
$templateRole->setEmail($recipientEmail);
$templateRole->setName($recipientName);
$templateRole->setRoleName("Buyer");
$templateRole->setClientUserId('12345');
$docusignlogs['Recipients'][]=array("Email"=>$recipientEmail,"Name"=>$recipientName,"Role"=>"Buyer");
$templateRole1 = new DocuSign\eSign\Model\TemplateRole();
$templateRole1->setEmail($agentEmail);
$templateRole1->setName($agentName);
$templateRole1->setRoleName("SA");
$docusignlogs['Recipients'][]=array("Email"=>$agentEmail,"Name"=>$agentName,"Role"=>"SA");
//$templateRole1->setClientUserId('12345');
$all_template_roles = array($templateRole,$templateRole1);
$envelop_definition = new DocuSign\eSign\Model\EnvelopeDefinition();
$envelop_definition->setEmailSubject(" E-CONTRACT – {$subname} – {$lotjobnum}");
$envelop_definition->setTemplateId($templateid);
$envelop_definition->setDocuments(array($document));
$envelop_definition->setTemplateRoles($all_template_roles);
// set envelope status to "sent" to immediately send the signature request
$envelop_definition->setStatus("sent");
// optional envelope parameters
$options = new \DocuSign\eSign\Api\EnvelopesApi\CreateEnvelopeOptions();
$options->setCdseMode(null);
$options->setMergeRolesOnDraft(null);
// create and send the envelope (aka signature request)
$envelop_summary = $envelopeApi->createEnvelope($accountId, $envelop_definition, $options);
if(!isset($envelop_summary->errorCode)){
$document=json_decode($envelop_summary);
$envloped=$document->envelopeId;
$viewrequest = new DocuSign\eSign\Model\RecipientViewRequest();
$viewrequest->setUserName($recipientName);
$viewrequest->setEmail($recipientEmail);
$viewrequest->setAuthenticationMethod('email');
$viewrequest->setClientUserId('12345');
$viewrequest->setReturnUrl($ReturnUrl);
$envelopview=$envelopeApi->createRecipientView($accountId,$document->envelopeId,$viewrequest);
$redirecturl=$envelopview->getUrl();
}else{
$message=isset($envelop_summary->message) ? $envelop_summary->message : "unable to create envelope";
$wpdb->update( $wpdb->prefix.'reservation', array('envelope_id'=>$message), array('id'=>$reservation_id));
return builderUX_flash('danger',"Error occurred with connecting to DocuSign please contact us .");
}
Thanks In advance.
So i found the soultion and this is
webhooks
you can read this here Docusign WebhooksFot this you just need to add a few lines of code when you create the envelope.
The DocuSign Connect service will make an HTTPS POST to your application's server when envelope status changes, so you don't have to regularly poll envelopes for changes.
A general overview of Connect is available here: https://www.docusign.com/blog/dsdev-adding-webhooks-application/
an example listener is available here: https://github.com/docusign/docusign-soap-sdk/tree/master/PHP/Connect
You can set up Connect for your entire account or you can request Connect for a specific envelope by including the
eventNotification
object with your Envelopes: create API call.