Skip to content

Commit

Permalink
santander pix cnab
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardokum committed Nov 17, 2023
1 parent f05ebf8 commit efd1cd9
Show file tree
Hide file tree
Showing 61 changed files with 809 additions and 220 deletions.
Binary file not shown.
Binary file not shown.
Binary file removed manuais/SANTANDER/webservice/Santander.pdf
Binary file not shown.
1 change: 1 addition & 0 deletions src/Api/Banco/Inter.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ public function createWebhook($url, $type = 'all')
* @throws CurlException
* @throws HttpException
* @throws UnauthorizedException
* @throws ValidationException
*/
public function createBoleto(BoletoAPIContract $boleto)
{
Expand Down
130 changes: 124 additions & 6 deletions src/Boleto/AbstractBoleto.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,20 @@

namespace Eduardokum\LaravelBoleto\Boleto;

use Exception;
use Carbon\Carbon;
use Illuminate\Support\Str;
use chillerlan\QRCode\QRCode;
use chillerlan\QRCode\QROptions;
use Eduardokum\LaravelBoleto\Exception\ValidationException;
use Exception;
use Illuminate\Support\Str;
use Eduardokum\LaravelBoleto\Util;
use Eduardokum\LaravelBoleto\Boleto\Render\Pdf;
use Eduardokum\LaravelBoleto\Boleto\Render\Html;
use Eduardokum\LaravelBoleto\Boleto\Render\PdfCaixa;
use Eduardokum\LaravelBoleto\Contracts\Boleto\Boleto;
use Eduardokum\LaravelBoleto\Exception\ValidationException;
use Eduardokum\LaravelBoleto\Contracts\Pessoa as PessoaContract;
use Eduardokum\LaravelBoleto\Contracts\Boleto\Boleto as BoletoContract;
use Throwable;

/**
* Class AbstractBoleto
Expand All @@ -27,6 +28,12 @@ abstract class AbstractBoleto implements BoletoContract
const SITUACAO_PAGO = 'pago';
const SITUACAO_PROTESTADO = 'protestado';

const TIPO_CHAVEPIX_CPF = 'cpf';
const TIPO_CHAVEPIX_CNPJ = 'cnpj';
const TIPO_CHAVEPIX_CELULAR = 'celular';
const TIPO_CHAVEPIX_EMAIL = 'email';
const TIPO_CHAVEPIX_ALEATORIA = 'aleatoria';

/**
* Campos necessários para o boleto
*
Expand Down Expand Up @@ -394,12 +401,22 @@ abstract class AbstractBoleto implements BoletoContract
*/
private $pixQrCode = null;

/**
* Chave Pix para criação de boleto com pix
* @var null
*/
private $pixChave = null;

/**
* Tipo da chave pix
* @var null
*/
private $pixChaveTipo = null;

/**
* AbstractBoleto constructor.
*
* @param array $params
*
* @throws ValidationException
*/
public function __construct($params = [])
{
Expand Down Expand Up @@ -1773,6 +1790,45 @@ public function getPixQrCode(): ?string
return $this->pixQrCode;
}

/**
* @return null
*/
public function getPixChave()
{
return $this->pixChave;
}

/**
* @param null $pixChave
* @return AbstractBoleto
*/
public function setPixChave($pixChave)
{
$this->pixChave = $pixChave;
return $this;
}

/**
* @return null
*/
public function getPixChaveTipo()
{
return $this->pixChaveTipo;
}

/**
* @param null $pixChaveTipo
* @return AbstractBoleto
* @throws ValidationException
*/
public function setPixChaveTipo($pixChaveTipo)
{
if (!in_array($pixChaveTipo, [self::TIPO_CHAVEPIX_CPF,self::TIPO_CHAVEPIX_CNPJ,self::TIPO_CHAVEPIX_CELULAR,self::TIPO_CHAVEPIX_EMAIL,self::TIPO_CHAVEPIX_ALEATORIA])) {
throw new ValidationException(sprintf('Tipo de chave %s não é válido', $pixChaveTipo));
}
$this->pixChaveTipo = $pixChaveTipo;
return $this;
}

/**
* @return ?string
Expand Down Expand Up @@ -1858,11 +1914,69 @@ public function isProtestado()
return $this->isSituacao(self::SITUACAO_PROTESTADO);
}

/**
* @return bool
*/
public function imprimeBoleto()
{
return true;
}

/**
* @return bool
* @throws ValidationException
*/
public function validarPix()
{
if ($this->getPixChave() || $this->getPixChaveTipo()) {
if (!$this->getPixChave()) {
throw new ValidationException('Informado tipo de chave de Pix porém não foi informado a chave');
}
if (!$this->getPixChaveTipo()) {
throw new ValidationException('Informado tipo de chave de Pix porém não foi informado a chave');
}
if (!$this->getID()) {
throw new ValidationException('ID necessita ser informado para geração da cobrança');
}

switch ($this->getPixChaveTipo()) {
case self::TIPO_CHAVEPIX_CPF:
if (!Util::validarCpf($this->getPixChave())) {
throw new ValidationException(sprintf('Chave do tipo CPF é invalida: %s', $this->getPixChave()));
}
break;
case self::TIPO_CHAVEPIX_CNPJ:
if (!Util::validarCnpj($this->getPixChave())) {
throw new ValidationException(sprintf('Chave do tipo CNPJ é invalida: %s', $this->getPixChave()));
}
break;
case self::TIPO_CHAVEPIX_EMAIL:
if (!filter_var($this->getPixChave(), FILTER_VALIDATE_EMAIL)) {
throw new ValidationException(sprintf('Chave do tipo EMAIL é invalida: %s', $this->getPixChave()));
}
break;
case self::TIPO_CHAVEPIX_CELULAR:
if (strlen(Util::onlyNumbers($this->getPixChave())) != 11) {
throw new ValidationException(sprintf('Chave do tipo CELULAR é invalida: %s', $this->getPixChave()));
}
break;
case self::TIPO_CHAVEPIX_ALEATORIA:
if (!preg_match('/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/', $this->getPixChave())) {
throw new ValidationException(sprintf('Chave do tipo ALEATÓRIA é invalida: %s', $this->getPixChave()));
}
break;
}

if (!$this->getPixQrCode()) {
$this->setPixQrCode(Util::gerarPixCopiaECola($this->getPixChave(), $this->getValor(), $this->getID(), $this->getBeneficiario()));
}

return true;
}

return false;
}

/**
* Render PDF
*
Expand Down Expand Up @@ -1893,7 +2007,7 @@ public function renderPDF($print = false, $instrucoes = true)
* @param bool $instrucoes
*
* @return string
* @throws \Throwable
* @throws Throwable
*/
public function renderHTML($print = false, $instrucoes = true)
{
Expand Down Expand Up @@ -1941,6 +2055,8 @@ public function toArray()
} catch (Exception $e) {
}

$this->validarPix();

return array_merge([
'linha_digitavel' => $linha_digitavel,
'codigo_barras' => $codigo_barras,
Expand Down Expand Up @@ -2017,6 +2133,8 @@ public function toArray()
'uso_banco' => $this->getUsoBanco(),
'status' => $this->getStatus(),
'mostrar_endereco_ficha_compensacao' => $this->getMostrarEnderecoFichaCompensacao(),
'pix_chave' => $this->getPixChave(),
'pix_chave_tipo' => $this->getPixChaveTipo(),
'pix_qrcode' => $this->getPixQrCode(),
'pix_qrcode_image' => $this->getPixQrCodeBase64(),
], $this->variaveis_adicionais);
Expand Down
2 changes: 0 additions & 2 deletions src/Boleto/Banco/Bancoob.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ public function getConvenio()
/**
* Gera o Nosso Número.
*
* @throws \Exception
* @return string
*/
protected function gerarNossoNumero()
Expand All @@ -126,7 +125,6 @@ public function getNossoNumeroBoleto()
* Método para gerar o código da posição de 20 a 44
*
* @return string
* @throws \Exception
*/
protected function getCampoLivre()
{
Expand Down
2 changes: 0 additions & 2 deletions src/Boleto/Banco/C6.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ public function __construct(array $params = [])
* Gera o Nosso Número.
*
* @return string
* @throws \Exception
*/
protected function gerarNossoNumero()
{
Expand All @@ -93,7 +92,6 @@ public function getNossoNumeroBoleto()
* Método para gerar o código da posição de 20 a 44
*
* @return string
* @throws \Exception
*/
protected function getCampoLivre()
{
Expand Down
2 changes: 0 additions & 2 deletions src/Boleto/Banco/Ourinvest.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ public function setEmissaoPropria($emissaoPropria)
/**
* Gera o Nosso Número.
*
* @throws \Exception
* @return string
*/
protected function gerarNossoNumero()
Expand All @@ -82,7 +81,6 @@ protected function gerarNossoNumero()
* Método para gerar o código da posição de 20 a 44
*
* @return string
* @throws \Exception
*/
protected function getCampoLivre()
{
Expand Down
2 changes: 0 additions & 2 deletions src/Boleto/Banco/Unicred.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ class Unicred extends AbstractBoleto implements BoletoContract
* Obs.: O Nosso Número é um identificador do boleto, devendo ser atribuído
* Nosso Número diferenciado para cada um.
*
* @throws \Exception
* @return string
*/
protected function gerarNossoNumero()
Expand All @@ -98,7 +97,6 @@ public function getNossoNumeroBoleto()
* Método para gerar o código da posição de 20 a 44
*
* @return string
* @throws \Exception
*/
protected function getCampoLivre()
{
Expand Down
4 changes: 3 additions & 1 deletion src/Boleto/Render/AbstractPdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Eduardokum\LaravelBoleto\Boleto\Render;

use Exception;

abstract class AbstractPdf extends \FPDF
{
// INCLUDE JS
Expand Down Expand Up @@ -151,7 +153,7 @@ protected function textFitCell($w, $h, $txt, $border, $ln, $align, $dec = 0.1)
* @param int $basewidth
* @param int $height
*
* @throws \Exception
* @throws Exception
*/
public function i25($xpos, $ypos, $code, $basewidth = 1, $height = 10)
{
Expand Down
16 changes: 8 additions & 8 deletions src/Cnab/Remessa/Cnab240/Banco/Bancoob.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

namespace Eduardokum\LaravelBoleto\Cnab\Remessa\Cnab240\Banco;

use Eduardokum\LaravelBoleto\Exception\ValidationException;
use Eduardokum\LaravelBoleto\Util;
use Eduardokum\LaravelBoleto\CalculoDV;
use Eduardokum\LaravelBoleto\Cnab\Remessa\Cnab240\AbstractRemessa;
Expand Down Expand Up @@ -78,7 +79,6 @@ public function __construct(array $params = [])
* @param BoletoContract $boleto
*
* @return $this
* @throws \Exception
*/
public function addBoleto(BoletoContract $boleto)
{
Expand All @@ -94,7 +94,7 @@ public function addBoleto(BoletoContract $boleto)
* @param BoletoContract $boleto
*
* @return $this
* @throws \Exception
* @throws ValidationException
*/
protected function segmentoP(BoletoContract $boleto)
{
Expand Down Expand Up @@ -168,7 +168,7 @@ protected function segmentoP(BoletoContract $boleto)
* @param BoletoContract $boleto
*
* @return $this
* @throws \Exception
* @throws ValidationException
*/
public function segmentoQ(BoletoContract $boleto)
{
Expand Down Expand Up @@ -214,7 +214,7 @@ public function segmentoQ(BoletoContract $boleto)
* @param BoletoContract $boleto
*
* @return $this
* @throws \Exception
* @throws ValidationException
*/
public function segmentoR(BoletoContract $boleto)
{
Expand Down Expand Up @@ -256,7 +256,7 @@ public function segmentoR(BoletoContract $boleto)

/**
* @return $this
* @throws \Exception
* @throws ValidationException
*/
protected function header()
{
Expand Down Expand Up @@ -295,7 +295,7 @@ protected function header()

/**
* @return $this
* @throws \Exception
* @throws ValidationException
*/
protected function headerLote()
{
Expand Down Expand Up @@ -332,7 +332,7 @@ protected function headerLote()

/**
* @return $this
* @throws \Exception
* @throws ValidationException
*/
protected function trailerLote()
{
Expand All @@ -359,7 +359,7 @@ protected function trailerLote()

/**
* @return $this
* @throws \Exception
* @throws ValidationException
*/
protected function trailer()
{
Expand Down
Loading

0 comments on commit efd1cd9

Please sign in to comment.