从Docusign完成Docusign信封状态后,我是否可以收到请求

时间:2018-03-14 17:27:13

标签: php docusignapi docusigncompositetmplts

我正在使用Docuisign为我的客户将其用作数字签名。我正在使用php rest API,我有5个模板角色,一切都很完美。

所以我希望在信封状态完成后从Docusign获取我的服务器上的请求。所以我也可以更新我身边的状态。

我脑子里有一个解决方案

1)解决方案1 ​​

我可以创建一个cron作业来检查信封的状态,但是我的服务器上已经运行了4个老鼠,所以我避免使用这个解决方案

我的代码是

$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 .");
}

提前致谢。

2 个答案:

答案 0 :(得分:2)

当信封状态发生变化时,DocuSign Connect服务将向您的应用程序服务器发送HTTPS POST,因此您无需定期轮询信封以进行更改。

此处提供了Connect的一般概述:https://www.docusign.com/blog/dsdev-adding-webhooks-application/

此处提供了一个示例侦听器:https://github.com/docusign/docusign-soap-sdk/tree/master/PHP/Connect

您可以为整个帐户设置Connect,也可以通过在信封中加入eventNotification对象来请求特定信封的连接:创建API调用。

答案 1 :(得分:0)

所以我找到了灵魂,这是webhooks你可以在这里阅读Docusign Webhooks

今天你只需要在创建信封时添加几行代码。

// 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);