簡體   English   中英

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

[英]Resend Contract in DocuSign REST API with PHP

我不是一個非常有經驗的程序員,並且發現很難使DocuSign API集成按客戶希望的方式工作。 我的問題是找到一個穩定的解決方案,以便在丟失合同的情況下再次將合同重新發送給同一收件人。 我花了一段時間才找到可以創建新電子郵件的內容,而不僅僅是偶爾發送。 在我的案例中,Trick做了一個注釋。

如果有人可以使用以下代碼:

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";
        }
    }

}

感謝您的解決方案和使用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);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM