首页 > 解决方案 > 使用 PHP 在 DocuSign REST API 中重新发送合同

问题描述

我不是一个非常有经验的程序员,并且发现很难让 DocuSign API 集成按照我的客户想要的方式工作。我的问题是找到一个稳定的解决方案,将合同重新发送给同一个收件人,以防他丢失。我花了一段时间才找到总是会创建新电子邮件的东西,而不仅仅是偶尔。在我的例子中,添加一个注释就可以了。

这是任何人都可以使用的代码:

class DocuSignSample
{
    public function ResendEmail($args)
    {
        global $docusign_args;
        $username = $docusign_args['username'];
        $password = $docusign_args['password'];
        $integrator_key = $docusign_args['integrator_key'];  

        // change to production (www.docusign.net) before going live
        $host = $docusign_args['host'];

        // create configuration object and configure custom auth header
        $config = new DocuSign\eSign\Configuration();
        $config->setHost($host);
        $config->addDefaultHeader("X-DocuSign-Authentication", "{\"Username\":\"" . $username . "\",\"Password\":\"" . $password . "\",\"IntegratorKey\":\"" . $integrator_key . "\"}");

        // instantiate a new docusign api client
        $apiClient = new DocuSign\eSign\ApiClient($config);
        $accountId = null;

        try 
        {
            //*** STEP 1 - Login API: get first Account ID and baseURL
            $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];
                $host = $loginAccount->getBaseUrl();
                $host = explode("/v2",$host);
                $host = $host[0];

                // UPDATE configuration object
                $config->setHost($host);

                // instantiate a NEW docusign api client (that has the correct baseUrl/host)
                $apiClient = new DocuSign\eSign\ApiClient($config);

                if(isset($loginInformation))
                {
                    $accountId = $loginAccount->getAccountId();
                    if(!empty($accountId))
                    {

                        // Set Up Recipient Data, Update note with current date
                        $Recipient = new \stdClass();
                        $Recipient->RecipientId='1';                        // In my case it is always No. 1
                        $Recipient->Email=$args['signer_email'];
                        $Recipient->name=$args['signer_name'];
                        $Recipient->Note='Resent on '.date("d.m.Y")." at ".date("H:i:s");

                        // Set Up Options - Put Recipients in Array
                        $options->Signers[] = $Recipient;
                        $options->resend_envelope='true';
                        $options->status='signed';
                        $options=json_encode($options);

                        // Update the Envelope Recipients
                        $envelopeApi = new DocuSign\eSign\Api\EnvelopesApi($apiClient);
                        $results = $envelopeApi->updateRecipients($accountId, $args['envelope_id'],$options);

                        // Get Envelope Recipients Details
                        $results2 = $envelopeApi->listRecipients($accountId, $args['envelope_id']);
                        echo "<br><br>";
                        print_r($results2);

                        if(!empty($results))
                        {
                            return "$results";
                        }

                    }
                }
            }
        }

        catch (DocuSign\eSign\ApiException $ex)
        {
            $error= $ex->getResponseBody()->errorCode . " " . $ex->getResponseBody()->message;
            echo "$error";
        }
    }

}

标签: phpdocusignapi

解决方案


感谢您的解决方案和使用 DocuSign。如果您只想发送有关正在等待签名的当前信封的提醒电子邮件,那么推荐的技术是使用Envelopes::update并将查询参数resend_envelope设置为 true。

我会先尝试一个空的请求对象,或者只提供信封Id。

对于 PHP,未经测试的代码:

$envelopeApi = new DocuSign\eSign\Api\EnvelopesApi($apiClient);
$options = new DocuSign\EnvelopesApi\UpdateOptions([resend_envelope => true]);
$body = new DocuSign\eSign\Model\Envelope([envelope_id => $envelope_id]);
$results = $envelopeApi->update($accountId, $envelope_id, $body, $options);

推荐阅读