私はREST APIを使用して複数の組織で使用されるソリューションを作成しています。DocuSign - API経由で通知を送信者に制御する方法
送信者側の誰が通知を受け取るかをAPIで制御する方法はありますか?デフォルトでは、すべての通知メールは、APIアカウントを作成したときに設定したメールに送信されます。しかし、実際に文書を送った人に通知を送る必要があります。
public static function sendForSignature($filename, //The name of the file that will show up in the email
$document_path, //The path to the file on the server
$template, //The json template file for this document
$opportunity=null, //The opportunity if applicable
$company_id=-1, //The company id if applicable
$contact_id=-1) //The contact if applicable
{
$envelop_summary = null;
$company = null;
$contact = null;
$sign_here_tabs=[];
$full_name_tabs=[];
$date_tabs=[];
$text_tabs=[];
$all_documents=[];
$basePath = Yii::getAlias('@frontend').'/doclib';
$mappingPath = $basePath.'/mapping';
$config = new \DocuSign\eSign\Configuration();
$config->setHost(\Yii::$app->params['docusign_host']);
$config->addDefaultHeader("X-DocuSign-Authentication",
"{\"Username\":\"" . \Yii::$app->params['docusign_username'] .
"\",\"Password\":\"" . \Yii::$app->params['docusign_password'] .
"\",\"IntegratorKey\":\"" . \Yii::$app->params['docusign_integrator_key'] . "\"}");
$apiClient = new \DocuSign\eSign\ApiClient($config);
$accountId = null;
$organization = Organization::findOne(['id' => Yii::$app->user->getIdentity()->org_id]);
$user = User::findOne(['id' => Yii::$app->user->getIdentity()->id]);
if($opportunity !== null){
$company = $opportunity->company;
$contact = $opportunity->contact;
}else{
$company = Company::findOne(['company_id' => $company_id]);
$contact = Contact::findOne(['contact_id' => $contact_id]);
}
try
{
//*** STEP 1 - Login API
$authenticationApi = new \DocuSign\eSign\Api\AuthenticationApi($apiClient);
$options = new \DocuSign\eSign\Api\AuthenticationApi\LoginOptions();
$loginInformation = $authenticationApi->login($options);
if(isset($loginInformation) && count($loginInformation) > 0)
{
$loginAccount = $loginInformation->getLoginAccounts()[0];
if(isset($loginInformation))
{
$accountId = $loginAccount->getAccountId();
$envelopeApi = new \DocuSign\eSign\Api\EnvelopesApi($apiClient);
$index = 0;
if(is_array($document_path)){
foreach($document_path as $d){
$pdf = new FPDI();
$page_count = $pdf->setSourceFile($d);
$document = new \DocuSign\eSign\Model\Document();
$document->setDocumentBase64(base64_encode(file_get_contents($d)));
$document->setName($filename[$index]);
$document->setDocumentId($index+1);
$all_documents[]=$document;
$template_file = json_decode(file_get_contents($mappingPath .'/'. $template[$index]));
foreach($template_file as $t){
if($t->type == 'signHereTab'){
$signHere = new \DocuSign\eSign\Model\SignHere();
if(isset($t->anchorString)){
$signHere->setAnchorString($t->anchorString);
$signHere->setAnchorXOffset($t->anchorXOffset);
$signHere->setAnchorYOffset($t->anchorYOffset);
$signHere->setAnchorUnits($t->anchorUnits);
}else if(isset($t->xPosition)){
$signHere->setXPosition($t->xPosition);
$signHere->setYPosition($t->yPosition);
}
// $signHere->setAnchorIgnoreIfNotPresent($t->anchorIgnoreIfNotPresent);
$signHere->setDocumentId($index+1);
if($t->page == -1){
$signHere->setPageNumber($page_count);
}else{
$signHere->setPageNumber($t->page);
}
$signHere->setRecipientId("1");
$sign_here_tabs[]=$signHere;
}else if($t->type == 'fullNameTab'){
$fullName = new \DocuSign\eSign\Model\FullName;
if(isset($t->anchorString)){
$fullName->setAnchorString($t->anchorString);
$fullName->setAnchorXOffset($t->anchorXOffset);
$fullName->setAnchorYOffset($t->anchorYOffset);
$fullName->setAnchorUnits($t->anchorUnits);
}else if(isset($t->xPosition)){
$fullName->setXPosition($t->xPosition);
$fullName->setYPosition($t->yPosition);
}
// $fullName->setAnchorIgnoreIfNotPresent($t->anchorIgnoreIfNotPresent);
$fullName->setDocumentId($index+1);
if($t->page == -1){
$fullName->setPageNumber($page_count);
}else{
$fullName->setPageNumber($t->page);
}
$fullName->setRecipientId(1);
$full_name_tabs[]=$fullName;
}else if($t->type == 'textTab'){
$text = new \DocuSign\eSign\Model\Text;
if(isset($t->anchorString)){
$text->setAnchorString($t->anchorString);
$text->setAnchorXOffset($t->anchorXOffset);
$text->setAnchorYOffset($t->anchorYOffset);
$text->setAnchorUnits($t->anchorUnits);
}else if(isset($t->xPosition)){
$text->setXPosition($t->xPosition);
$text->setYPosition($t->yPosition);
}
if(isset($t->label))
$text->setTabLabel($t->label);
// $text->setAnchorIgnoreIfNotPresent($t->anchorIgnoreIfNotPresent);
$text->setDocumentId($index+1);
if($t->page == -1){
$text->setPageNumber($page_count);
}else{
$text->setPageNumber($t->page);
}
$text->setRecipientId("1");
$text_tabs[]=$text;
}else if($t->type == 'dateTab'){
$date = new \DocuSign\eSign\Model\Date;
if(isset($t->anchorString)){
$date->setAnchorString($t->anchorString);
$date->setAnchorXOffset($t->anchorXOffset);
$date->setAnchorYOffset($t->anchorYOffset);
$date->setAnchorUnits($t->anchorUnits);
}else if(isset($t->xPosition)){
$date->setXPosition($t->xPosition);
$date->setYPosition($t->yPosition);
}
// $date->setAnchorIgnoreIfNotPresent($t->anchorIgnoreIfNotPresent);
$date->setDocumentId($index+1);
if($t->page == -1){
$date->setPageNumber($page_count);
}else{
$date->setPageNumber($t->page);
}
$date->setRecipientId(1);
$date_tabs[] = $date;
}
}
$index++;
}
}else{
// Add a document to the envelope
$document = new \DocuSign\eSign\Model\Document();
$document->setDocumentBase64(base64_encode(file_get_contents($document_path)));
$document->setName($filename);
$document->setDocumentId("1");
$all_documents[] = $document;
$pdf = new FPDI();
$page_count = $pdf->setSourceFile($document_path);
$template_file = json_decode(file_get_contents($mappingPath .'/'. $template));
foreach($template_file as $t){
if($t->type == 'signHereTab'){
$signHere = new \DocuSign\eSign\Model\SignHere();
if(isset($t->anchorString)){
$signHere->setAnchorString($t->anchorString);
$signHere->setAnchorXOffset($t->anchorXOffset);
$signHere->setAnchorYOffset($t->anchorYOffset);
$signHere->setAnchorUnits($t->anchorUnits);
}else if(isset($t->xPosition)){
$signHere->setXPosition($t->xPosition);
$signHere->setYPosition($t->yPosition);
}
// $signHere->setAnchorIgnoreIfNotPresent($t->anchorIgnoreIfNotPresent);
$signHere->setDocumentId("1");
if($t->page == -1){
$signHere->setPageNumber($page_count);
}else{
$signHere->setPageNumber($t->page);
}
$signHere->setRecipientId("1");
$sign_here_tabs[]=$signHere;
}else if($t->type == 'fullNameTab'){
$fullName = new \DocuSign\eSign\Model\FullName;
if(isset($t->anchorString)){
$fullName->setAnchorString($t->anchorString);
$fullName->setAnchorXOffset($t->anchorXOffset);
$fullName->setAnchorYOffset($t->anchorYOffset);
$fullName->setAnchorUnits($t->anchorUnits);
}else if(isset($t->xPosition)){
$fullName->setXPosition($t->xPosition);
$fullName->setYPosition($t->yPosition);
}
// $fullName->setAnchorIgnoreIfNotPresent($t->anchorIgnoreIfNotPresent);
$fullName->setDocumentId(1);
if($t->page == -1){
$fullName->setPageNumber($page_count);
}else{
$fullName->setPageNumber($t->page);
}
$fullName->setRecipientId(1);
$full_name_tabs[]=$fullName;
}else if($t->type == 'textTab'){
$text = new \DocuSign\eSign\Model\Text;
if(isset($t->anchorString)){
$text->setAnchorString($t->anchorString);
$text->setAnchorXOffset($t->anchorXOffset);
$text->setAnchorYOffset($t->anchorYOffset);
$text->setAnchorUnits($t->anchorUnits);
}else if(isset($t->xPosition)){
$text->setXPosition($t->xPosition);
$text->setYPosition($t->yPosition);
}
if(isset($t->label))
$text->setTabLabel($t->label);
// $text->setAnchorIgnoreIfNotPresent($t->anchorIgnoreIfNotPresent);
$text->setDocumentId("1");
if($t->page == -1){
$text->setPageNumber($page_count);
}else{
$text->setPageNumber($t->page);
}
$text->setRecipientId("1");
$text_tabs[]=$text;
}else if($t->type == 'dateTab'){
$date = new \DocuSign\eSign\Model\Date;
if(isset($t->anchorString)){
$date->setAnchorString($t->anchorString);
$date->setAnchorXOffset($t->anchorXOffset);
$date->setAnchorYOffset($t->anchorYOffset);
$date->setAnchorUnits($t->anchorUnits);
}else if(isset($t->xPosition)){
$date->setXPosition($t->xPosition);
$date->setYPosition($t->yPosition);
}
// $date->setAnchorIgnoreIfNotPresent($t->anchorIgnoreIfNotPresent);
$date->setDocumentId(1);
if($t->page == -1){
$date->setPageNumber($page_count);
}else{
$date->setPageNumber($t->page);
}
$date->setRecipientId(1);
$date_tabs[] = $date;
}
}
}
$tabs = new \DocuSign\eSign\Model\Tabs();
if(count($sign_here_tabs) > 0)
$tabs->SetSignHereTabs($sign_here_tabs);
if(count($full_name_tabs) > 0)
$tabs->setFullNameTabs($full_name_tabs);
if(count($text_tabs) > 0)
$tabs->setTextTabs($text_tabs);
if(count($date_tabs) > 0)
$tabs->setDateTabs($date_tabs);
$signer = new \DocuSign\eSign\Model\Signer();
$signer->setEmail(trim($contact->email));
if(!is_null($contact))
$signer->setName($contact->first_name.' '.$contact->last_name);
$signer->setRecipientId("1");
$signer->setTabs($tabs);
$emailNotification = new \DocuSign\eSign\Model\RecipientEmailNotification();
$emailNotification->setEmailSubject('Please sign these document(s).');
$signer->setEmailNotification($emailNotification);
// Add a recipient to sign the document
$recipients = new \DocuSign\eSign\Model\Recipients();
$recipients->setSigners(array($signer));
$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(\Yii::$app->params['docusign_callback_url']);
$event_notification->setLoggingEnabled("true");
$event_notification->setRequireAcknowledgment("false");
$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("false");
$event_notification->setEnvelopeEvents($envelope_events);
// $event_notification->setRecipientEvents($recipient_events);
$email_settings = new \DocuSign\eSign\Model\EmailSettings();
$email_settings->setReplyEmailAddressOverride($user->email);
$email_settings->setReplyEmailNameOverride($user->first_name.' '.$user->last_name);
$envelop_definition = new \DocuSign\eSign\Model\EnvelopeDefinition();
$envelop_definition->setEmailSubject("Document(s) from: ".$user->first_name.' '.$user->last_name.' '.$organization->name);
$envelop_definition->setEventNotification($event_notification);
$envelop_definition->setEmailSettings($email_settings);
// set envelope status to "sent" to immediately send the signature request
$status = 'sent';
$envelop_definition->setStatus($status);
$envelop_definition->setRecipients($recipients);
$envelop_definition->setDocuments($all_documents);
$envelop_summary = $envelopeApi->createEnvelope($accountId, $envelop_definition, null);
foreach($all_documents as $d){
$sd = new SignedDocument;
if($opportunity !== null)
$sd->opportunity_id = $opportunity->opportunity_id;
$sd->company_id = ($company == null) ? -1 : $company->company_id;
$sd->contact_id = ($contact == null) ? -1 : $contact->contact_id;
$sd->user_id = \Yii::$app->user->getIdentity()->id;
$sd->signature_id = $envelop_summary->getEnvelopeId();
$sd->save();
}
return 201;
}
}
}
catch (DocuSign\eSign\ApiException $ex)
{
Yii::error("Exception: " . $ex->getMessage().' '.$ex->getResponseBody(),'Signature');
return 500;
}
}
どの認証メカニズムを使用していますか?エンベロープ作成コードの一部を投稿できますか? –
こんにちは@CodingDawgは、署名のためにドキュメントを送信するコードの完全なセットを追加しました。ありがとう。 – O2U