Link Search Menu Expand Document (external link)

php-client

Table of contents
  1. Installation
  2. Usage

The PHP client helps to lighten the hassle of building all APIs from the scratch. It contains wrapper classes which will help the development of integration with the Mark-Sign APIs faster. This package complies with PSR-4 autoloading standard.

Installation

Installation is pretty much straight forward with composer. To install, just run the following command:

composer require mark-sign/gateway-sdk-php

Usage

To use the package, at first initialize the AppBundle\GatewaySDKPhp\Client class with access token and a logger insterface. In the following example monolog logger is used.

use AppBundle\GatewaySDKPhp\Client;
use Monolog\Handler\StreamHandler;
use Monolog\Logger;

$accessToken = 'XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX';
$logger = new Logger('dev', [new StreamHandler('log_file_name')]);

$client = new Client($accessToken, $logger);

Then, build a request builder object which will contain request body parameters. The final call to createRequest() method will return an object that implements AppBundle\GatewaySDKPhp\Model\RequestInterface. All the request builders under the AppBundle\GatewaySDKPhp\RequestBuilder namespace implements AppBundle\GatewaySDKPhp\RequestBuilder\RequestBuilderInterface which contains the declaration of createRequest() method, and hence, all the request builders will have their own implementation of createRequest() method.

In the following, AppBundle\GatewaySDKPhp\RequestBuilder\DocumentUploadRequestBuilder is used as request builder.

use AppBundle\GatewaySDKPhp\RequestBuilder\DocumentUploadRequestBuilder;
use AppBundle\GatewaySDKPhp\RequestBuilder\Partials\FileUpload;
use AppBundle\GatewaySDKPhp\RequestBuilder\Partials\Signer;

$filePath = __DIR__ . "demo.pdf";

$requestBuilder = (new DocumentUploadRequestBuilder)
    ->withAccessToken(ACCESS_TOKEN)
    ->withAccess('private')
    ->withFile(
        (new FileUpload)->setFileName(basename($filePath))->setContent(base64_encode(file_get_contents($filePath)))
    )
    ->withSigners([
        (new Signer)->setName('Tex')->setSurName('Ryta')->setEmail('tex.ryta@domain.com')->setNoEmail(false),
        (new Signer)->setName('John')->setSurName('Quil')->setEmail('john.quil@domain.com')->setNoEmail(false),
    ])
    ->createRequest();

And finally, pass the result of createRequest() method to the Client’s postRequest() method.

$response = $client->postRequest($requestBuilder);
$responseArray = $response->toArray(false);

And, that’s it. API call has been done and by using toArray() on the response, we can convert the response to an array.

The whole code block is as following

use Monolog\Handler\StreamHandler;
use Monolog\Logger;
use AppBundle\GatewaySDKPhp\Client;
use AppBundle\GatewaySDKPhp\RequestBuilder\DocumentUploadRequestBuilder;
use AppBundle\GatewaySDKPhp\RequestBuilder\Partials\FileUpload;
use AppBundle\GatewaySDKPhp\RequestBuilder\Partials\Signer;

$accessToken = 'XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX';
$logger = new Logger('dev', [new StreamHandler('log_file_name')]);

$client = new Client($accessToken, $logger);
$filePath = __DIR__ . "demo.pdf";

$requestBuilder = (new DocumentUploadRequestBuilder)
    ->withAccessToken(ACCESS_TOKEN)
    ->withAccess('private')
    ->withFile(
        (new FileUpload)->setFileName(basename($filePath))->setContent(base64_encode(file_get_contents($filePath)))
    )
    ->withSigners([
        (new Signer)->setName('Tex')->setSurName('Ryta')->setEmail('tex.ryta@domain.com')->setNoEmail(false),
        (new Signer)->setName('John')->setSurName('Quil')->setEmail('john.quil@domain.com')->setNoEmail(false),
    ])
    ->createRequest();

$response = $client->postRequest($requestBuilder);
$responseArray = $response->toArray();