diff --git a/src/Boleto/Banco/Unicred.php b/src/Boleto/Banco/Unicred.php index c0143ff7..5f980040 100644 --- a/src/Boleto/Banco/Unicred.php +++ b/src/Boleto/Banco/Unicred.php @@ -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 + */ + 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 + */ + 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. * @@ -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()), ]; } diff --git a/tests/Boleto/BoletoTest.php b/tests/Boleto/BoletoTest.php index 3e54e2b7..ddf6216a 100644 --- a/tests/Boleto/BoletoTest.php +++ b/tests/Boleto/BoletoTest.php @@ -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; @@ -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()), + ] + ]); + } }