Can i get a request when the Docusign envelope status is completed from Docusign

你离开我真会死。 提交于 2020-03-05 03:26:31

问题


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.


回答1:


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.




回答2:


So i found the soultion and this is webhooks you can read this here Docusign Webhooks

Fot this you just need to add a few lines of code when you create the envelope.

// The envelope request includes a signer-recipient and their tabs object,
// and an eventNotification object which sets the parameters for
// webhook notifications to use from the DocuSign platform    
$envelope_events = [
    (new \DocuSign\eSign\Model\EnvelopeEvent())->setEnvelopeEventStatusCode("sent"),
    (new \DocuSign\eSign\Model\EnvelopeEvent())->setEnvelopeEventStatusCode("delivered"),
    (new \DocuSign\eSign\Model\EnvelopeEvent())->setEnvelopeEventStatusCode("completed"),
    (new \DocuSign\eSign\Model\EnvelopeEvent())->setEnvelopeEventStatusCode("declined"),
    (new \DocuSign\eSign\Model\EnvelopeEvent())->setEnvelopeEventStatusCode("voided"),
    (new \DocuSign\eSign\Model\EnvelopeEvent())->setEnvelopeEventStatusCode("sent"),
    (new \DocuSign\eSign\Model\EnvelopeEvent())->setEnvelopeEventStatusCode("sent")
];

$recipient_events = [
    (new \DocuSign\eSign\Model\RecipientEvent())->setRecipientEventStatusCode("Sent"),
    (new \DocuSign\eSign\Model\RecipientEvent())->setRecipientEventStatusCode("Delivered"),
    (new \DocuSign\eSign\Model\RecipientEvent())->setRecipientEventStatusCode("Completed"),
    (new \DocuSign\eSign\Model\RecipientEvent())->setRecipientEventStatusCode("Declined"),
    (new \DocuSign\eSign\Model\RecipientEvent())->setRecipientEventStatusCode("AuthenticationFailed"),
    (new \DocuSign\eSign\Model\RecipientEvent())->setRecipientEventStatusCode("AutoResponded")
];

$event_notification = new \DocuSign\eSign\Model\EventNotification();
$event_notification->setUrl($webhook_url);
$event_notification->setLoggingEnabled("true");
$event_notification->setRequireAcknowledgment("true");
$event_notification->setUseSoapInterface("false");
$event_notification->setIncludeCertificateWithSoap("false");
$event_notification->setSignMessageWithX509Cert("false");
$event_notification->setIncludeDocuments("true");
$event_notification->setIncludeEnvelopeVoidReason("true");
$event_notification->setIncludeTimeZone("true");
$event_notification->setIncludeSenderAccountAsCustomField("true");
$event_notification->setIncludeDocumentFields("true");
$event_notification->setIncludeCertificateOfCompletion("true");
$event_notification->setEnvelopeEvents($envelope_events);
$event_notification->setRecipientEvents($recipient_events);


来源:https://stackoverflow.com/questions/49284179/can-i-get-a-request-when-the-docusign-envelope-status-is-completed-from-docusign

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!