docusign / docusign-esign-php-client

The Official Docusign PHP Client Library used to interact with the eSign REST API. Send, sign, and approve documents using this client.
https://www.docusign.com/devcenter
MIT License
198 stars 122 forks source link

Tabs assigned to signer & still showing free from signing on embedded signing #156

Closed realx4rd closed 2 years ago

realx4rd commented 2 years ago

Actual Preview

screenshot-demo docusign net-2021 10 27-12_04_43

Envelope Code

  private function make_envelope($args)
  {   

    $filename = 'file.pdf';

    $demo_docs_path = asset($filename);

    $arrContextOptions=array(
        "ssl"=>array(
            "verify_peer"=>false,
            "verify_peer_name"=>false,
        ),
    );  

    $content_bytes = file_get_contents($demo_docs_path,false, stream_context_create($arrContextOptions));
    // dd($content_bytes);
    $base64_file_content = base64_encode($content_bytes);
    // dd($base64_file_content);
    # Create the document model
    $document = new \DocuSign\eSign\Model\Document([# create the DocuSign document object
    'document_base64' => $base64_file_content,
        'name' => 'Example document 3', # 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 the signer recipient model
    $signer = new \DocuSign\eSign\Model\Signer([ # The signer
        'email' => 'aqib@gmail.com', 'name' => 'aqib',
        'recipient_id' => "1", 'routing_order' => "1",
        # Setting the client_user_id marks the signer as embedded
        'client_user_id' => $args['signer_client_id']
    ]);
    # Create a sign_here tab (field on the document)
    $sign_here = new \DocuSign\eSign\Model\SignHere([ # DocuSign SignHere field/tab
        'anchor_string' => '/sn1/', 'anchor_units' => 'pixels',
        'anchor_y_offset' => '10', 'anchor_x_offset' => '20'
    ]);
    # Add the tabs model (including the sign_here tab) to the signer
    # The Tabs object wants arrays of the different field/tab types
    $signer->settabs(new \DocuSign\eSign\Model\Tabs(['sign_here_tabs' => [$sign_here]]));
    # Next, create the top level envelope definition and populate it.
    $envelope_definition = new \DocuSign\eSign\Model\EnvelopeDefinition([
        'email_subject' => "Please sign this document sent from the PHP SDK",
        'documents' => [$document],
        # The Recipients object wants arrays for each recipient type
        'recipients' => new \DocuSign\eSign\Model\Recipients(['signers' => [$signer]]),
        'status' => "sent" # requests that the envelope be created and sent.
    ]);
    return $envelope_definition;
}

Creating RecipientView

 public function signDocument()
{       
    try{
        $this->args = $this->getTemplateArgs();

        $args = $this->args;

        $envelope_args = $args["envelope_args"];

        # Create the envelope request object
        $envelope_definition = $this->make_envelope($args["envelope_args"]);
        $envelope_api = $this->getEnvelopeApi();
        # Call Envelopes::create API method
        # Exceptions will be caught by the calling function

        $api_client = new \DocuSign\eSign\client\ApiClient($this->config);
        $envelope_api = new \DocuSign\eSign\Api\EnvelopesApi($api_client);
        $results = $envelope_api->createEnvelope($args['account_id'], $envelope_definition);
        $envelope_id = $results->getEnvelopeId();

        $authentication_method = 'None'; # How is this application authenticating
        # the signer? See the `authenticationMethod' definition
        # https://developers.docusign.com/esign-rest-api/reference/Envelopes/EnvelopeViews/createRecipient
        $recipient_view_request = new \DocuSign\eSign\Model\RecipientViewRequest([
            'authentication_method' => $authentication_method,
            'client_user_id' => $envelope_args['signer_client_id'],
            'recipient_id' => '1',
            'return_url' => $envelope_args['ds_return_url'],
            'user_name' => 'aqib', 'email' => 'aqib@gmail.com'
        ]);

        $results = $envelope_api->createRecipientView($args['account_id'], $envelope_id,$recipient_view_request);

        return redirect()->to($results['url']);
    } catch (Exception $e) {
        dd($e);
    }

}

Object debugging

download

HobbyProjects commented 2 years ago

It's unclear what you're asking about. If you're asking why the tab for the specific signer isn't showing up, please verify the anchor string "/sn1/" actually exists in your document.

Try removing the anchor string and just place the tab at a specific location - does it show up then? That could be an indication that the anchor string is not found.

In short, this is not a SDK related issue as your envelope is created as expected. I suggest that you post your question on Stackoverflow - https://stackoverflow.com/search?q=docusignapi, if you haven't already done so.