picoss/yousign-bundle

Symfony2 YouSign bundle

Installs: 6 760

Dependents: 0

Suggesters: 0

Security: 0

Stars: 2

Watchers: 1

Forks: 4

Open Issues: 3

Type:symfony-bundle

2.2 2019-02-08 14:06 UTC

This package is auto-updated.

Last update: 2024-10-09 02:36:28 UTC


README

Latest Stable Version Total Downloads Latest Unstable Version License

This bundle provides integration for Yousign in your Symfony2 Project.

License: MIT

Installation

Step 1: Download the Bundle

Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:

    $ composer require picoss/yousign-bundle

This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation.

2: Enable the Bundle

When using Flex, this step is handled automatically.

Then, enable the bundle by adding the following line in the app/AppKernel.php file of your project:

    // app/AppKernel.php

    class AppKernel extends Kernel
    {
        public function registerBundles()
        {
            $bundles = array(
                // ...

                new Picoss\YousignBundle\PicossYousignBundle(),
            );

            // ...
        }

        // ...
    }

3: Configure the bundle

# config/packages/picoss_yousign.yml
picoss_yousign:
    env: demo #demo or prod
    api_key: yousign_api_key
    username: yousign_username
    password: yousign_password

Note: If you need to pass some options to the saop client, add soap_options config:

# config/packages/picoss_yousign.yml
picoss_yousign:
    env: demo #demo or prod
    api_key: yousign_api_key
    username: yousign_username
    password: yousign_password
    soap_options:
        trace: 1

Check $options argument of the soap client to see available options : http://php.net/manual/en/soapclient.soapclient.php

4: Usage

4.1: Test API connection

The following example shows how to test the connection to the Yousign API in your controller

<?php

namespace App\Controller;

use Picoss\YousignBundle\Yousign\YousignApi;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Response;

class TestController extends Controller
{
    /**
     * @Route("/test", name="test")
     */
    public function index(YousignApi $api)
    {
        $auth = $api->authentication;
        
        $result = $auth->connect() ? 'Connected' : 'Enable to connect';

        $response = new Response();
        $response->setContent(sprintf('<html><body>%s</body></html>', $result));

        return $response;
    }
}

4.2: Create a signature demand

<?php

namespace App\Controller;

use Picoss\YousignBundle\Model\Cosigner;
use Picoss\YousignBundle\Model\Demand;
use Picoss\YousignBundle\Model\File;
use Picoss\YousignBundle\Yousign\YousignApi;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Response;

class TestController extends Controller
{
    /**
     * @Route("/test", name="test")
     */
    public function index(YousignApi $api)
    {
        $signatureApi = $api->signature;

        $file = new File();
        $file
            ->setName('My PDF Filename')
            ->setContent(file_get_contents('/path/to/the/file.pdf'))
        ;

        $cosigner = new Cosigner();
        $cosigner
            ->setFirstName('John')
            ->setLastName('Doe')
            ->setMail('john.doe@email.com')
            ->setAuthenticationMode('mail');

        $visibleOptions = array(
            'visibleSignaturePage' => '5',
            'isVisibleSignature' => true,
            'visibleRectangleSignature' => '10,10,10,10',
        );

        $demand = new Demand();
        $demand
            ->addFile($file, $visibleOptions)
            ->addCosigner($cosigner)
        ;

        $signature = $signatureApi->initCosign($demand);

        $response = new Response();
        $response->setContent(sprintf('<html><body>Signature demand id: %s</body></html>', $signature->getIdDemand()));

        return $response;
    }
}

4.3: Available methods

4.3.1: Authentication API

4.3.2: Signature API

For more informations, please visite Yousign API documentation