0

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

所以我想在信封状态完成后从 Docusign 向我的服务器发出请求。这样我也可以更新我这边的状态。

我有一个解决方案

1)解决方案1

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

我的代码是

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

提前致谢。

4

2 回答 2

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对象包含在您的 Envelopes 中来请求 Connect 以获得特定的信封:创建 API 调用。

于 2018-03-14T18:29:57.917 回答
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);
于 2018-05-14T07:41:07.563 回答