Git Product home page Git Product logo

thewisenoob / signnowphpsdk Goto Github PK

View Code? Open in Web Editor NEW

This project forked from signnow/signnowphpsdk

0.0 1.0 0.0 33 KB

The Official SignNow PHP SDK library for interacting with SignNow REST API. Sign documents, request e-signatures, and build role-based workflows with multiple signers using this client.

Home Page: https://www.signnow.com/developers

License: MIT License

PHP 100.00%

signnowphpsdk's Introduction

SignNow API PHP Client

Simple API Client to integrate SignNow with your application or website. Sign documents, request e-signatures, and build role-based workflows with multiple signers: https://www.signnow.com/developers

Table of Contents

  1. Requirements
  2. Install
  3. Setting up
  4. Entity manager
  5. Examples & use cases

Requirements

PHP 7.1 or newer

Install

composer require signnow/api-php-sdk

Setting up

Register an annotation loader:

AnnotationRegistry::registerLoader('class_exists');

Prepare options for the Guzzle client. We recommend the following configuration:

$stack = HandlerStack::create();
$stack->setHandler(new CurlMultiHandler());
$stack->push(new AuthorizationMiddleware(new BasicToken($token))));
$stack->push(new ResponseCheckerMiddleware());
$options = [
    'base_uri'        => $host,
    'headers'         => ['Content-Type' => 'application/json'],
    'connect_timeout' => 30,
    'request_timeout' => 30,
    'handler'         => $stack,
];

Or you can use builder for configuring the default options:

$options = (new OptionBuilder())
    ->setUri($uri)
    ->useAuthorization($token)
    ->getOptions();

Create the instance of Entity Manager:

$entityManager = (new EntityManagerFactory())->createEntityManager($options);

Setup update http method for Entity Manager:

$entityManager->setUpdateHttpMethod(Request::METHOD_PUT);

Entity manager

Entity manager is the main class which controls communication with 3rd party REST API where JSON is used as main data type. It's responsible for saving objects to and fetching objects from the API.

Each entity is described by:

  • API resource url (via HttpEntity annotation),
  • API payload (via properties and theirs types),
  • API response type (via ResponseType annotation, optional).

Examples & use cases

Upload Document to SignNow

$uploadFile = (new Document\Upload(new \SplFileInfo('realFilePath')));
$document = $entityManager->create($uploadFile);

Download Document from SignNow

$document = $entityManager->get(Document\Download::class, ['id' => $document_id], ['type' => 'collapsed']);

OAuth 2.0

Request Access Token

$entityManager->create(new TokenRequestPassword($username, $password));

Verify Access Token

$entityManager->get(Token::class);

Refresh Access Token

$entityManager->create(new TokenRequestRefresh($refresh_token));

Document

Upload document

$entityManager->create(new Document\Upload(new \SplFileInfo($filePath)));

Upload document with text tags & convert them to fillable fields

$entityManager->create(new Document\FieldExtract(new \SplFileInfo($filePath)));

Retrieve document

$entityManager->get(Document\Document::class, ['id' => $document_id]);

Delete document

$entityManager->delete(Document\Document::class, ['id' => $document_id]);

Download document

$entityManager->get(Document\Download::class, ['id' => $document_id], ['type' => 'collapsed']);
// type can be 'collapsed' or 'zip' 

// if need table containing the document's history set with_history=1
$entityManager->get(Document\Download::class, ['id' => $document_id], ['type' => 'collapsed', 'with_history' => 1]);

Create a single-use link for document downloading

$entityManager->create(new Document\DownloadLink(), ['id' => $document_id])

Create a role-based invite to sign a document

$to[] = new Recipient($recipient_email, $role, $roleId, $order);
$invite = new Invite($email, $to, $cc);
$entityManager->create($invite, ['documentId' => $document_id]);

Create a simple free form invite to sign a document

$invite = (new Invite())
            ->setDocumentId($document_id)
            ->setTo($to)
            ->setFrom($from)
            ->setCc([])
            ->setSubject($subject)
            ->setMessage($message);
              
$entityManager->create($invite, ["documentId" => $document_id]);

Cancel an invite to sign a document

$entityManager
    ->setUpdateHttpMethod(Request::METHOD_PUT)
    ->update(new CancelInvite(), ['documentId' => $document_id]);

Create a signing link

$entityManager->create(new SigningLink($document_id));

Add fillable fields to a document

$signature = (new SignatureField())
    ->setName('My Signature')
    ->setPageNumber(0)
    ->setRole('role 1')
    ->setRequired(true)
    ->setHeight(20)
    ->setWidth(10)
    ->setX(5)
    ->setY(10);

$text = (new TextField())
    ->setName('My text')
    ->setLabel('Some label')
    ->setPrefilledText('prefilled text')
    ->setPageNumber(0)
    ->setRole('role 1')
    ->setRequired(true)
    ->setHeight(20)
    ->setWidth(10)
    ->setX(100)
    ->setY(150);

$document = (new Document\Document())
    ->setId($document_id)
    ->setFields([$signature, $text]);
               
$entityManager->update($document);

Template

Create a template

$template = (new Template\Template())
    ->setDocumentId($document_id)
    ->setDocumentName($document_name);
 
$entityManager->create($template);

Generate a document from template (Copy template)

$templateCopy = (new Template\Copy())
        ->setTemplateId($template_id)
        ->setDocumentName($document_name);

$entityManager->create($templateCopy);

Document group

Retrieve document group

$entityManager->get(DocumentGroup\DocumentGroup::class, ['id' => $document_group_id])

Delete document group

$entityManager->delete(DocumentGroup\DocumentGroup::class, ['id' => $document_group_id])

Cancel document group invite

$entityManager->create(
    new DocumentGroup\GroupInvite\Cancel(),
    [
        'documentGroupId' => $documentGroupId,
        'groupInviteId' => $groupInviteId
    ]
);

Event subscriptions

Get User Event Subscriptions

$entityManager->get(new EventSubscription\GetEventSubscriptions());

Create User Event Subscription

$entityManager->create(
    (new EventSubscription\CreateEventSubscription())
    ->setEvent('document.update')
    ->setCallbackUrl('https://google.com.ua')
);

Delete User Event Subscription

$entityManager->delete(
    new EventSubscription\DeleteEventSubscription(),
    ['uniqueId' => $uniqueId]
);

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.