diff --git a/Readme.md b/Readme.md index a87fb92..d794c94 100644 --- a/Readme.md +++ b/Readme.md @@ -3,261 +3,60 @@ [![Latest Stable Version][packagist-image]][packagist-url] [![Build Status][travis-image]][travis-url] -PHP SDK for [Mifiel](https://www.mifiel.com) API. -Please read our [documentation](http://docs.mifiel.com/) for instructions on how to start using the API. +PHP SDK for the [Mifiel](https://www.mifiel.com) API. -## Installation - -Just run `composer require mifiel/api-client` in the root your project or add `mifiel/api-client` to your [composer.json](https://getcomposer.org/). - -```json - "require": { - "mifiel/api-client": "^1.0" - } -``` +## Documentation -And then execute `composer install`. +API reference, guides, and examples: -## Usage +- English: https://docs.mifiel.com/en/ +- EspaƱol: https://docs.mifiel.com/es/ -For your convenience Mifiel offers a Sandbox environment where you can confidently test your code. +This README covers installation and client setup only. -To start using the API in the Sandbox environment you need to first create an account at [app-sandbox.mifiel.com](https://app-sandbox.mifiel.com). - -Once you have an account you will need an APP_ID and an APP_SECRET which you can generate in [app-sandbox.mifiel.com/settings/access-tokens](https://app-sandbox.mifiel.com/settings/access-tokens). - -Then you can configure the library with: +## Installation -```php - use Mifiel\ApiClient as Mifiel; - Mifiel::setTokens('APP_ID', 'APP_SECRET'); - // if you want to use our sandbox environment use: - Mifiel::url('https://app-sandbox.mifiel.com/api/v1/'); +```bash +composer require mifiel/api-client ``` -By default `setTokens` points at production (`https://app.mifiel.com/api/v1/`). - -Document methods: - -- Find: +Or add it to your `composer.json`: - ```php - use Mifiel\Document; - $document = Document::find('id'); - $document->original_hash; - $document->file; - $document->file_signed; - # ... - ``` - -- Find all: - - ```php - 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. - - ```php - 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 - -```php - 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'); +```json +{ + "require": { + "mifiel/api-client": "^3.0" + } +} ``` -- Delete +## Setup - ```php - use Mifiel\Document; - Document::delete('id'); - ``` - -Certificate methods: - -- Sat Certificates - - ```php - use Mifiel\Certificate; - $sat_certificates = Certificate::sat(); - ``` - -- Find: - - ```php - use Mifiel\Certificate; - $certificate = Certificate::find('id'); - $certificate->cer_hex; - $certificate->type_of; - # ... - ``` - -- Find all: - - ```php - use Mifiel\Certificate; - $certificates = Certificate::all(); - ``` - -- Create - - ```php - use Mifiel\Certificate; - $certificate = new Certificate([ - 'file_path' => 'path/to/my-certificate.cer' - ]) - $certificate->save(); - ``` - -- Delete - - ```php - use Mifiel\Certificate; - Certificate::delete('id'); - ``` - -Template methods: - -- Find: - - ```php - use Mifiel\Template; - $template = Template::find('id'); - $template->name; - $template->header; - $template->content; - # ... - ``` - -- Find all: - - ```php - use Mifiel\Template; - $templates = Template::all(); - ``` - -- Create: - - ```php - use Mifiel\Template; - $template = new Template([ - 'name' => 'My template name', - 'header' => 'Some header text', - 'content' => '
The signer SIGNER
', - 'footer' => 'Some footer text' - ]); - - $template->save(); - $template->id; - ``` - -- Delete - - ```php - use Mifiel\Template; - Template::delete('id'); - ``` - -- Generate a document from a template +1. Create an account (production or [sandbox](https://app-sandbox.mifiel.com)). +2. Generate an `APP_ID` and `APP_SECRET` in [Access Tokens](https://app-sandbox.mifiel.com/settings/access-tokens). +3. Configure the client: ```php -use Mifiel\Document; +use Mifiel\ApiClient as Mifiel; -$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 - -```php -$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-other-external-id' - ], [ - 'fields' => [ - 'name' => 'Signer 2', - 'type' => 'Lawyer 2' - ], - 'signatories' => [[ - 'email' => 'some2@email.com' - ]], - 'external_id' => 'some-other-external-id' - ]] -]); +Mifiel::setTokens('APP_ID', 'APP_SECRET'); +// Production is the default (https://app.mifiel.com/api/v1/). +// For sandbox: +Mifiel::url('https://app-sandbox.mifiel.com/api/v1/'); ``` ## Development & Tests -We have two kinds of tests, unit and e2e (internet). You can run them with - ```bash # Unit -php vendor/bin/phpunit --exclude-group internet +php vendor/bin/phpunit --exclude-group internet # e2e php vendor/bin/phpunit --group internet ``` ## Contributing -1. Fork it ( https://github.com/Mifiel/php-api-client/fork ) +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`) @@ -265,6 +64,5 @@ php vendor/bin/phpunit --group internet [travis-image]: https://travis-ci.org/Mifiel/php-api-client.svg?branch=master [travis-url]: https://travis-ci.org/Mifiel/php-api-client - [packagist-image]: https://img.shields.io/packagist/v/mifiel/api-client.svg [packagist-url]: https://packagist.org/packages/mifiel/api-client diff --git a/src/Webhook.php b/src/Webhook.php new file mode 100644 index 0000000..94333c2 --- /dev/null +++ b/src/Webhook.php @@ -0,0 +1,32 @@ +id) { + throw new ArgumentError('Webhook id is required to trigger', 1); + } + + return ApiClient::post( + static::$resourceName . '/' . $this->id . '/trigger', + [ + 'resource' => $resource, + 'instant' => $instant, + ], + false + ); + } +}