Skip to content

Commit

Permalink
response
Browse files Browse the repository at this point in the history
  • Loading branch information
ewerson@e-htl.com.br committed Sep 20, 2018
1 parent 90811a8 commit 4962790
Show file tree
Hide file tree
Showing 6 changed files with 278 additions and 27 deletions.
3 changes: 1 addition & 2 deletions examples/examples.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@
$cnab = new CNABPagamento(\Ewersonfc\CNABPagamento\Bancos::SAFRA);
//$tipoRetorno = 'confirmacao_rejeicao';
//$data = $cnab->processarRetorno('/home/ewerson/Downloads/RETORNO_701EHTLRONL0042119206.txt', $tipoRetorno);
$tipoRetorno = 'liquidacao';
$data = $cnab->processarRetorno('/home/ewerson/Downloads/RETORNO_701EHTLRONL0042123031.txt', $tipoRetorno);
$data = $cnab->processarRetorno('/home/ewerson/Downloads/RETORNO_701EHTLRONL0042119194.txt');

echo '<pre>';
print_r($data);
Expand Down
14 changes: 14 additions & 0 deletions src/Bancos.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/
namespace Ewersonfc\CNABPagamento;

use Ewersonfc\CNABPagamento\Constants\TipoRetorno;
use Ewersonfc\CNABPagamento\Exceptions\CNABPagamentoException;
/**
* Class Bancos
Expand Down Expand Up @@ -38,4 +39,17 @@ public static function getBankData(int $banco)
break;
}
}

public static function getSafraDetailType($type)
{
switch ($type)
{
case 'C':
return TipoRetorno::CONFIRMACAO_REJEICAO;
case 'L':
return TipoRetorno::LIQUIDACAO;
default:
return TipoRetorno::CONFIRMACAO_REJEICAO;
}
}
}
15 changes: 5 additions & 10 deletions src/CNABPagamento.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,13 @@ public function gerarArquivo(DataFile $dataFile)

/**
* @param $archivePath
* @throws \Exception
* @param $tipoRetorno
* @return Factories\DataFile
* @throws FileRetornoException
*/
public function processarRetorno($archivePath, $tipoRetorno)
public function processarRetorno($archivePath)
{
if(!in_array($tipoRetorno, [
TipoRetorno::CONFIRMACAO_REJEICAO,
TipoRetorno::LIQUIDACAO,
TipoRetorno::DDA,
])) {
throw new FileRetornoException("Tipo de retorno definido não existe.");
};
$data = $this->serviceRetorno->readFile($archivePath, $tipoRetorno);
$data = $this->serviceRetorno->readFile($archivePath);
return $data;
}
}
49 changes: 43 additions & 6 deletions src/Factories/RetornoFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
namespace Ewersonfc\CNABPagamento\Factories;


use Ewersonfc\CNABPagamento\Responses\FileResponse;
use Ewersonfc\CNABPagamento\Entities\DataFile;

class RetornoFactory
Expand All @@ -35,15 +36,51 @@ function __construct($header, $detail)
$this->detail = $detail;
}

private function makeRejeicao($dataRejeicao)
{
return str_split($dataRejeicao, 3);
}

/**
* @return DataFile
*/
public function generateResponse()
public function generateSafraResponse()
{
$dataFile = new DataFile();
$dataFile->header = $this->header;
$dataFile->detail = $this->detail;
$response = [];
foreach($this->detail as $detail) {
$approved = false;
$fileResponse = new FileResponse;

if(($detail['codigo_operacao']['value'] == 'C' AND trim($detail['codigo_rejeicao']['value']) == null) OR $detail['codigo_operacao']['value'] == 'L')
$approved = true;

return $dataFile;

$fileResponse->aprovado = $approved;
$fileResponse->tipoAprovacao = $detail['codigo_operacao']['value'];
if(!$approved) {
$fileResponse->rejeicao = $this->makeRejeicao($detail['codigo_motivo_rejeicao']['value']);
}
$fileResponse->registro = $detail['codigo_registro']['value'];
$fileResponse->inscricao = $detail['codigo_registro']['value'];
$fileResponse->agencia = $detail['codigo_agencia']['value'];
$fileResponse->fornecedor = $detail['codigo_fornecedor']['value'];
$fileResponse->documento = $detail['tipo_documento']['value'];
$fileResponse->compromisso = $detail['numero_compromisso']['value'];
$fileResponse->dataPagamento = $detail['data_pagamento']['value'];
$fileResponse->dataVencimento = $detail['data_vencimento']['value'];
$fileResponse->operacao = $detail['codigo_operacao']['value'];
$fileResponse->ocorrencia = $detail['codigo_ocorrencia']['value'];
$fileResponse->dataOcorrencia = $detail['data_ocorrencia']['value'];
$fileResponse->numeroCompromisso = $detail['negociacao_compromisso']['value'];
$fileResponse->valorCompromisso = $detail['valor_compromisso']['value'];
$fileResponse->agenciaDestino = $detail['agencia_destino']['value'];
$fileResponse->contaDestino = $detail['conta_destino']['value'];

$response[] = $fileResponse;
}
print_r($response);
exit();
}
}
}


193 changes: 193 additions & 0 deletions src/Responses/FileResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
<?php

namespace Ewersonfc\CNABPagamento\Responses;
/**
* Created by PhpStorm.
* User: ewerson
* Date: 20/09/18
* Time: 11:23
*/

class FileResponse
{
public $aprovado;

public $tipoAprovacao;

public $rejeicao;

public $registro;

public $inscricao;

public $agencia;

public $fornecedor;

public $documento;

public $compromisso;

public $dataPagamento;

public $dataVencimento;

public $operacao;

public $ocorrencia;

public $dataOcorrencia;

public $negociacaoCompromisso;

public $valorCompromisso;

public $agenciaDestino;

public $contaDestino;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

}
Loading

0 comments on commit 4962790

Please sign in to comment.