Skip to content

Commit

Permalink
Merge pull request #7 from marciodojr/qrcode
Browse files Browse the repository at this point in the history
Adiciona parametro QRcode no document create
  • Loading branch information
marciodojr committed Mar 21, 2019
2 parents e55f2b3 + f52e404 commit 218ba86
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 51 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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
```

Expand Down
29 changes: 22 additions & 7 deletions src/Resource/Constants/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
86 changes: 46 additions & 40 deletions src/Resource/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand All @@ -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.
*/
Expand All @@ -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.
*/
Expand All @@ -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.
*/
Expand All @@ -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.
*/
Expand All @@ -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)) {
Expand All @@ -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', [
Expand All @@ -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.
*/
Expand All @@ -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.
*/
Expand All @@ -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.
*/
Expand All @@ -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,
];
}
Expand All @@ -224,7 +230,7 @@ private function buildCreatePayload(array $data)
}

$payload[] = [
'name' => $key,
'name' => $key,
'contents' => $value,
];
}
Expand Down
27 changes: 26 additions & 1 deletion tests/Resource/DocumentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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'));
Expand Down Expand Up @@ -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,
],
];
Expand Down
5 changes: 3 additions & 2 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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,
],
];
Expand Down

0 comments on commit 218ba86

Please sign in to comment.