DocuSign PHP API从模板创建信封,然后添加文档 [英] DocuSign PHP API Creating Envelope from Template then add Document

查看:68
本文介绍了DocuSign PHP API从模板创建信封,然后添加文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在尝试第一个DocuSign API项目,但遇到了麻烦.我们正在为DocuSign使用PHP API,并且尝试从其中包含静态文档的模板创建信封,然后添加其他自定义生成的文档,然后发送信封.但是我们不知道如何使它工作.

we are attempting our first DocuSign API Project and have hit a snag. We're using PHP API for DocuSign, and we are attempting to create an envelope from a template that has static documents inside it, then add one other custom-generated document, then send the envelope. But we can't figure out how to make it work.

我们最初尝试创建信封,应用模板,然后添加静态文档,然后上传/发送信封,仅发送模板.然后,经过研究,尝试创建信封,应用模板,上传信封,添加静态文档然后发送,这也只发送了静态页面.

We originally tried creating the envelope, apply the template, then add the static document, then upload/sending the envelope, which only sends the template. Then, after research, tried creating the envelope, apply the template, upload the envelope, add the static document then sending, which only sent the static pages too.

这是我们当前正在使用的代码:

Here's our current code we're using:

    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信封中.

The envelope does send, but it only sends the static document that was in the template. We're expecting the static document in the template AND the dynamically generated PDF to both be in the DocuSign Envelope.

谢谢!

推荐答案

知道了这个...如果有人感兴趣,请在此处发布.谢谢!

Got this figured out... posting here in case anyone is ever interested. Thank you!


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

这篇关于DocuSign PHP API从模板创建信封,然后添加文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆