簡體   English   中英

DocuSign PHP API從模板創建信封,然后添加文檔

[英]DocuSign PHP API Creating Envelope from Template then add Document

我們正在嘗試第一個DocuSign API項目,但遇到了麻煩。 我們正在為DocuSign使用PHP API,並且嘗試從其中包含靜態文檔的模板創建信封,然后添加其他自定義生成的文檔,然后發送信封。 但是我們不知道如何使它工作。

我們最初嘗試創建信封,應用模板,然后添加靜態文檔,然后上傳/發送信封,僅發送模板。 然后,經過研究,嘗試創建信封,應用模板,上傳信封,添加靜態文檔然后發送,這也只發送了靜態頁面。

這是我們正在使用的當前代碼:

    public function send($signer_name,$signer_email, $cc_name, $cc_email, $template_id,$email_subject, $extrapdf = null) {
        $this->checkToken();
        $sign_here = new \DocuSign\eSign\Model\SignHere([
        'anchor_string' => '/sn1/', 'anchor_units' =>  'pixels',
        'anchor_y_offset' => '10', 'anchor_x_offset' => '20']);

        //create roles for signers

        $templateRole = new DocuSign\eSign\Model\TemplateRole();
        $templateRole->setEmail($signer_email);
        $templateRole->setName($signer_name);
        $templateRole->setRoleName('Signer 1');
        $templateRole->setTabs(new \DocuSign\eSign\Model\Tabs(['sign_here_tabs' => [$sign_here]]));

        $templateRole2 = new DocuSign\eSign\Model\TemplateRole();
        $templateRole2->setEmail($cc_email);
        $templateRole2->setName($cc_name);
        $templateRole2->setRoleName('Signer 2');
        $templateRole2->setTabs(new \DocuSign\eSign\Model\Tabs(['sign_here_tabs' => [$sign_here]]));

        //create envelope definition
        $envelop_definition = new DocuSign\eSign\Model\EnvelopeDefinition();
        //set template to be used on envelope
        $envelop_definition->setTemplateId($template_id);
        //set email subject on envelope
        $envelop_definition->setEmailSubject($email_subject);
        //apply template roles from above to envelope
        $envelop_definition->setTemplateRoles(array($templateRole, $templateRole2));
        //create new instance of envelope API
        $envelopeApi = new DocuSign\eSign\Api\EnvelopesApi(self::$apiClient);
        //go ahead and create the envelope at DocuSign
        $results = $envelopeApi->createEnvelope(self::$accountID, $envelop_definition);
        //get the created envelope Envelope ID
        $envelopeId = $results['envelope_id'];

        //create another envelope definition.
        $envelop_definition = new DocuSign\eSign\Model\EnvelopeDefinition();
        //see if we have an additional PDF to add to the envelope created above.
        if ($extrapdf != null) {
            //if so, base64 encode it.
            $extrapdf64 = base64_encode($extrapdf);
            //create a new document
            $document = new DocuSign\eSign\Model\Document();
            $document->setDocumentBase64($extrapdf64);
            $document->setName("HomeownershipCounseling.pdf");
            $document->setDocumentId("1");
            $document->setFileExtension("PDF");
            //attach document to envelope definition.
            $envelop_definition->setDocuments([$document]);         
            //update the envelope definition to sent to get DocuSign to actually send the envelope.
            $envelop_definition->setStatus('sent');
            //apply changes to the original envelope above.
            $results = $envelopeApi->update(self::$accountID, $envelopeId, $envelop_definition);
        }       
        return $results;
    }

信封會發送,但只會發送模板中的靜態文檔。 我們期望模板中的靜態文檔和動態生成的PDF都在DocuSign信封中。

謝謝!

弄清楚了...如果有人感興趣,請在此處發布。 謝謝!


  public function send($signer_name,$signer_email, $cc_name, $cc_email, $template_id,$email_subject, $extrapdf = null) {
        $this->checkToken();

        //create roles for signers

        $signer1 = new \DocuSign\eSign\Model\Signer([
            'email' => $signer_email, 'name' => $signer_name,
            'role_name' => "Signer 1", 'recipient_id' => "1"
        ]);


        $signer2 = new \DocuSign\eSign\Model\Signer([
            'email' => $cc_email, 'name' => $cc_name,
            'role_name' => "Signer 2", 'recipient_id' => "2"

        ]);

        $recipients_server_template = new \DocuSign\eSign\Model\Recipients([
            'signers' => [$signer1,$signer2]]);


        //create composite template
        $comp_template1 = new \DocuSign\eSign\Model\CompositeTemplate([
            'composite_template_id' => "1",
            'server_templates' => [
                new \DocuSign\eSign\Model\ServerTemplate([
                    'sequence' => "1", 'template_id' => $template_id])
            ],
            # Add the roles via an inlineTemplate
            'inline_templates' => [
                new \DocuSign\eSign\Model\InlineTemplate([
                    'sequence' => "1",
                    'recipients' => $recipients_server_template])
            ]

        ]);

        //create new document to be added
        $doc1_b64 = base64_encode($extrapdf);
        $doc1 = new DocuSign\eSign\Model\Document([
            'document_base64' => $doc1_b64,
            'name' => 'HomeownershipCounseling', # can be different from
                                                 # actual file name
            'file_extension' => 'pdf', 'document_id' =>'1']);

        $comp_template2 = new DocuSign\eSign\Model\CompositeTemplate([
            'composite_template_id' => "2",
            # Add the recipients via an inlineTemplate
            'inline_templates' => [
                new \DocuSign\eSign\Model\InlineTemplate([
                    'sequence' => "2"])
            ],
            'document' => $doc1]);


        //create envelope definition
        $envelop_definition = new DocuSign\eSign\Model\EnvelopeDefinition();
        //set email subject on envelope
        $envelop_definition->setEmailSubject($email_subject);
        $envelop_definition->setCompositeTemplates(array($comp_template1, $comp_template2));
        $envelop_definition->setStatus('sent');
        //create new instance of envelope API
        $envelopeApi = new DocuSign\eSign\Api\EnvelopesApi(self::$apiClient);
        //go ahead and create the envelope at DocuSign
        $results = $envelopeApi->createEnvelope(self::$accountID, $envelop_definition);
        //get the created envelope Envelope ID
        $envelopeId = $results['envelope_id'];


        return $results;
    }

暫無
暫無

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

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