laravel-8docusignapidocusigncompositetmplts

How to put sign here tab on last page of document sending via DocuSignApi?


Here is my code for building envelope for multiple dynamic documents with DocuSign Api. It works fine for me but the main problem is it puts "sign here" tab on the first page of every documents. But, I want to put it on the last page of every documents. How can I achieve this in laravel? Can anyone suggests me for this?

private function buildEnvelope($envelopeFiles, $user): EnvelopeDefinition
    {
        $recipientEmail = $user->email;
        $recipientName = $user->first_name . " " . $user->last_name;

        // Create an array to store all CompositeTemplate objects
        $compositeTemplates = [];
        foreach ($envelopeFiles as $index => $documentPath) {
            $fileContent = file_get_contents($documentPath);
            $fileName = pathinfo($documentPath, PATHINFO_BASENAME);
            $fileExtension = pathinfo($documentPath, PATHINFO_EXTENSION);

            // Create a Document object for the current document
            $document = new Document([
                'document_base64' => base64_encode($fileContent),
                'name' => $fileName,
                'file_extension' => $fileExtension,
                'document_id' => $index + 1
            ]);

            // Create a SignHere tab for the current document
            $signHereTab = new SignHere([
                'document_id' => $index + 1,
                'page_number' => 1,
                'recipient_id' => '1',
                'tab_label' => 'Sign Here',
                'x_position' => '70',
                'y_position' => '780'
            ]);

            // Create a Tabs object for the current document with the SignHere tab
            $tabs = new Tabs([
                'sign_here_tabs' => [$signHereTab]
            ]);

            // Create a Signer object for the recipient with the Tabs object
            $recipient = new Signer([
                'email' => $recipientEmail,
                'name' => $recipientName,
                'recipient_id' => '1',
                'routing_order' => '1',
                'tabs' => $tabs
            ]);

            // Create an InlineTemplate object for the current document with the recipient
            $recipients = new Recipients(['signers' => [$recipient]]);
            $inlineTemplate = new InlineTemplate([
                'sequence' => $index + 1,
                'recipients' => $recipients
            ]);

            // Create a CompositeTemplate object for the current document with the Document 
            $compositeTemplate = new CompositeTemplate([
                'inline_templates' => [$inlineTemplate],
                'document' => $document
            ]);

            // Add the CompositeTemplate object to the array of CompositeTemplate objects
            $compositeTemplates[] = $compositeTemplate;
        }

        // Create the EnvelopeDefinition object with all the CompositeTemplate objects and other settings
        $envelopeDefinition = new EnvelopeDefinition([
            'composite_templates' => $compositeTemplates,
            'email_subject' => "Please sign the documents",
            'status' => "sent"
        ]);

        return $envelopeDefinition;
    }

Solution

  • This line:

    'page_number' => 1,
    

    Is what you need to update, but the problem is if every document/envelope has a variable number of pages, and you don't know how many, you'll have to first make an API call to find out. If you know it's 4 pages, you replace the "1" with "4", otherwise you have to make 3 API calls:

    1. Just to upload the documents to DocuSign, without the tabs/SignHere
    2. To get back the document object so you can know how many pages.
    3. To add just the SignHere tab

    Note: DocuSign cannot tell you how many pages will a document be until you sent it over to DocuSign using the API.