使用PHP在DocuSign REST API中重新发送合同

问题描述 投票:1回答:1

我不是一个非常有经验的程序员,发现很难让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";
        }
    }

}
php docusignapi
1个回答
0
投票

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

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

对于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);
© www.soinside.com 2019 - 2024. All rights reserved.