From f52e404219e29109dad43bde49b90a4bbce4920c Mon Sep 17 00:00:00 2001 From: Leonato Ieiri Date: Thu, 21 Mar 2019 10:53:12 -0300 Subject: [PATCH] Adiciona parametro QRcode no document create --- README.md | 5 +- src/Resource/Constants/Document.php | 29 +++++++--- src/Resource/Document.php | 86 +++++++++++++++-------------- tests/Resource/DocumentTest.php | 27 ++++++++- tests/TestCase.php | 5 +- 5 files changed, 101 insertions(+), 51 deletions(-) diff --git a/README.md b/README.md index 9cba68d..c708b7b 100644 --- a/README.md +++ b/README.md @@ -91,6 +91,7 @@ $lembreteVencimento = true; // opcional $frequencia = 'semanal'; // ou 'diario' opcional $diasVencimento = 7; // opcional $dataVencimento = '2018-09-10'; // opcional +$qrCode = 'B'; // opctional $doc->create( $nome, @@ -102,7 +103,8 @@ $doc->create( $lembreteVencimento, $frequencia, $diasVencimento, - $dataVencimento + $dataVencimento, + $qrCode ); ``` Reenviar email de assinatura para os signatários que não assinaram/rejeitaram @@ -194,6 +196,7 @@ composer test Caso queira testar contra o ambiente de sandbox: ``` export AUTENTIQUE_TOKEN=sandbox_token +export AUTENTIQUE_ENDPOINT=endpoint_url composer test ``` diff --git a/src/Resource/Constants/Document.php b/src/Resource/Constants/Document.php index 868da6d..5b0c4fc 100644 --- a/src/Resource/Constants/Document.php +++ b/src/Resource/Constants/Document.php @@ -12,37 +12,52 @@ class Document { /** - * @var string document reason. + * @var string document reason */ const FUNCAO_ASSINAR = 'assinar'; /** - * @var string document reason. + * @var string document reason */ const FUNCAO_ASSINAR_TESTEMUNHA = 'assinar_testemunha'; /** - * @var string document reason. + * @var string document reason */ const FUNCAO_ACUSAR_RECEBIMENTO = 'acusar_recebimento'; /** - * @var string document reason. + * @var string document reason */ const FUNCAO_RECONHECER = 'reconhecer'; /** - * @var string document reason. + * @var string document reason */ const FUNCAO_APROVAR = 'aprovar'; /** - * @var string document reason. + * @var string document reason */ const FREQUENCIA_SEMANAL = 'semanal'; /** - * @var string document reason. + * @var string document reason */ const FREQUENCIA_DIARIA = 'diario'; + + /** + * @var string QR Code + */ + const QRCODE_BOTTOM = 'B'; + + /** + * @var string QR Code + */ + const QRCODE_LEFT = 'L'; + + /** + * @var string QR Code + */ + const QRCODE_RIGHT = 'R'; } diff --git a/src/Resource/Document.php b/src/Resource/Document.php index e6be3de..faea24a 100644 --- a/src/Resource/Document.php +++ b/src/Resource/Document.php @@ -12,18 +12,18 @@ class Document extends AbstractResource { /** - * @var string api path for document manipulation. + * @var string api path for document manipulation */ const PATH = 'documentos'; /** * List documents that are not in a folder. * - * @param int $page page counter. - * @param int $counter number of items in the page. - * @param string $s search string. + * @param int $page page counter + * @param int $counter number of items in the page + * @param string $s search string * - * @return \stdClass document list. + * @return \stdClass document list * * @see https://autentique.docs.apiary.io/#reference/0/documentos/lista-todos-documentos-que-nao-estao-numa-pasta. */ @@ -37,9 +37,9 @@ public function listNotInFolder(int $page, int $count, string $s = '') /** * Retrieves a document with uuid $uuid. * - * @param string $uuid document uuid. + * @param string $uuid document uuid * - * @return \stdClass document data. + * @return \stdClass document data * * @see https://autentique.docs.apiary.io/#reference/0/documentos/resgata-informacoes-sobre-documento-especifico. */ @@ -53,11 +53,11 @@ public function retrieve(string $uuid) /** * List received documents that are not in a folder. * - * @param int $page page counter. - * @param int $counter number of items in the page. - * @param string $s search string. + * @param int $page page counter + * @param int $counter number of items in the page + * @param string $s search string * - * @return \stdClass received document list. + * @return \stdClass received document list * * @see https://autentique.docs.apiary.io/#reference/0/documentos/lista-apenas-documentos-recebidos-que-nao-estao-numa-pasta. */ @@ -71,11 +71,11 @@ public function listReceivedNotInFolder(int $page, int $count, string $s = '') /** * List sent documents. * - * @param int $page page counter. - * @param int $counter number of items in the page. - * @param string $s search string. + * @param int $page page counter + * @param int $counter number of items in the page + * @param string $s search string * - * @return \stdClass list of documents sent. + * @return \stdClass list of documents sent * * @see https://autentique.docs.apiary.io/#reference/0/documentos/lista-apenas-documentos-enviados. */ @@ -89,18 +89,19 @@ public function listOnlySent(int $page, int $count, string $s = '') /** * Creates a new document. * - * @param string $nome document name. - * @param array $partes document signatories. - * @param resource $arquivo document file. - * @param bool $rejeitavel is rejectable. - * @param string|null $mensagem document message. - * @param bool|null $lembreteAssinatura sign remainder. - * @param bool|null $lembreteVencimento expiration date remainder. - * @param string|null $frequencia remainder sending. - * @param int|null $diasVencimento days left to due date. - * @param string|null $dataVencimento due date. + * @param string $nome document name + * @param array $partes document signatories + * @param resource $arquivo document file + * @param bool $rejeitavel is rejectable + * @param string|null $mensagem document message + * @param bool|null $lembreteAssinatura sign reminder + * @param bool|null $lembreteVencimento expiration date reminder + * @param string|null $frequencia reminder sending + * @param int|null $diasVencimento days left to due date + * @param string|null $dataVencimento due date + * @param string|null $qrcode QRcode type (B: bottom, L: left, R: right) * - * @return \stdClass new document info. + * @return \stdClass new document info * * @see https://autentique.docs.apiary.io/#reference/0/documentos/cria-um-novo-documento. */ @@ -114,13 +115,14 @@ public function create( bool $lembreteVencimento = null, string $frequencia = null, int $diasVencimento = null, - string $dataVencimento = null + string $dataVencimento = null, + string $qrcode = null ) { $data = [ - 'nome' => $nome, - 'partes' => $partes, - 'arquivo' => $arquivo, - 'rejeitavel' => $rejeitavel, + 'nome' => $nome, + 'partes' => $partes, + 'arquivo' => $arquivo, + 'rejeitavel' => $rejeitavel, ]; if (!is_null($mensagem)) { @@ -147,6 +149,10 @@ public function create( $data['dataVencimento'] = $dataVencimento; } + if (!is_null($qrcode)) { + $data['rodape'] = $qrcode; + } + $payload = $this->buildCreatePayload($data); $result = $this->post(self::PATH.'.json', [ @@ -159,9 +165,9 @@ public function create( /** * Resend signature email to signatories. * - * @param string $uuid document uuid. + * @param string $uuid document uuid * - * @return string an empty string. + * @return string an empty string * * @see https://autentique.docs.apiary.io/#reference/0/documentos/reenvia-email-de-assinatura-para-os-signatarios-que-nao-assinara/rejeitaram. */ @@ -175,9 +181,9 @@ public function resendNotSignedOrRejected(string $uuid) /** * Deletes a document with uuid $uuid. * - * @param string $uuid document uuid. + * @param string $uuid document uuid * - * @return \stdClass object with a message key (this is different from api documentation). + * @return \stdClass object with a message key (this is different from api documentation) * * @see https://autentique.docs.apiary.io/#reference/0/documentos/remove-documento-especifico. */ @@ -191,9 +197,9 @@ public function deleteDocument(string $uuid) /** * Build the payload for creating a new document. * - * @param array $data creation data. + * @param array $data creation data * - * @return array Guzzle multipart array. + * @return array guzzle multipart array * * @see http://docs.guzzlephp.org/en/stable/request-options.html#multipart. */ @@ -203,11 +209,11 @@ private function buildCreatePayload(array $data) foreach ($data['partes'] as $idx => $value) { $payload[] = [ - 'name' => 'partes['.$idx.'][funcao]', + 'name' => 'partes['.$idx.'][funcao]', 'contents' => $value['funcao'] ?? null, ]; $payload[] = [ - 'name' => 'partes['.$idx.'][email]', + 'name' => 'partes['.$idx.'][email]', 'contents' => $value['email'] ?? null, ]; } @@ -224,7 +230,7 @@ private function buildCreatePayload(array $data) } $payload[] = [ - 'name' => $key, + 'name' => $key, 'contents' => $value, ]; } diff --git a/tests/Resource/DocumentTest.php b/tests/Resource/DocumentTest.php index 0a8dc18..401e1fe 100644 --- a/tests/Resource/DocumentTest.php +++ b/tests/Resource/DocumentTest.php @@ -9,6 +9,7 @@ use Exception; use GuzzleHttp\Psr7\Response; use Mdojr\Autentique\Tests\TestCase; +use Mdojr\Autentique\Resource\Constants\Document as DocumentConstants; class DocumentTest extends TestCase { @@ -169,6 +170,30 @@ public function testCanCreateDocument() $this->assertNotEmpty($data->nome); } + public function testCanCreateDocumentWithQRCode() + { + $document = $this->getDocument($this->setUpCanCreateDocument()); + + $docData = $this->getDocData(); + + $data = $document->create( + $docData[0], // nome + $docData[1], // partes + $docData[2], // arquivo + $docData[3], // rejeitavel + null, // message + null, // sign reminder + null, // expiration date reminder + null, // reminder sending + null, // days left to due date + null, // due date + DocumentConstants::QRCODE_BOTTOM // QR Code + ); + + $this->assertNotEmpty($data->uuid); + $this->assertNotEmpty($data->nome); + } + public function setUpCreateDocumentThrowsError401() { return new Response(401, ['Content-Type' => 'application/json'], file_get_contents(__DIR__.'/../data/document/create-401.json')); @@ -289,7 +314,7 @@ public function getDocData() $nome = 'Contrato de Emprestimo P2P'; $partes = [ [ - 'email' => 'testando@fakeemail.com', + 'email' => 'testando@fakeemail.com', 'funcao' => Constants\Document::FUNCAO_ASSINAR, ], ]; diff --git a/tests/TestCase.php b/tests/TestCase.php index f949f00..5408b82 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -21,6 +21,7 @@ abstract class TestCase extends BaseTestCase protected function getClient(Response $mockedResponse = null, $useBadToken = false) { $sandboxToken = getenv('AUTENTIQUE_TOKEN'); + $endpoint = getenv('AUTENTIQUE_ENDPOINT'); $token = self::MOCK_TOKEN; if ($useBadToken) { @@ -30,8 +31,8 @@ protected function getClient(Response $mockedResponse = null, $useBadToken = fal } $config = [ - 'base_uri' => Endpoint::SANDBOX, - 'headers' => [ + 'base_uri' => $endpoint ? $endpoint : Endpoint::SANDBOX, + 'headers' => [ 'X-Autntiq-Api' => $token, ], ];