1

I seem to be lost in the REST API/PHP syntax and documentation of the DocuSign PHP client has been less than helpful. The problem I'm solving is how to add two remote signers (both must sign) to one envelope. It is important that both sign the document.

If I use this code, only the second one gets the email and after he signs, the document is completed. (edit: included complete code)

echo 'Docusign php file alive, results (potentially) below<p><p>';
//Get variables from ???esign.php
$recemail = 'martin.strnad@xxx.com';
$recname = 'test name partner';
$xsoftrecemail = 'martin.strnad@yyy.com';
$xsoftrecname = 'test name employee';

require_once('vendor/autoload.php');
require_once('vendor/docusign/esign-client/autoload.php');
// DocuSign account credentials & Integrator Key
$username = "";
$password = "";
$integrator_key = "";
$host = "https://demo.docusign.net/restapi";
// create a new DocuSign configuration and assign host and header(s)
$config = new DocuSign\eSign\Configuration();
$config->setHost($host);
$config->addDefaultHeader("X-DocuSign-Authentication", "{\"Username\":\"" . 
$username . "\",\"Password\":\"" . $password . "\",\"IntegratorKey\":\"" . 
$integrator_key . "\"}");
/////////////////////////////////////////////////////////////////////////
// STEP 1:  Login() API
/////////////////////////////////////////////////////////////////////////
// instantiate a new docusign api client
$apiClient = new DocuSign\eSign\ApiClient($config);
// we will first make the Login() call which exists in the 
AuthenticationApi...
$authenticationApi = new DocuSign\eSign\Api\AuthenticationApi($apiClient);
// optional login parameters
$options = new \DocuSign\eSign\Api\AuthenticationApi\LoginOptions();
// call the login() API
$loginInformation = $authenticationApi->login($options);
// parse the login results
if(isset($loginInformation) && count($loginInformation) > 0)
{
// note: defaulting to first account found, user might be a member of multiple accounts
$loginAccount = $loginInformation->getLoginAccounts()[0];
    if(isset($loginInformation))
    {
        $accountId = $loginAccount->getAccountId();
        if(!empty($accountId))
        {
            echo "Account ID = $accountId\n";
        }
    }
}
/////////////////////////////////////////////////////////////////////////
// STEP 2:  Create & Send Envelope (aka Signature Request)
/////////////////////////////////////////////////////////////////////////// set recipient information
$recipientName = $recname;
$recipientEmail = $recemail;
$ysoftrecipientName = $xsoftrecname;
$ysoftrecipientEmail = $xsoftrecemail;


// configure the document we want signed
$documentFileName = "/doc2besigned.pdf";
$documentName = "SignTest1.pdf";
// instantiate a new envelopeApi object
$envelopeApi = new DocuSign\eSign\Api\EnvelopesApi($apiClient);
// Add a document to the envelope
$document = new DocuSign\eSign\Model\Document();
$document->setDocumentBase64(base64_encode(file_get_contents(__DIR__ . 
$documentFileName)));
$document->setName($documentName);
$document->setDocumentId("1");
// Create a |SignHere| tab somewhere on the document for the recipient to 
sign
$signHere = new \DocuSign\eSign\Model\SignHere();
$signHere->setXPosition("100");
$signHere->setYPosition("100");
$signHere->setDocumentId("1");
$signHere->setPageNumber("1");
$signHere->setRecipientId("1");

// $signHere = new \DocuSign\eSign\Model\SignHere();
$signHere->setXPosition("200");
$signHere->setYPosition("100");
$signHere->setDocumentId("1");
$signHere->setPageNumber("3");
$signHere->setRecipientId("2");


// add the signature tab to the envelope's list of tabs
$tabs = new DocuSign\eSign\Model\Tabs();
$tabs->setSignHereTabs(array($signHere));
// add a counterparty signer to the envelope


$signer = new \DocuSign\eSign\Model\Signer();
$signer->setEmail($recipientEmail);
$signer->setName($recipientName);
$signer->setRecipientId("1");
$signer->setRoutingOrder("1");

// $signer = new \DocuSign\eSign\Model\Signer();
$signer->setEmail($xsoftrecipientEmail);
$signer->setName($xsoftrecipientName);
$signer->setRecipientId("2");
$signer->setRoutingOrder("1");

$signer->setTabs($tabs);
// Add a recipient to sign the document
$recipients = new DocuSign\eSign\Model\Recipients();
$recipients->setSigners(array($signer));
$envelop_definition = new DocuSign\eSign\Model\EnvelopeDefinition();
$envelop_definition->setEmailSubject("[XSoft RoboLawyer] - Please sign this 
doc");
// set envelope status to "sent" to immediately send the signature request
$envelop_definition->setStatus("sent");
$envelop_definition->setRecipients($recipients);
$envelop_definition->setRecipients($recipients);
$envelop_definition->setDocuments(array($document));

// create and send the envelope! (aka signature request)
$envelop_summary = $envelopeApi->createEnvelope($accountId, 
$envelop_definition, null);
echo "$envelop_summary\n";
?>
phrogg
  • 888
  • 1
  • 13
  • 28
Martin Strnad
  • 36
  • 1
  • 3
  • BTW: Setting the routing order to 1 and 2 doesn't seem to work either – Martin Strnad Apr 03 '18 at 19:23
  • How you are adding two signers as recipients, above code is not showing adding two signers, its just showing populating one signer details, can you please share complete code – Amit K Bist Apr 03 '18 at 21:36

1 Answers1

0

Code is not showing adding two signers, its just showing populating one signer details, like email, name etc. Check Unit Test Code to see how to send envelope using PHP.

Amit K Bist
  • 6,760
  • 1
  • 11
  • 26
  • Amit, thank you. I included the full code. How to add the second signer (and not to repeat adding only the details of the first one) is precisely my question. Unfortunately, even the unit tests you linked seem to include only one signer:( Any hints will be appreciated:) – Martin Strnad Apr 04 '18 at 07:18
  • I am not PHP developer, but in your updated code, where are you adding multiple signer (or array of signers) in the $recipients, it seems it is always adding same $signer object. Your code should have two instance of $signer, and then adding both signers in the recipients object. – Amit K Bist Apr 04 '18 at 14:16
  • Amit, that´s it! And how do I add a second instance, please? – Martin Strnad Apr 04 '18 at 14:22
  • I am not PHP developer but you need to create array of signers, and array of signer's tabs.I would assume you know how to create array on objects in php. – Amit K Bist Apr 04 '18 at 15:03
  • I do not:) That´s why I´m confused;) Apologies for asking a stupid question again;) – Martin Strnad Apr 04 '18 at 16:01
  • https://stackoverflow.com/a/676703/3530898 will show you how to add elements to an array. Also check comments for https://stackoverflow.com/a/37840891/3530898.You need to learn PHP to implement your fucntionality. – Amit K Bist Apr 04 '18 at 16:40
  • Learning by doing, Amit, and just found my limits:) Thanks for pointing me in the right direction, will do a bit of learning on the array syntax;) – Martin Strnad Apr 04 '18 at 16:55