Skip to content

Commit

Permalink
tipo de pessoa
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardokum committed Sep 20, 2024
1 parent 4ea02b8 commit 0648f08
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 12 deletions.
5 changes: 3 additions & 2 deletions src/Api/AbstractAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,7 @@ public function getBeneficiario()
public function setBeneficiario($beneficiario)
{
Util::addPessoa($this->beneficiario, $beneficiario);
$this->beneficiario->setTipo('beneficiario');

return $this;
}
Expand Down Expand Up @@ -464,7 +465,7 @@ protected function setRequestInfo($requestInfo)
* @throws UnauthorizedException
* @throws CurlException
*/
protected function post($url, array $post, $raw = false, $clear=true)
protected function post($url, array $post, $raw = false, $clear = true)
{
$url = ltrim($url, '/');
$this->init()
Expand All @@ -474,7 +475,7 @@ protected function post($url, array $post, $raw = false, $clear=true)
]));

// clean string
if($clear) {
if ($clear) {
$post = $this->arrayMapRecursive(function ($data) {
return Util::normalizeChars($data);
}, $post);
Expand Down
3 changes: 3 additions & 0 deletions src/Boleto/AbstractBoleto.php
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,7 @@ public function getCarteiras()
public function setBeneficiario($beneficiario)
{
Util::addPessoa($this->beneficiario, $beneficiario);
$this->beneficiario->setTipo('beneficiario');

return $this;
}
Expand Down Expand Up @@ -1271,6 +1272,7 @@ public function getMoeda()
public function setPagador($pagador)
{
Util::addPessoa($this->pagador, $pagador);
$this->pagador->setTipo('pagador');

return $this;
}
Expand All @@ -1296,6 +1298,7 @@ public function getPagador()
public function setSacadorAvalista($sacadorAvalista)
{
Util::addPessoa($this->sacadorAvalista, $sacadorAvalista);
$this->sacadorAvalista->setTipo('sacadorAvalista');

return $this;
}
Expand Down
1 change: 1 addition & 0 deletions src/Cnab/Remessa/AbstractRemessa.php
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ public function getBeneficiario()
public function setBeneficiario($beneficiario)
{
Util::addPessoa($this->beneficiario, $beneficiario);
$this->beneficiario->setTipo('beneficiario');

return $this;
}
Expand Down
1 change: 1 addition & 0 deletions src/Cnab/Retorno/Cnab240/Detalhe.php
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,7 @@ public function getPagador()
public function setPagador($pagador)
{
Util::addPessoa($this->pagador, $pagador);
$this->pagador->setTipo('pagador');

return $this;
}
Expand Down
2 changes: 2 additions & 0 deletions src/Contracts/Pessoa.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

interface Pessoa
{
public function getTipo();

public function getNome();

public function getNomeDocumento();
Expand Down
58 changes: 48 additions & 10 deletions src/Pessoa.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@

class Pessoa implements PessoaContract
{
/**
* @var string
*/
protected $tipo;

/**
* @var string
*/
Expand Down Expand Up @@ -72,15 +77,15 @@ class Pessoa implements PessoaContract
public static function create($nome, $documento, $endereco = null, $bairro = null, $cep = null, $cidade = null, $uf = null, $email = null, $nomeFantasia = null)
{
return new static([
'nome' => $nome,
'nomeFantasia' => $nomeFantasia,
'endereco' => $endereco,
'bairro' => $bairro,
'cep' => $cep,
'uf' => $uf,
'cidade' => $cidade,
'documento' => $documento,
'email' => $email,
'nome' => $nome,
'nomeFantasia' => $nomeFantasia,
'endereco' => $endereco,
'bairro' => $bairro,
'cep' => $cep,
'uf' => $uf,
'cidade' => $cidade,
'documento' => $documento,
'email' => $email,
]);
}

Expand All @@ -94,6 +99,39 @@ public function __construct($params = [])
Util::fillClass($this, $params);
}

/**
* Define o tipo
*
* @param $tipo
* @param bool $force
* @return Pessoa
* @throws ValidationException
*/
public function setTipo($tipo, $force = false)
{
if (! in_array($tipo, ['pagador', 'beneficiario', 'sacadorAvalista'])) {
throw new ValidationException("Tipo de pessoa inválido [$tipo]");
}

if ($this->getTipo() && ! $force) {
return $this;
}

$this->tipo = $tipo;

return $this;
}

/**
* Retorna o bairro
*
* @return string
*/
public function getTipo()
{
return $this->tipo;
}

/**
* Define o CEP
*
Expand Down Expand Up @@ -248,7 +286,7 @@ public function getNome()
{
return $this->nome;
}

/**
* Define o Nome Fantasia
*
Expand Down

0 comments on commit 0648f08

Please sign in to comment.