简体   繁体   中英

Using the PHP SDK, how do I replace my template base document when creating an envelope?

I have created a template using a base document (a customer contract) the details of which will change when I send out an envelope but the layout will remain the same. I am trying to replace the base document from the template when creating the envelope. I read from the manual that I need to call the EnvelopeDocuments:update method. Is this correct, if so how do I implement that?

Here is what I tried below that threw an error that I am unable to figure out.

**Updated code 2/1/21 for composite templates:

private function make_envelope(array $args): EnvelopeDefinition
{
    // create roles for signers
    $signer = new Signer([

        'email' => $args['signer_email'], 'name' => $args['signer_name'],
        'role_name' => "signer", 'recipient_id' => "1",
    ]);

    # Create the company signer recipient
    $companySigner = new Signer([

        'email' => $args['companySigner_email'], 'name' => $args['companySigner_name'],
        'role_name' => "companySigner", 'recipient_id' =>"2"

    ]);

    # Recipients object:
    $recipients_server_template = new Recipients([
        'signers' => [$signer, $companySigner]]);

    # Create a composite template
    $comp_template1 = new CompositeTemplate([
        'composite_template_id' => "1",
        'server_templates' => [
            new ServerTemplate([
                'sequence' => "1", 'template_id' => $args['template_id']])
        ],

        # Add the roles via an inlineTemplate
        'inline_templates' => [
            new InlineTemplate([
                'sequence' => "1",
                'recipients' => $recipients_server_template])
        ]

    ]);


    # Create the pdf document that will be added to the envelope
    $doc_file = 'Fiber_Connect_Customer_Agreement.pdf';
    $content_bytes = file_get_contents(self::DEMO_DOCS_PATH . $doc_file);
    $base64_file_content = base64_encode($content_bytes);

    # Create the document model
    $documentUpdated = new Document([  # create the DocuSign document object
        'document_base64' => $base64_file_content,
        'name' => 'Prepared Fiber Connect Customer Agreement',  # can be different from actual file name
        'file_extension' => 'pdf',  # many different document types are accepted
        'document_id' => '1'  # a label used to reference the doc


    # Create a composite template for the added document
    $comp_template2 = new CompositeTemplate([
        'composite_template_id' => "2",

        # Add the recipients via an inlineTemplate
        'inline_templates' => [
            new InlineTemplate([
                'sequence' => "2"])

        ],

        'document' => $documentUpdated]);

    # Create the envelope definition with the composited templates
    $envelope_definition = new EnvelopeDefinition([

        'status' => "sent",

        'composite_templates' => [$comp_template1, $comp_template2]

    ]);

    return $envelope_definition;

}

What you need to use are compositeTemplates. We have a pretty good guide on it here: https://developers.docusign.com/docs/esign-rest-api/how-to/request-signature-composite-template-embedded/

What you need to do is to create your template with the "base document" and when you're creating the envelope, you'd need to replace the base document from the serverTemplate by specifying the document field.

Let us know if you encounter any issues while getting this to work.

I was able to edit the code which is now working again if anyone is interested for the future.

/**
 * Creates envelope definition using composite templates
 * Parameters for the envelope: signer_email, signer_name, signer_client_id
 *
 * @param  $args array
 * @return mixed -- returns an envelope definition
 */
private function make_envelope(array $args): EnvelopeDefinition
{
    // create roles for signers
    $signer = new Signer([

        'email' => $args['signer_email'], 'name' => $args['signer_name'],
        'role_name' => "signer", 'recipient_id' => "1",
    ]);

    # Create the company signer recipient
    $companySigner = new Signer([

        'email' => $args['companySigner_email'], 'name' => $args['companySigner_name'],
        'role_name' => "companySigner", 'recipient_id' => "2"

    ]);

    # Recipients object:
    $recipients_server_template = new Recipients([
        'signers' => [$signer, $companySigner]
    ]);

  

    # Create the pdf document that will be added to the envelope
    $doc_file = 'Customer_Agreement_ADOBE_TABS.pdf';
    $content_bytes = file_get_contents(self::DEMO_DOCS_PATH . $doc_file);
    $base64_file_content = base64_encode($content_bytes);

    # Create the document model
    $documentUpdated = new Document([  # create the DocuSign document object
        'document_base64' => $base64_file_content,
        'name' => 'Updated Prepared Fiber Connect Customer Agreement',  # can be different from actual file name
        'file_extension' => 'pdf',  # many different document types are accepted
        'document_id' => '1'  # a label used to reference the doc
    ]);

    # Create a composite template for the added document
    $comp_template1 = new CompositeTemplate([
        'composite_template_id' => "1",
        'document' => $documentUpdated,
        'server_templates' => [
            new ServerTemplate([
                'sequence' => "1", 'template_id' => $args['template_id']
            ])
        ],
        # Add the roles via an inlineTemplate
        'inline_templates' => [
            new InlineTemplate([
                'sequence' => "1",
                'recipients' => $recipients_server_template
            ])
        ]
    ]);

    # Create the envelope definition with the composited templates
    $envelope_definition = new EnvelopeDefinition([

        'status' => "sent",

        'composite_templates' => [$comp_template1]

    ]);

    return $envelope_definition;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM