0

我正在研究 DocuSign 集成。我具有基本功能,但似乎无法弄清楚如何将本地文档 (PDF) 与服务器模板合并,以便在服务器模板上配置的选项卡被使用或覆盖在传递的文档上。

我的模板是在服务器上定义的,我可以直接从 Web UI 使用它而不会出现问题(它是 W4 表单)。该模板具有三个选项卡(SSN、在此处签名和日期),如下所示。使用 API Explorer 通过其 ID 访问此模板会产生以下 json

{
    "envelopeTemplateDefinition": {
        "templateId": "_redacted_",
        "name": "W4 3/13/2017",
        "shared": "true",
        "password": "",
        "description": "",
        "lastModified": "2017-06-05T18:45:28.4470000Z",
        "lastModifiedBy": {
            "userName": "Andrew",
            "userId": "_redacted_",
            "email": "my_email_address",
            "uri": "/users/_redacted_
        },
        "pageCount": 2,
        "uri": "/templates/_redacted_",
        "folderName": "Templates",
        "folderId": "_redacted_",
        "folderUri": "/folders/_redacted_",
        "owner": {
            "userName": "Andrew",
            "userId": "_redacted_",
            "email": "my_email_address"
        }
    },
    "documents": [
        {
            "documentId": "46677269",
            "uri": "/envelopes/_redacted_/documents/46677269",
            "name": "W4.pdf",
            "order": "1",
            "pages": "2",
            "display": "inline",
            "includeInDownload": "true",
            "signerMustAcknowledge": "no_interaction",
            "templateLocked": "false",
            "templateRequired": "false",
            "documentGroup": "content"
        }
    ],
    "emailSubject": "Please DocuSign: W4.pdf",
    "emailBlurb": "",
    "signingLocation": "online",
    "autoNavigation": "true",
    "envelopeIdStamping": "true",
    "authoritativeCopy": "false",
    "notification": {
        "reminders": {
            "reminderEnabled": "false",
            "reminderDelay": "0",
            "reminderFrequency": "0"
        },
        "expirations": {
            "expireEnabled": "true",
            "expireAfter": "120",
            "expireWarn": "0"
        }
    },
    "enforceSignerVisibility": "false",
    "enableWetSign": "true",
    "allowMarkup": "false",
    "allowReassign": "true",
    "recipients": {
        "signers": [
            {
                "defaultRecipient": "false",
                "tabs": {
                    "signHereTabs": [
                        {
                            "stampType": "signature",
                            "name": "SignHere",
                            "tabLabel": "Signature _redacted_",
                            "scaleValue": 1.0,
                            "optional": "false",
                            "documentId": "46677269",
                            "recipientId": "94043042",
                            "pageNumber": "1",
                            "xPosition": "193",
                            "yPosition": "682",
                            "tabId": "_redacted_",
                            "templateLocked": "false",
                            "templateRequired": "false"
                        }
                    ],
                    "dateSignedTabs": [
                        {
                            "name": "DateSigned",
                            "value": "",
                            "tabLabel": "Date Signed _redacted_",
                            "font": "lucidaconsole",
                            "fontColor": "black",
                            "fontSize": "size9",
                            "documentId": "46677269",
                            "recipientId": "94043042",
                            "pageNumber": "1",
                            "xPosition": "480",
                            "yPosition": "713",
                            "tabId": "_redacted_",
                            "templateLocked": "false",
                            "templateRequired": "false"
                        }
                    ],
                    "ssnTabs": [
                        {
                            "validationPattern": "",
                            "validationMessage": "",
                            "shared": "false",
                            "requireInitialOnSharedChange": "false",
                            "requireAll": "false",
                            "value": "",
                            "width": 144,
                            "required": "true",
                            "locked": "false",
                            "concealValueOnDocument": "true",
                            "disableAutoSize": "false",
                            "maxLength": 4000,
                            "tabLabel": "Text _redacted_",
                            "font": "lucidaconsole",
                            "fontColor": "black",
                            "fontSize": "size9",
                            "documentId": "46677269",
                            "recipientId": "94043042",
                            "pageNumber": "1",
                            "xPosition": "442",
                            "yPosition": "563",
                            "tabId": "_redacted_",
                            "templateLocked": "false",
                            "templateRequired": "false"
                        }
                    ]
                },
                "signInEachLocation": "false",
                "name": "",
                "email": "",
                "recipientId": "94043042",
                "accessCode": "",
                "requireIdLookup": "false",
                "routingOrder": "1",
                "note": "",
                "roleName": "New Employee",
                "deliveryMethod": "email",
                "templateLocked": "false",
                "templateRequired": "false",
                "inheritEmailNotificationConfiguration": "false"
            }
        ],
        "agents": [ ],
        "editors": [ ],
        "intermediaries": [ ],
        "carbonCopies": [ ],
        "certifiedDeliveries": [ ],
        "inPersonSigners": [ ],
        "recipientCount": "1"
    }
}

我想要做的是将此模板应用于已经部分填写的PDF,这样当签名者得到它时,服务器模板中定义的选项卡将用于sing。

就目前而言,什么都没有。只是我在下面作为 base64 数据传入的部分填写的 PDF,没有要填写或签名的服务器模板选项卡。这是我用于 API 调用的 json(在 PHP 中)。

  $data = array (
        "emailBlurb" => "Test Email Body",
        "emailSubject" => "Test Email Subject",
        "status" => "sent",
        "compositeTemplates" => array(array(
            "document" => array(
                "documentId" => 46677269,
                "name" => $documentName,
                "documentBase64" => $document
            ),
            "serverTemplates" => array(array(

                "sequence" => 1,
                "templateId" => "_redacted_"
            )),
            "inlineTemplates" => array(array(
                "sequence" => 2,
                "recipients" => array(
                    "signers" => array(array(
                        "email" => $recipientEmail,
                        "name" => $recipientName,
                        "recipientId" => $recipientID,
                        "roleName" => "New Employee"
                    ))
                )
            ))
        ))
  ); //$data = array...

我怀疑我只是缺少对服务器模板中定义的选项卡的一些适当引用。但是文档很糟糕,我已经花了几个小时梳理网络。任何帮助将非常感激。

更新1

根据要求,这是成功生成信封的代码:

function c_requestSignature($templateID, $recipientName, $recipientEmail, $recipientID, $document){
  //function sets up the passed document for signing using the specified template
  $documentName = "W4"; //FIXME fetch document name using templateID
  $baseURL = c_docusignBaseURL();
  $accountId = c_docusignAccountId();
  $header = c_docusignHeader();
  $data = array (
        "emailSubject" => "Please sign " . $documentName,
        //"emailBlurb" => "Test Email Body",
        "status" => "sent",
        "compositeTemplates" => array(
            "compositeTemplate" => array(
                "serverTemplates" => array(
                    "serverTemplate" => array(
                        "sequence" => "1",
                        "templateId" => "_redacted_"
                    )
                ),
                "inlineTemplates" => array(
                    "inlineTemplate" => array(
                        "sequence" => "2",
                        "recipients" => array(
                            "signers" => array(
                                "signer" => array(
                                    "name" => $recipientName,
                                    "email" => $recipientEmail,
                                    "roleName" => "NewHire"
                                )
                            )
                        )
                    )
                ),
                "document" => array(
                    "documentId" => "1",
                    "name" => $documentName,
                    "fileExtension" => "pdf",
                    "documentBase64" => $document
                )
            )
        )
  );

  // Send to the /envelopes end point, which is relative to the baseUrl received above.
  $curl = curl_init($baseURL . "/envelopes" );
  curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($curl, CURLOPT_POST, true);
  curl_setopt($curl, CURLOPT_POSTFIELDS, $data_string);
  curl_setopt($curl, CURLOPT_HTTPHEADER, array(
    'Content-Type: application/json',
    'Content-Length: ' . strlen($data_string),
    "X-DocuSign-Authentication: $header" )
  );

  $json_response = curl_exec($curl); // Do it!

  $status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
  if ( $status != 201 ) {
    echo "Error calling DocuSign, status is:" . $status . "\nerror text: ";
    print_r($json_response); echo "\n";
    exit(-1);
  }

  $response = json_decode($json_response, true);
  $envelopeId = $response["envelopeId"];

  error_log ("successfully created envelope: $envelopeId");
  $url = getSignatureURL($envelopeId, $recipientName, $recipientEmail, $recipientID);
  return $url;
}//c_requestSignature()...

函数 getSignatureURL() 的代码如下:

function getSignatureURL($envelopeId, $recipientName, $recipientEmail, $recipientID){
  //function retrieves the signing ceremony UX URL from DocuSign
  $baseURL = c_docusignBaseURL();
  $accountId = c_docusignAccountId();
  $header = c_docusignHeader();
  //set up the data we'll send to the Docusign server
  $data = array("returnUrl" => "http://_redacted_",
    "authenticationMethod" => "none",
    "email" => $recipientEmail,
    "name" => $recipientName,
    "recipientId" => $recipientID,
    //"recipientId" => "1",
    //"clientUserId" => $recipientID,
    "userName" => $recipientName
  );
  $data_string = json_encode($data);
  //set up curl
  $curl = curl_init($baseURL . "/envelopes/$envelopeId/views/recipient" );
  curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($curl, CURLOPT_POST, true);
  curl_setopt($curl, CURLOPT_POSTFIELDS, $data_string);
  curl_setopt($curl, CURLOPT_HTTPHEADER, array(
    'Content-Type: application/json',
    'Content-Length: ' . strlen($data_string),
    "X-DocuSign-Authentication: $header" )
  );
  //make the API call
  $json_response = curl_exec($curl);
  $status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
  if ( $status != 201 ) {
    echo "error calling webservice, status is:" . $status . "\nerror text is --> ";
    print_r($json_response); echo "\n";
    exit(-1);
  }
  //retrieve and process the response
  $response = json_decode($json_response, true);
  return $response["url"];
}

更新 2

这是所要求的原始json...

{
  "emailSubject": "some subject",
  "status": "sent",
  "compositeTemplates": [
    {
      "serverTemplates": [
        {
          "sequence": "1",
          "templateId": "_redacted_"
        }
      ],
      "inlineTemplates": [
        {
          "sequence": "2",
          "recipients": {
            "signers": [
              {
                "name": "Andrew Tester1",
                "email": "my_email_address",
                "roleName": "NewHire",
                "recipientId": "1234",
                "clientUserId": "1234"
              }
            ]
          }
        }
      ],
      "document": {
        "documentId": "1",
        "name": "W4",
        "fileExtension": "pdf",
        "documentBase64": "_redacted_"
      }
    }
  ]
}

更新 3

我遇到了一个问题,它阻止我看到上述 json 的正确输出。修复后,现在我收到以下错误:

调用 DocuSign 时出错,状态为:400 错误文本:{“errorCode”:“TAB_REFERS_TO_MISSING_DOCUMENT”,“message”:“选项卡元素中指定的 DocumentId 不引用此信封中的文档。Tab 引用 DocumentId 46677269,它不是当下。” }

如果我将上面的文档节更改如下:

      "document": {
        "documentId": "46677269",
        "name": "W4",
        "fileExtension": "pdf",
        "documentBase64": "_redacted_"
      }

错误消失了,但我仍然得到一个没有标签的签字仪式。

4

2 回答 2

0

以下请求可用于从服务器模板创建信封。服务器模板文档将替换为请求中指定的新文档。

{
    "emailSubject": "Test Email Subject",
    "emailBlurb" :  "Test Email Body",
    "status": "sent",
    "compositeTemplates": [
        {
            "serverTemplates": [
                {
                    "sequence": "1",
                    "templateId": "86841739-f12d-460e-9807-23a9b90cff6b"
                }
            ],
            "inlineTemplates": [
                {
                    "sequence": "1",
                    "recipients": {
                        "signers": [
                            {
                                "name": "Jane Doe",
                                "email": "janedoe@acme.com",
                                "roleName": "New Employee"
                            }
                        ]
                    }
                }
            ],       
            "document": {
                "documentId": "1",
                "name": "Your Doc Name",
                "fileExtension": "pdf",
                "documentBase64": ""
            }
        }       
    ]
}
于 2017-06-05T20:00:46.403 回答
0

嗯,这是一个棘手的问题,但我(终于)找到了解决方案,在 Docusign 的一些人的帮助下。我想我会把它贴在这里给那些将来可能会遇到这个问题的人。

解决方案 传递给 DocuSign API 的 json 结构非常重要。如果其中有任何错误,它将无法正常工作,并且错误消息并不总是有用的。此外,在我所做的事情中,传递的具体参数也很关键。上面的信封生成代码是正确的,但需要注意的是您必须指定作为存储在 DocuSign 服务器上的模板的一部分的 PDF 文档 ID。你可以通过他们的 API 查询这个给定的信封 ID(这就是我正在做的)。显然这过去不是必需的,但现在它是必需的,而且任何地方都没有说明这一点的文档。

不过,我对签名选项卡的根本问题是请求签名仪式 URL 的代码。我有额外的参数被无误地接受,但是把事情搞砸了。发现这一点,通过使用 DocuSign 的REST API 资源管理器生成一个有效的签名仪式 URL(包含所有正确的签名选项卡),并将输出 json 与我试图在我的代码中传递的内容进行比较。

这是生成正确 json 的有效 PHP 代码:

  $data = array(
    "authenticationMethod" => "email",
    "clientUserId" => $recipientID,
    "email" => $recipientEmail,
    "returnUrl" => "_redacted_", 
    "userName" => $recipientName
  );
  $data_string = json_encode($data);
于 2017-06-18T17:16:38.830 回答