Skip to content

Commit

Permalink
Ajustes no payload de envio de jusro e multa na api da Unicred
Browse files Browse the repository at this point in the history
  • Loading branch information
mfgustav0 committed Jul 2, 2024
1 parent 415c0d5 commit 32a71c1
Show file tree
Hide file tree
Showing 2 changed files with 173 additions and 5 deletions.
116 changes: 111 additions & 5 deletions src/Boleto/Banco/Unicred.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,113 @@ class Unicred extends AbstractBoleto implements BoletoContract
* @var string|null
*/
protected $variacao_carteira = null;


/**
* Tipo de Juros
*/
const TIPO_JURO_VALOR_DIARIO = '1';
const TIPO_JURO_TAXA_DIARIA = '2';
const TIPO_JURO_TAXA_MENSAL = '3';
const TIPO_JURO_ISENTO = '5';

/**
* Tipo de Juro
*
* @var int
*/
protected $tipoJuro = self::TIPO_JURO_ISENTO;

/**
* Tipo de Juro Válidos
*
* @var array<int>
*/
protected $tipoJurosValidos = [
'VALOR_DIARIO' => self::TIPO_JURO_VALOR_DIARIO,
'TAXA_DIARIA' => self::TIPO_JURO_TAXA_DIARIA,
'TAXA_MENSAL' => self::TIPO_JURO_TAXA_MENSAL,
'ISENTO' => self::TIPO_JURO_ISENTO,
];

/**
* Tipo de Multa
*/
const TIPO_MULTA_VALOR_FIXO = '1';
const TIPO_MULTA_TAXA = '2';
const TIPO_MULTA_ISENTO = '3';

/**
* Tipo de Multa
*
* @var string
*/
protected $tipoMulta = self::TIPO_MULTA_ISENTO;

/**
* Tipo de Multas Válidos
*
* @var array<int>
*/
protected $tipoMultasValidos = [
'ISENTO' => self::TIPO_MULTA_ISENTO,
'VALOR_FIXO' => self::TIPO_MULTA_VALOR_FIXO,
'TAXA' => self::TIPO_MULTA_TAXA
];

/**
* Define a Tipo de Juro
*
* @param ?string $tipoJuro
* @return AbstractBoleto
*/
public function setTipoJuro($tipoJuro)
{
if(!isset($this->tipoJurosValidos[$tipoJuro])) {
throw new \Exception("Tipo de juro não disponível!");
}

$this->tipoJuro = $this->tipoJurosValidos[$tipoJuro];

return $this;
}

/**
* Retorna Tipo de Juro
*
* @return string
*/
public function getTipoJuro()
{
return $this->tipoJuro;
}

/**
* Define a Tipo de Multa
*
* @param string $tipoMulta
* @return AbstractBoleto
*/
public function setTipoMulta($tipoMulta)
{
if(!isset($this->tipoMultasValidos[$tipoMulta])) {
throw new \Exception("Tipo de multa não disponível!");
}

$this->tipoMulta = $this->tipoMultasValidos[$tipoMulta];

return $this;
}

/**
* Retorna Tipo de Multa
*
* @return string
*/
public function getTipoMulta()
{
return $this->tipoMulta;
}

/**
* Define o número da variação da carteira.
*
Expand Down Expand Up @@ -267,16 +373,16 @@ public function toAPI()

if ($this->getMulta()) {
$data['multa'] = [
'indicador' => '0',
'dataLimite' => ($this->getDataVencimento()->copy())->addDay()->format('Y-m-d'),
'codigo' => $this->getTipoMulta(),
'dataInicio' => ($this->getDataVencimento()->copy())->addDay()->format('Y-m-d'),
'valor' => Util::nFloat($this->getMulta()),
];
}

if ($this->getJuros()) {
$data['juros'] = [
'indicador' => '0',
'dataLimite' => ($this->getDataVencimento()->copy())->addDays($this->getJurosApos() > 0 ? $this->getJurosApos() : 1)->format('Y-m-d'),
'codigo' => $this->getTipoJuro(),
'dataInicio' => ($this->getDataVencimento()->copy())->addDays($this->getJurosApos() > 0 ? $this->getJurosApos() : 1)->format('Y-m-d'),
'valor' => Util::nFloat($this->getJuros()),
];
}
Expand Down
62 changes: 62 additions & 0 deletions tests/Boleto/BoletoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Eduardokum\LaravelBoleto\Tests\Boleto;

use Exception;
use Eduardokum\LaravelBoleto\Util;
use Eduardokum\LaravelBoleto\Pessoa;
use PHPUnit\Framework\Constraint\IsType;
use Eduardokum\LaravelBoleto\Tests\TestCase;
Expand Down Expand Up @@ -857,4 +858,65 @@ public function testBoletoAilos()
$this->assertNotNull($boleto->renderHTML());
$this->assertNotNull($boleto->renderPDF());
}

public function testBoletoApiUnicred()
{
$boleto = new Boleto\Unicred([
'logo' => realpath(__DIR__ . '/../../logos/') . DIRECTORY_SEPARATOR . '136.png',
'dataVencimento' => new \Carbon\Carbon(),
'valor' => 100,
'multa' => 5,
'juros' => 5,
'numero' => 1,
'numeroDocumento' => 1,
'pagador' => self::$pagador,
'beneficiario' => self::$beneficiario,
'carteira' => '21',
'convenio' => '000000',
'agencia' => 1111,
'agenciaDv' => 1,
'conta' => 11111,
'contaDv' => 1,
'descricaoDemonstrativo' => ['demonstrativo 1', 'demonstrativo 2', 'demonstrativo 3'],
'instrucoes' => ['instrucao 1', 'instrucao 2', 'instrucao 3'],
'aceite' => 'S',
'especieDoc' => 'DM',
'tipoJuro' => 'VALOR_DIARIO',
'tipoMulta' => 'VALOR_FIXO',
]);
$this->assertThat($boleto->toAPI(), (new IsType(IsType::TYPE_ARRAY)));

$this->assertEquals($boleto->toAPI(), [
'seuNumero' => $boleto->getNumero(),
'valor' => Util::nFloat($boleto->getValor(), 2, false),
'vencimento' => $boleto->getDataVencimento()->format('Y-m-d'),
'pagador' => [
'nomeRazaoSocial' => substr($boleto->getPagador()->getNome(), 0, 40),
'tipoPessoa' => strlen(Util::onlyNumbers($boleto->getPagador()->getDocumento())) == 14 ? 'J' : 'F',
'numeroDocumento' => Util::onlyNumbers($boleto->getPagador()->getDocumento()),
'nomeFantasia' => $boleto->getPagador()->getNomeFantasia(),
'email' => $boleto->getPagador()->getEmail(),
'endereco' => [
'logradouro' => $boleto->getPagador()->getEndereco(),
'bairro' => $boleto->getPagador()->getBairro(),
'cidade' => $boleto->getPagador()->getCidade(),
'uf' => $boleto->getPagador()->getUf(),
'cep' => Util::onlyNumbers($boleto->getPagador()->getCep())
]
],
'mensagensFichaCompensacao' => array_filter(array_map(function($instrucao) {
return is_null($instrucao) ? null : trim($instrucao);
}, $boleto->getInstrucoes())),
'multa' => [
'codigo' => $boleto->getTipoMulta(),
'dataInicio' => ($boleto->getDataVencimento()->copy())->addDay()->format('Y-m-d'),
'valor' => Util::nFloat($boleto->getMulta()),
],
'juros' => [
'codigo' => $boleto->getTipoJuro(),
'dataInicio' => ($boleto->getDataVencimento()->copy())->addDays($boleto->getJurosApos() > 0 ? $boleto->getJurosApos() : 1)->format('Y-m-d'),
'valor' => Util::nFloat($boleto->getJuros()),
]
]);
}
}

0 comments on commit 32a71c1

Please sign in to comment.