文档签名 PHP API 从模板创建信封,然后添加文档



我们正在尝试我们的第一个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 DocuSigneSignModelSignHere([
        'anchor_string' => '/sn1/', 'anchor_units' =>  'pixels',
        'anchor_y_offset' => '10', 'anchor_x_offset' => '20']);
        //create roles for signers
        $templateRole = new DocuSigneSignModelTemplateRole();
        $templateRole->setEmail($signer_email);
        $templateRole->setName($signer_name);
        $templateRole->setRoleName('Signer 1');
        $templateRole->setTabs(new DocuSigneSignModelTabs(['sign_here_tabs' => [$sign_here]]));
        $templateRole2 = new DocuSigneSignModelTemplateRole();
        $templateRole2->setEmail($cc_email);
        $templateRole2->setName($cc_name);
        $templateRole2->setRoleName('Signer 2');
        $templateRole2->setTabs(new DocuSigneSignModelTabs(['sign_here_tabs' => [$sign_here]]));
        //create envelope definition
        $envelop_definition = new DocuSigneSignModelEnvelopeDefinition();
        //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 DocuSigneSignApiEnvelopesApi(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 DocuSigneSignModelEnvelopeDefinition();
        //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 DocuSigneSignModelDocument();
            $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 DocuSigneSignModelSigner([
            'email' => $signer_email, 'name' => $signer_name,
            'role_name' => "Signer 1", 'recipient_id' => "1"
        ]);

        $signer2 = new DocuSigneSignModelSigner([
            'email' => $cc_email, 'name' => $cc_name,
            'role_name' => "Signer 2", 'recipient_id' => "2"
        ]);
        $recipients_server_template = new DocuSigneSignModelRecipients([
            'signers' => [$signer1,$signer2]]);

        //create composite template
        $comp_template1 = new DocuSigneSignModelCompositeTemplate([
            'composite_template_id' => "1",
            'server_templates' => [
                new DocuSigneSignModelServerTemplate([
                    'sequence' => "1", 'template_id' => $template_id])
            ],
            # Add the roles via an inlineTemplate
            'inline_templates' => [
                new DocuSigneSignModelInlineTemplate([
                    'sequence' => "1",
                    'recipients' => $recipients_server_template])
            ]
        ]);
        //create new document to be added
        $doc1_b64 = base64_encode($extrapdf);
        $doc1 = new DocuSigneSignModelDocument([
            'document_base64' => $doc1_b64,
            'name' => 'HomeownershipCounseling', # can be different from
                                                 # actual file name
            'file_extension' => 'pdf', 'document_id' =>'1']);
        $comp_template2 = new DocuSigneSignModelCompositeTemplate([
            'composite_template_id' => "2",
            # Add the recipients via an inlineTemplate
            'inline_templates' => [
                new DocuSigneSignModelInlineTemplate([
                    'sequence' => "2"])
            ],
            'document' => $doc1]);

        //create envelope definition
        $envelop_definition = new DocuSigneSignModelEnvelopeDefinition();
        //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 DocuSigneSignApiEnvelopesApi(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;
    }

最新更新