2017 © Pedro Peláez
 

library hellosign-php-sdk

This is the official PHP wrapper for HelloSign's API

image

hellosign/hellosign-php-sdk

This is the official PHP wrapper for HelloSign's API

  • Thursday, June 14, 2018
  • by hellosign
  • Repository
  • 29 Watchers
  • 24 Stars
  • 142,260 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 23 Forks
  • 10 Open issues
  • 40 Versions
  • 12 % Grown

The README.md

⚠ This SDK has been deprecated ⚠

This SDK is now deprecated and will no longer receive feature updates or bug fixes. Security fixes will still be applied as needed., (*1)

The new dropbox/sign SDK can be found at hellosign/dropbox-sign-php!, (*2)

The new SDK and this legacy SDK are not backwards-compatible!, (*3)

Please see here for a comprehensive migration guide., (*4)


HelloSign PHP SDK

Build Status, (*5)

This is the official PHP SDK for HelloSign's API. View API Documentation and Examples., (*6)

Installation

Requirements

The latest version of the SDK requires PHP version 8.0 or higher. For PHP 7.x use SDK version 3.7.*, (*7)

You can import this SDK into your library two ways, either through including the base HelloSign.php file into your project or using Composer., (*8)

To use Composer:, (*9)

  • First, install Composer if you don't have it already, (*10)

    curl -sS https://getcomposer.org/installer | php
    
  • Create a composer.json file and add the following:, (*11)

    {
        "require": {
            "hellosign/hellosign-php-sdk": "^3.0"
        }
    }
    
  • Install hellosign-php-sdk package via Composer, (*12)

    php composer.phar install
    
  • Include the library in your script, (*13)

    require_once 'vendor/autoload.php';
    
  • See below for how to configure your Client class.

Configuration

All HelloSign API requests can be made using the HelloSign\Client class. This class must be initialized with your authentication details such as an API key (preferred), email/password combo, or OAuth credentials., (*14)

API key Config

$client = new HelloSign\Client($apikey);

Email/Password Config

$client = new HelloSign\Client($email_address, $password);

Oauth Config

$client = new HelloSign\Client($oauth_token); //instance of HelloSign\OAuthToken

Your app users are almost ready to start signing! See below for the most common use cases for this wrapper., (*15)

Usage

You can test your authentication by calling, (*16)

$account = $client->getAccount();

Retrieving fields returned from the API

Using magic methods, (*17)

$signature_request->title;

Or if you want to get all attributes in an array, (*18)

$signature_request->toArray();

Creating a Signature Request

$request = new HelloSign\SignatureRequest;
$request->enableTestMode();
$request->setTitle('NDA with Acme Co.');
$request->setSubject('The NDA we talked about');
$request->setMessage('Please sign this NDA and let\'s discuss.');
$request->addSigner('jack@example.com', 'Jack');
$request->addSigner('jill@example.com', 'Jill');
$request->addCC('lawyer@example.com');
$request->addFile('nda.pdf'); //Adding file from local

$response = $client->sendSignatureRequest($request);

To specify a URL to a remote file instead use:, (*19)

$request->addFileURL('PUBLIC_URL_TO_YOUR_FILE');

If you are using Text Tags in your document, you can enable and configure them through the respective methods:, (*20)

$request->setUseTextTags(true);
$request->setHideTextTags(true);

Or if you want to set Form Fields per Document:, (*21)

$request->setFormFieldsPerDocument(
            array(
                array( //document 1
                    array( //field 1
                        "api_id"=> $random_prefix . "_1",
                        "name"=> "",
                        "type"=> "text",
                        "x"=> 112,
                        "y"=> 328,
                        "width"=> 100,
                        "height"=> 16,
                        "required"=> true,
                        "signer"=> 0
                    ),
                    array( //field 2
                        "api_id"=> $random_prefix . "_2",
                        "name"=> "",
                        "type"=> "signature",
                        "x"=> 530,
                        "y"=> 415,
                        "width"=> 150,
                        "height"=> 30,
                        "required"=> true,
                        "signer"=> 1
                    ),
                ),
            )
        );

Retrieving a User's Templates

The HelloSign API provides paged lists for user templates and signature requests. These lists are represented as objects that can be iterated upon., (*22)

$templates = $client->getTemplates($page_number);
foreach ($templates as $template) {
    echo $template->getTitle() . "\n";
}

Creating a Signature Request from a Template

$request = new HelloSign\TemplateSignatureRequest;
$request->enableTestMode();
$request->setTemplateId($template->getId());
$request->setSubject('Purchase Order');
$request->setMessage('Glad we could come to an agreement.');
$request->setSigner('Client', 'george@example.com', 'George');
$request->setCC('Accounting', 'accounting@example.com');
$request->setCustomFieldValue('Cost', '$20,000');

$response = $client->sendTemplateSignatureRequest($request);

Checking the Status of a Signature Request

$response = $client->getSignatureRequest($signature_request_id);
if ($response->isComplete()) {
    echo 'All signers have signed this request.';
} else {
    foreach ($response->getSignatures() as $signature) {
        echo $signature->getStatusCode() . "\n";
    }
}

Creating an Embedded Signature Request to use for Embedded Signing

Refer to the (Embedded Signing Walkthrough)[https://app.hellosign.com/api/embeddedSigningWalkthrough] for more details., (*23)

// Create the SignatureRequest or TemplateSignatureRequest object
$request = ...

// Turn it into an embedded request
$embedded_request = new HelloSign\EmbeddedSignatureRequest($request, $client_id);

// Send it to HelloSign
$response = $client->createEmbeddedSignatureRequest($embedded_request);

// Grab the signature ID for the signature page that will be embedded in the
// page (for the demo, we'll just use the first one)
$signatures   = $response->getSignatures();
$signature_id = $signatures[0]->getId();

// Retrieve the URL to sign the document
$response = $client->getEmbeddedSignUrl($signature_id);

// Store it to use with the embedded.js HelloSign.open() call
$sign_url = $response->getSignUrl();

Creating an Embedded Template draft

$template = new HelloSign\Template();
$template->enableTestMode();
$template->setClientId($client_id);
$template->addFile('nda.pdf');
$template->setTitle('Test Title');
$template->setSubject('Test Subject');
$template->setMessage('Test Message');
$template->addSignerRole('Test Role');
$template->addMetadata('custom_id', '1234');

$response = $client->createEmbeddedDraft($template);

Creating an Unclaimed Draft to use for Embedded Requesting


$draft = new HelloSign\UnclaimedDraft($request, $client_id); // optionally change it to a self-signing draft with $draft->setType("send_document"); $response = $client->createUnclaimedDraft($draft); // Store it to use with the embedded.js HelloSign.open() call $sign_url = $response->getClaimUrl();

Enabling OAuth

// If the account does not exist
if !($client->isAccountValid($email)) {
    // Create new account
    $account = $client->createAccount(
        new HelloSign\Account($email),
        $client_id,
        $client_secret
    );

    // Get OAuth token
    $token = $account->getOAuthData();
} else {
    // Create the OAuthTokenRequest object
    $oauth_request = new HelloSign\OAuthTokenRequest(array(
        'code'          => $code,
        'state'         => $state,
        'client_id'     => $client_id,
        'client_secret' => $client_secret
    ));

    // Request OAuth token for the first time
    $token = $client->requestOAuthToken($oauth_request);
}

// Export token to array, store it to use later
$hellosign_oauth = $token->toArray();

// Populate token from array
$token = new HelloSign\OAuthToken($hellosign_oauth);

// Refresh token if it expired
$client->refreshOAuthToken($token);

// Provide the user's OAuth access token to the client
$client = new HelloSign\Client($token);

Displaying warnings

Any warnings returned from the API can be accessed via the returned object / list via the getWarnings method:, (*24)

  $response = $this->client->getSignatureRequests();
  print_r($response->getWarnings());

Testing

This project contains PHPUnit tests that check the SDK code and can also be referenced for examples. Most are functional and integrated tests that walk through real user scenarios., (*25)

In order to pass the unit tests, you will need:, (*26)

  1. The API Key for a confirmed HelloSign account
  2. The client ID and secret key from a confirmed HelloSign API App
  3. A HelloSign subscription (to create a team)
  4. A HelloSign API subscription (to access paid API endpoints)
  5. A template with 1 signer role named 'Signer'
  6. A Team with 1 additional team member

*** WARNING: these tests will add and remove users from your team. Use with caution., (*27)

To run the tests

  • Copy file phpunit.xml.dist to phpunit.xml
  • Edit the new file and enter your values for API_KEY, CLIENT_ID, CLIENT_SECRET, CALLBACK_URL, API_URL, AND OAUTH_TOKEN_URL
  • Run ./vendor/bin/phpunit

License

The MIT License (MIT)

Copyright (C) 2014 hellosign.com

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

The Versions

14/06 2018

v3.x-dev

3.9999999.9999999.9999999-dev

This is the official PHP wrapper for HelloSign's API

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar hellosign

14/06 2018

v3.5.3

3.5.3.0

This is the official PHP wrapper for HelloSign's API

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar hellosign

01/03 2018

3.5.2

3.5.2.0

This is the official PHP wrapper for HelloSign's API

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar hellosign

05/01 2018

3.5.1

3.5.1.0

This is the official PHP wrapper for HelloSign's API

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar hellosign

26/09 2017

3.5.0

3.5.0.0

This is the official PHP wrapper for HelloSign's API

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar hellosign

14/08 2017

dev-DEV-3147

dev-DEV-3147

This is the official PHP wrapper for HelloSign's API

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar hellosign

21/02 2017

dev-issue_35

dev-issue_35

This is the official PHP wrapper for HelloSign's API

  Sources   Download

MIT

The Requires

 

The Development Requires

17/10 2016

3.4.6

3.4.6.0

This is the official PHP wrapper for HelloSign's API

  Sources   Download

MIT

The Requires

 

The Development Requires

15/10 2016

3.4.5

3.4.5.0

This is the official PHP wrapper for HelloSign's API

  Sources   Download

MIT

The Requires

 

The Development Requires

08/08 2016

3.4.4

3.4.4.0

This is the official PHP wrapper for HelloSign's API

  Sources   Download

MIT

The Requires

 

The Development Requires

20/05 2016

3.4.3

3.4.3.0

This is the official PHP wrapper for HelloSign's API

  Sources   Download

MIT

The Development Requires

13/05 2016

3.4.2

3.4.2.0

This is the official PHP wrapper for HelloSign's API

  Sources   Download

MIT

The Development Requires

29/04 2016

3.4.1

3.4.1.0

This is the official PHP wrapper for HelloSign's API

  Sources   Download

MIT

The Development Requires

10/09 2015

3.4.0

3.4.0.0

This is the official PHP wrapper for HelloSign's API

  Sources   Download

MIT

The Development Requires

09/09 2015

3.3.4

3.3.4.0

This is the official PHP wrapper for HelloSign's API

  Sources   Download

MIT

The Development Requires

02/09 2015

3.3.3

3.3.3.0

This is the official PHP wrapper for HelloSign's API

  Sources   Download

MIT

The Development Requires

15/08 2015

3.3.2

3.3.2.0

This is the official PHP wrapper for HelloSign's API

  Sources   Download

MIT

The Development Requires

05/08 2015

3.3.1

3.3.1.0

This is the official PHP wrapper for HelloSign's API

  Sources   Download

MIT

The Development Requires

29/07 2015

3.3.0

3.3.0.0

This is the official PHP wrapper for HelloSign's API

  Sources   Download

MIT

The Development Requires

08/07 2015

3.2.8

3.2.8.0

This is the official PHP wrapper for HelloSign's API

  Sources   Download

MIT

The Development Requires

11/06 2015

3.2.7

3.2.7.0

This is the official PHP wrapper for HelloSign's API

  Sources   Download

MIT

The Development Requires

03/06 2015

3.2.6

3.2.6.0

This is the official PHP wrapper for HelloSign's API

  Sources   Download

MIT

The Development Requires

02/06 2015

3.2.5

3.2.5.0

This is the official PHP wrapper for HelloSign's API

  Sources   Download

MIT

The Development Requires

02/06 2015

3.2.4

3.2.4.0

This is the official PHP wrapper for HelloSign's API

  Sources   Download

MIT

The Development Requires

05/05 2015

3.2.3

3.2.3.0

This is the official PHP wrapper for HelloSign's API

  Sources   Download

MIT

The Development Requires

25/04 2015

3.2.2

3.2.2.0

This is the official PHP wrapper for HelloSign's API

  Sources   Download

MIT

The Development Requires

09/04 2015

3.2.1

3.2.1.0

This is the official PHP wrapper for HelloSign's API

  Sources   Download

MIT

The Development Requires

03/04 2015

3.2

3.2.0.0

This is the official PHP wrapper for HelloSign's API

  Sources   Download

MIT

The Development Requires

19/03 2015

3.1.1

3.1.1.0

This is the official PHP wrapper for HelloSign's API

  Sources   Download

MIT

The Development Requires

19/03 2015

3.1.0

3.1.0.0

This is the official PHP wrapper for HelloSign's API

  Sources   Download

MIT

The Development Requires

17/03 2015

3.0.9

3.0.9.0

This is the official PHP wrapper for HelloSign's API

  Sources   Download

MIT

The Development Requires

31/12 2014

3.0.8

3.0.8.0

This is the official PHP wrapper for HelloSign's API

  Sources   Download

MIT

The Development Requires

30/12 2014

3.0.7

3.0.7.0

This is the official PHP wrapper for HelloSign's API

  Sources   Download

MIT

The Development Requires

30/11 2014

3.0.6

3.0.6.0

This is the official PHP wrapper for HelloSign's API

  Sources   Download

MIT

The Development Requires

27/11 2014

3.0.5

3.0.5.0

This is the official PHP wrapper for HelloSign's API

  Sources   Download

MIT

The Development Requires

14/10 2014

3.0.4

3.0.4.0

This is the official PHP wrapper for HelloSign's API

  Sources   Download

MIT

The Development Requires

05/09 2014

3.0.3

3.0.3.0

This is the official PHP wrapper for HelloSign's API

  Sources   Download

MIT

The Development Requires

13/05 2014

3.0.2

3.0.2.0

This is the official PHP wrapper for HelloSign's API

  Sources   Download

MIT

The Development Requires

12/05 2014

3.0.1

3.0.1.0

This is the official PHP wrapper for HelloSign's API

  Sources   Download

MIT

The Development Requires

07/05 2014

3.0

3.0.0.0

This is the official PHP wrapper for HelloSign's API

  Sources   Download

MIT

The Development Requires