Skip to content

Commit

Permalink
update retorno pix
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardokum committed Jan 17, 2024
1 parent c3e86e6 commit 9556859
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 91 deletions.
5 changes: 2 additions & 3 deletions exemplos/pix_retorno.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
<?php

require 'autoload.php';
$retorno = \Eduardokum\LaravelBoleto\Cnab\Retorno\Factory::make(__DIR__ . DIRECTORY_SEPARATOR . 'arquivos' . DIRECTORY_SEPARATOR . 'santander_pix.ret');
$retorno = \Eduardokum\LaravelBoleto\Cnab\Retorno\Factory::make(__DIR__ . DIRECTORY_SEPARATOR . 'arquivos' . DIRECTORY_SEPARATOR . 'ret.TXT');
$retorno->processar();

echo $retorno->getBancoNome();
dd([
'ID' => $retorno->getDetalhe(1)->getId(),
'CHAVE' => $retorno->getDetalhe(1)->getPixChave(),
'CHAVE_TIPO' => $retorno->getDetalhe(1)->getPixChaveTipo(),
'LOCATION' => $retorno->getDetalhe(1)->getLocation(),
'COPIA_E_COLA_VEIO_NO_RETORNO' => $retorno->getDetalhe(1)->getPixQrCode(),
'COPIA_E_COLA_GERADO_PELA_CLASSE' => $retorno->getDetalhe(1)->gerarPixCopiaECola('NOMEEMPRESA', 'SÃO PAULO', true),
]);
Binary file not shown.
41 changes: 9 additions & 32 deletions src/Cnab/Retorno/Cnab240/Detalhe.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,7 @@ class Detalhe implements DetalheContract
/**
* @var
*/
protected $pixChave;

/**
* @var
*/
protected $pixChaveTipo;
protected $pixLocation;

/**
* @var string
Expand Down Expand Up @@ -722,37 +717,18 @@ public function setPixQrCode($pixQrCode)
/**
* @return mixed
*/
public function getPixChave()
public function getPixLocation()
{
return $this->pixChave;
return $this->pixLocation;
}

/**
* @param mixed $pixChave
* @param mixed $pixLocation
* @return Detalhe
*/
public function setPixChave($pixChave)
public function setPixLocation($pixLocation)
{
$this->pixChave = $pixChave;

return $this;
}

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

/**
* @param mixed $pixChaveTipo
* @return Detalhe
*/
public function setPixChaveTipo($pixChaveTipo)
{
$this->pixChaveTipo = $pixChaveTipo;
$this->pixLocation = $pixLocation;

return $this;
}
Expand All @@ -762,15 +738,16 @@ public function setPixChaveTipo($pixChaveTipo)
* @param $cidade
* @param bool $force
* @return string|null
* @throws ValidationException
*/
public function gerarPixCopiaECola($nome, $cidade, $force = false)
{
if ($this->getPixQrCode() && ! $force) {
return $this->getPixQrCode();
}

if ($this->getPixChave() && $this->getValor() && $this->getID()) {
$this->setPixQrCode(Util::gerarPixCopiaECola($this->getPixChave(), $this->getValor(), $this->getID(), new Pessoa(['nome' => Util::normalizeChars($nome), 'cidade' => Util::normalizeChars($cidade)])));
if ($this->getPixLocation() && $this->getValor() && $this->getID()) {
$this->setPixQrCode(Util::gerarPixCopiaECola($this->getPixLocation(), $this->getValor(), $this->getID(), new Pessoa(['nome' => Util::normalizeChars($nome), 'cidade' => Util::normalizeChars($cidade)])));
}

return $this->getPixQrCode();
Expand Down
3 changes: 1 addition & 2 deletions src/Cnab/Retorno/Cnab400/Banco/Bradesco.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,7 @@ protected function processarTrailer(array $trailer)
private function processarPix(array $detalhe)
{
$d = $this->getDetalhe($this->increment - 1);
$d->setPixChave($this->rem(29, 105, $detalhe));
$d->setPixChaveTipo(Util::tipoChavePix($d->getPixChave()));
$d->setPixLocation($this->rem(29, 105, $detalhe));
$d->setId($this->rem(106, 140, $detalhe));

return false;
Expand Down
3 changes: 1 addition & 2 deletions src/Cnab/Retorno/Cnab400/Banco/Itau.php
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,7 @@ private function processarPix(array $detalhe)

$d->setPixQrCode(trim($this->rem(2, 391, $detalhe)));
if ($decoded = Util::decodePixCopiaECola($d->getPixQrCode())) {
$d->setPixChave(Arr::get($decoded, '26.01'));
$d->setPixChaveTipo(Util::tipoChavePix($d->getPixChave()));
$d->setPixLocation(Arr::get($decoded, '26.25'));
$d->setId(Arr::get($decoded, '62.05'));
}
$d->appendError($aErrorPix[sprintf('%03s', $this->rem(392, 394, $detalhe))]);
Expand Down
12 changes: 1 addition & 11 deletions src/Cnab/Retorno/Cnab400/Banco/Santander.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Illuminate\Support\Arr;
use Eduardokum\LaravelBoleto\Util;
use Eduardokum\LaravelBoleto\Boleto\AbstractBoleto;
use Eduardokum\LaravelBoleto\Contracts\Cnab\RetornoCnab400;
use Eduardokum\LaravelBoleto\Exception\ValidationException;
use Eduardokum\LaravelBoleto\Cnab\Retorno\Cnab400\AbstractRetorno;
Expand Down Expand Up @@ -369,17 +368,8 @@ protected function processarTrailer(array $trailer)
*/
private function processarPix(array $detalhe)
{
$tipoChave = [
1 => AbstractBoleto::TIPO_CHAVEPIX_CPF,
2 => AbstractBoleto::TIPO_CHAVEPIX_CNPJ,
3 => AbstractBoleto::TIPO_CHAVEPIX_CELULAR,
4 => AbstractBoleto::TIPO_CHAVEPIX_EMAIL,
5 => AbstractBoleto::TIPO_CHAVEPIX_ALEATORIA,
];

$d = $this->getDetalhe($this->increment - 1);
$d->setPixChaveTipo(Arr::get($tipoChave, $this->rem(2, 2, $detalhe)));
$d->setPixChave($this->rem(3, 79, $detalhe));
$d->setPixLocation($this->rem(3, 79, $detalhe));
$d->setId($this->rem(80, 114, $detalhe));

return false;
Expand Down
42 changes: 10 additions & 32 deletions src/Cnab/Retorno/Cnab400/Detalhe.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Eduardokum\LaravelBoleto\Util;
use Eduardokum\LaravelBoleto\Pessoa;
use Eduardokum\LaravelBoleto\MagicTrait;
use Eduardokum\LaravelBoleto\Exception\ValidationException;
use Eduardokum\LaravelBoleto\Contracts\Cnab\Retorno\Cnab400\Detalhe as DetalheContract;

class Detalhe implements DetalheContract
Expand Down Expand Up @@ -125,12 +126,7 @@ class Detalhe implements DetalheContract
/**
* @var
*/
protected $pixChave;

/**
* @var
*/
protected $pixChaveTipo;
protected $pixLocation;

/**
* @var string
Expand Down Expand Up @@ -679,37 +675,18 @@ public function setPixQrCode($pixQrCode)
/**
* @return mixed
*/
public function getPixChave()
{
return $this->pixChave;
}

/**
* @param mixed $pixChave
* @return Detalhe
*/
public function setPixChave($pixChave)
{
$this->pixChave = $pixChave;

return $this;
}

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

/**
* @param mixed $pixChaveTipo
* @param mixed $pixLocation
* @return Detalhe
*/
public function setPixChaveTipo($pixChaveTipo)
public function setPixLocation($pixLocation)
{
$this->pixChaveTipo = $pixChaveTipo;
$this->pixLocation = $pixLocation;

return $this;
}
Expand All @@ -719,14 +696,15 @@ public function setPixChaveTipo($pixChaveTipo)
* @param $cidade
* @param bool $force
* @return string|null
* @throws ValidationException
*/
public function gerarPixCopiaECola($nome, $cidade, $force = false)
{
if ($this->getPixQrCode() && ! $force) {
return $this->getPixQrCode();
}
if ($this->getPixChave() && $this->getValor() && $this->getID()) {
$this->setPixQrCode(Util::gerarPixCopiaECola($this->getPixChave(), $this->getValor(), $this->getID(), new Pessoa(['nome' => Util::normalizeChars($nome), 'cidade' => Util::normalizeChars($cidade)])));
if ($this->getPixLocation() && $this->getValor() && $this->getID()) {
$this->setPixQrCode(Util::gerarPixCopiaECola($this->getPixLocation(), $this->getValor(), $this->getID(), new Pessoa(['nome' => Util::normalizeChars($nome), 'cidade' => Util::normalizeChars($cidade)])));
}

return $this->getPixQrCode();
Expand Down
9 changes: 2 additions & 7 deletions src/Contracts/Cnab/Retorno/Detalhe.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,12 @@ public function getId();
/**
* @return mixed
*/
public function getPixQrCode();
public function getPixLocation();

/**
* @return mixed
*/
public function getPixChave();
public function getPixQrCode();

/**
* @param $nome
Expand All @@ -126,11 +126,6 @@ public function getPixChave();
*/
public function gerarPixCopiaECola($nome, $cidade, $force = false);

/**
* @return mixed
*/
public function getPixChaveTipo();

/**
* @return bool
*/
Expand Down
3 changes: 1 addition & 2 deletions tests/Retorno/RetornoCnab400Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -407,8 +407,7 @@ public function testRetornoPixCnab400()
$this->assertCount(1, $retorno->getDetalhes());

$this->assertNotNull($retorno->current()->getId());
$this->assertNotNull($retorno->current()->getPixChave());
$this->assertNotNull($retorno->current()->getPixChaveTipo());
$this->assertNotNull($retorno->current()->getPixLocation());
}

public function testRetornoSemPixCnab400()
Expand Down

0 comments on commit 9556859

Please sign in to comment.