mifiel/api-client

Mifiel API Client for PHP

2.0.3 2018-01-23 21:10 UTC

README

Latest Stable Version Build Status Coverage Status

PHP SDK for Mifiel API. Please read our documentation for instructions on how to start using the API.

Installation

Just run composer require mifiel/api-client in the root your project or add mifiel/api-client to your composer.json.

  "require": {
    "mifiel/api-client": "^1.0"
  }

And then execute composer install.

Usage

For your convenience Mifiel offers a Sandbox environment where you can confidently test your code.

To start using the API in the Sandbox environment you need to first create an account at sandbox.mifiel.com.

Once you have an account you will need an APP_ID and an APP_SECRET which you can generate in sandbox.mifiel.com/access_tokens.

Then you can configure the library with:

  use Mifiel\ApiClient as Mifiel;
  Mifiel::setTokens('APP_ID', 'APP_SECRET');
  // if you want to use our sandbox environment use:
  Mifiel::url('https://sandbox.mifiel.com/api/v1/');

Document methods:

  • Find:

      use Mifiel\Document;
      $document = Document::find('id');
      $document->original_hash;
      $document->file;
      $document->file_signed;
      # ...
  • Find all:

      use Mifiel\Document;
      $documents = Document::all();
  • Create:

Use only original_hash if you dont want us to have the file.
Only file or original_hash must be provided.

  use Mifiel\Document;
  $document = new Document([
    'file_path' => 'path/to/my-file.pdf',
    'signatories' => [
      [ 
        'name' => 'Signer 1', 
        'email' => 'signer1@email.com', 
        'tax_id' =>  'AAA010101AAA' 
      ],
      [ 
        'name' => 'Signer 2', 
        'email' => 'signer2@email.com', 
        'tax_id' =>  'AAA010102AAA'
      ]
    ]
  ]);
  // if you dont want us to have the PDF, you can just send us 
  // the original_hash and the name of the document. Both are required
  $document = new Document([
    'original_hash' => hash('sha256', file_get_contents('path/to/my-file.pdf')),
    'name' => 'my-file.pdf',
    'signatories' => ...
  ]);

  $document->save();
  • Save Document related files
  use Mifiel\Document;
  $document = Document::find('id');

  # save the original file
  $document->saveFile('path/to/save/file.pdf');
  # save the signed file (original file + signatures page)
  $document->saveFileSigned('path/to/save/file-signed.pdf');
  # save the signed xml file
  $document->saveXML('path/to/save/xml.xml');
  • Delete

      use Mifiel\Document;
      Document::delete('id');

Certificate methods:

  • Sat Certificates

      use Mifiel\Certificate;
      $sat_certificates = Certificate::sat();
  • Find:

      use Mifiel\Certificate;
      $certificate = Certificate::find('id');
      $certificate->cer_hex;
      $certificate->type_of;
      # ...
  • Find all:

      use Mifiel\Certificate;
      $certificates = Certificate::all();
  • Create

      use Mifiel\Certificate;
      $certificate = new Certificate([
        'file_path' => 'path/to/my-certificate.cer'
      ])
      $certificate->save();
  • Delete

      use Mifiel\Certificate;
      Certificate::delete('id');

Template methods:

  • Find:

      use Mifiel\Template;
      $template = Template::find('id');
      $template->name;
      $template->header;
      $template->content;
      # ...
  • Find all:

      use Mifiel\Template;
      $templates = Template::all();
  • Create:

      use Mifiel\Template;
      $template = new Template([
        'name' => 'My template name',
        'header' => 'Some header text',
        'content' => '<div>The signer <field name="signer">SIGNER</field></div>',
        'footer' => 'Some footer text'
      ]);
      
      $template->save();
      $template->id;
  • Delete

      use Mifiel\Template;
      Template::delete('id');
  • Generate a document from a template

use Mifiel\Document;

$document = Document::createFromTemplate([
  'template_id' => 'some-id',
  'name' => 'Some-name.pdf',
  'fields' => [
    'name' => 'Signer 1',
    'type' => 'Lawyer'
  ],
  'signatories' => [[
    'email' => 'some@email.com'
  ]],
  'external_id' => 'some-external-id'
]);
  • Generate several documents from a template
$document = Document::createManyFromTemplate([
  'template_id' => 'some-id',
  'identifier' => 'name',
  'callback_url' => 'https://some-url.com',
  'documents' => [[
    'fields' => [
      'name' => 'Signer 1',
      'type' => 'Lawyer 1'
    ],
    'signatories' => [[
      'email' => 'some1@email.com'
    ]],
    'external_id' => 'some-external-id'
  ], [
    'fields' => [
      'name' => 'Signer 2',
      'type' => 'Lawyer 2'
    ],
    'signatories' => [[
      'email' => 'some2@email.com'
    ]],
    'external_id' => 'some-other-external-id'
  ]]
]);

Development

Install grunt and run grunt in the terminal. This will run all tests whenever a change is detected to any file in the project.

Contributing

  1. Fork it ( https://github.com/Mifiel/php-api-client/fork )
  2. Create your feature branch (git checkout -b feature/my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin feature/my-new-feature)
  5. Create a new Pull Request