项目作者: Tucker-Eric

项目描述 :
Wrapper for the official Docusign PHP Client Library
高级语言: PHP
项目地址: git://github.com/Tucker-Eric/docusign-rest-client.git
创建时间: 2016-05-25T05:44:56Z
项目社区:https://github.com/Tucker-Eric/docusign-rest-client

开源协议:MIT License

下载


Docusign Rest Client

Wrapper for the official Docusign PHP Client Library.

This library handles all the object instantiation for the endpoints in the DocuSign Api Explorer.

Install Through Composer

  1. composer require tucker-eric/docusign-rest-client

Usage

The DocuSign\Rest\Client accesses all models and api endpoints and returns the respective obect. It also handles all authentication as well as passing the $account_id to any method that requires it.

Api Endpoints

All classes in the DocuSign\eSign\Api namesapace are accessible as properties of DocuSign\Rest\Client.

Each property is a the orignal class name camel cased without the Api suffix.

Example:

  1. <?php
  2. require 'vendor/autoload.php';
  3. $client = new DocuSign\Rest\Client([
  4. 'impersonated_user_id' => $impersonated_user_id,
  5. 'integrator_key' => $integrator_key,
  6. 'host' => $host,
  7. 'private_key' => $private_key,
  8. 'auth_server' => $auth_server
  9. ]);
  10. $client->accounts // Returns DocuSign\eSign\Api\AccountsApi
  11. $client->customTabs // Returns DocuSign\eSign\Api\CustomTabsApi
  12. $client->folders // Returns DocuSign\eSign\Api\FoldersApi

The client handles injecting the $account_id to any method that requires it.

So calling a method like the DocuSign\eSign\Api\FoldersApi list() method is as easy as:

  1. $client->folders->list(); // Returns \DocuSign\eSign\Model\FoldersResponse

Models

All classes in the DocuSign\eSign\Model namespace are accessible as a camel cased method of DocuSign\Rest\Client and accept an array of snake cased parameters that will be set on the model. Calling the method returns that model object.

Example:

  1. <?php
  2. require 'vendor/autoload.php';
  3. $client = new DocuSign\Rest\Client([
  4. 'impersonated_user_id' => $impersonated_user_id,
  5. 'private_key' => $private_key,
  6. 'integrator_key' => $integrator_key,
  7. 'host' => $host,
  8. 'auth_server' => $auth_server
  9. ]);
  10. $templateRole = $client->templateRole([
  11. 'email' => '[SIGNER_EMAIL]',
  12. 'name' => '[SIGNER_NAME]',
  13. 'role_name' => '[ROLE_NAME]'
  14. ]); // Returns DocuSign\eSign\Model\TemplateRole
  15. $templateRole->getRoleName() // returns '[ROLE_NAME]' as set in the above method.
  16. $envelopeDefinition = $client->envelopeDefinition([
  17. 'status' => 'sent'
  18. 'email_subject' => '[DocuSign PHP SDK] - Signature Request Sample',
  19. 'template_id' => '[TEMPLATE_ID]',
  20. 'template_roles' => [
  21. $templateRole
  22. ],
  23. ]); // Returns DocuSign\eSign\Model\EnvelopeDefinition

Api Options

Some classes in the DocuSign\eSign\Api namespace have options objects that can be created and passed to methods of that class. Those objects are accessible by calling it as a method from that Api class. The options methods accept an array of snake cased parameters to set. You can also call this method without any parameters and it will return the options object and you can use that object’s setter methods to set its properties

The ->search() method in the DocuSign\eSign\Api\FoldersApi class accepts DocuSign\eSign\Api\FoldersApi\SearchOptions to set the options. These options are set as in the example below

Example:

  1. $foldersApi = $this->client->folders;
  2. $searchOptions = $foldersApi->searchOptions([
  3. 'count' => 20,
  4. 'order_by' => 'sent',
  5. 'from_date' => '2010-01-01'
  6. ]);
  7. $foldersApi->search($searchOptions);

You can retrieve any previously set options on an Api class with the getOptions method. Passing the name of the method used to set the options returns that options object or not passing any parameters will return an array of all options objects for that Api class keyed by method name.

Example:

  1. $envelopesApi = $this->client->envelopes;
  2. $envelopesApi->createEnvelopeOptions([
  3. 'merge_roles_on_draft' => 'true'
  4. ]);
  5. $envelopesApi->updateOptions([
  6. 'resend_envelope' => 'true'
  7. ]);
  8. $envelopesApi->getOptions(); // returns ['updateOptions' => DocuSign\eSign\Api\EnvelopesApi\UpdateOptions, 'createEnvelopeOptions' => DocuSign\eSign\Api\EnvelopesApi\CreateEnvelopeOptions]
  9. $envelopesApi->getOptions('updateOptions') // returns DocuSign\eSign\Api\EnvelopesApi\UpdateOptions

Examples

To login and send a signature request from a template:

This will produce the same result as this example from official Docusign Client

  1. <?php
  2. require 'vendor/autoload.php';
  3. class DocuSignSample
  4. {
  5. public function signatureRequestFromTemplate()
  6. {
  7. $impersonated_user_id = "[IMPERSONATED_USER_ID]";
  8. $private_key = "[PRIVATE_KEY]";
  9. $integrator_key = "[INTEGRATOR_KEY]";
  10. // change these to production before going live
  11. $host = "https://demo.docusign.net/restapi";
  12. $auth_server = "account-d.docusign.com";
  13. // Once instantiated, authentication is handled automatically
  14. $client = new DocuSign\Rest\Client([
  15. 'impersonated_user_id' => $impersonated_user_id,
  16. 'private_key' => $private_key,
  17. 'integrator_key' => $integrator_key,
  18. 'host' => $host,
  19. 'auth_server' => $auth_server
  20. ]);
  21. $templateRole = $client->templateRole([
  22. 'email' => '[SIGNER_EMAIL]',
  23. 'name' => '[SIGNER_NAME]',
  24. 'role_name' => '[ROLE_NAME]'
  25. ]);
  26. $envelopeDefinition = $client->envelopeDefinition([
  27. 'status' => 'sent',
  28. 'email_subject' => '[DocuSign PHP SDK] - Signature Request Sample',
  29. 'template_id' => '[TEMPLATE_ID]',
  30. 'template_roles' => [
  31. $templateRole
  32. ],
  33. ]);
  34. $envelopeOptions = $client->envelopes->createEnvelopeOptions([
  35. 'merge_roles_on_draft' => false
  36. ]);
  37. $envelopeSummary = $client->envelopes->createEnvelope($envelopeDefinition, $envelopeOptions);
  38. }
  39. }

That same example refactored in it’s own class:

  1. <?php
  2. require 'vendor/autoload.php';
  3. class DocuSignSample
  4. {
  5. protected $impersonated_user_id = "[IMPERSONATED_USER_ID]";
  6. protected $private_key = "[PRIVATE_KEY]";
  7. protected $integrator_key = "[INTEGRATOR_KEY]";
  8. // change these to production before going live
  9. protected $host = "https://demo.docusign.net/restapi";
  10. protected $auth_server = "account-d.docusign.com";
  11. protected $client;
  12. public function __construct()
  13. {
  14. // Once instantiated, authentication is handled automatically
  15. $this->client = new DocuSign\Rest\Client([
  16. 'impersonated_user_id' => $impersonated_user_id,
  17. 'private_key' => $private_key,
  18. 'integrator_key' => $integrator_key,
  19. 'host' => $host,
  20. 'auth_server' => $auth_server
  21. ]);
  22. }
  23. /**
  24. * @return DocuSign\eSign\Model\EnvelopeSummary
  25. */
  26. public function signatureRequestFromTemplate()
  27. {
  28. return $this->client->envelopes->createEnvelope($this->client->envelopeDefinition([
  29. 'status' => 'sent',
  30. 'email_subject' => '[DocuSign PHP SDK] - Signature Request Sample',
  31. 'template_id' => '[TEMPLATE_ID]',
  32. 'template_roles' => [
  33. $this->client->templateRole([
  34. 'email' => '[SIGNER_EMAIL]',
  35. 'name' => '[SIGNER_NAME]',
  36. 'role_name' => '[ROLE_NAME]'
  37. ])
  38. ]
  39. ])
  40. );
  41. }
  42. }