NilsonCain
NilsonCain

Reputation: 111

How to get multiple signatures in an envelope from one recipient? DocuSign PHP SDK

I have an need to get one Recipient to sign in multiple places in one Envelope. Perhaps I have missed some documentation on the proper way to do this, but I have been unsuccessful in searching this. Here is my method for adding recipients:

function addSigner($signerName, $signerEmail, $xPos, $yPos, $documentId = 1, $documentPage = 1)
{
    $index = count($this->signers);
    $this->signers[$index] = new DocuSign\eSign\Model\Signer();
    $this->signers[$index]->setName($signerName);
    $this->signers[$index]->setEmail($signerEmail);
    $this->signers[$index]->setRecipientId((string)$index + 1);
    $this->sigFields[$index] = new DocuSign\eSign\Model\SignHere();
    $this->sigFields[$index]->setXPosition($xPos);
    $this->sigFields[$index]->setYPosition($yPos);
    $this->sigFields[$index]->setDocumentId($documentId);
    $this->sigFields[$index]->setPageNumber($documentPage);
    $this->sigFields[$index]->setRecipientId((string)$index + 1);
    $this->sigTabs[$index] = new DocuSign\eSign\Model\Tabs();
    $this->sigTabs[$index]->setSignHereTabs(array($this->sigFields[$index]));

    return $index;
}

And here's my attempt to call the method

$test->addSigner('Nilson Cain', '[email protected]', 90, 652, 1, 1);
$test->addSigner('Nilson Cain', '[email protected]', 90, 652, 2, 1);

Unfortunately this results in this generic error (which I don't get without the duplicate Recipient.)

Exception: exception 'DocuSign\eSign\ApiException' with message '[400] Error connecting to the API 

Thanks for any help!

Upvotes: 0

Views: 415

Answers (1)

NilsonCain
NilsonCain

Reputation: 111

I solved this by first splitting the addSigner() method up into two parts. One method to add a Recipient, and another method to add a SignHereTab. You can have multiple SignHereTabs per Recipient, but not duplicate Recipients.

function addRecipient($signerName, $signerEmail)
{
    $index = count($this->signers);
    $this->signers[$index] = new DocuSign\eSign\Model\Signer();
    $this->signers[$index]->setName($signerName);
    $this->signers[$index]->setEmail($signerEmail);
    $this->signers[$index]->setRecipientId($index + 1);
    $this->sigTabs[$index] = new DocuSign\eSign\Model\Tabs();

    return $index;
}

function addSignHereTab($signerId, $xPos, $yPos, $documentId = 1, $documentPage = 1)
{
    $index = count($this->sigFields);
    $this->sigFields[$index] = new DocuSign\eSign\Model\SignHere();
    $this->sigFields[$index]->setXPosition($xPos);
    $this->sigFields[$index]->setYPosition($yPos);
    $this->sigFields[$index]->setDocumentId($documentId);
    $this->sigFields[$index]->setPageNumber($documentPage);
    $this->sigFields[$index]->setRecipientId($signerId + 1);

    return $index;
}

I also moved the setSignHereTabs to my SendEnvelope method which will be called after the Recipients and SignHereTabs are all created.

// add tabs to the document
foreach($this->signers as $signerId => $signer)
{
    $this->sigTabs[$signerId]->setSignHereTabs($this->sigFields);
    $this->sigTabs[$signerId]->setDateSignedTabs($this->dateSignedFields);
    $this->signers[$signerId]->setTabs($this->sigTabs[$signerId]);
}

Upvotes: 1

Related Questions