Skip to content

Commit

Permalink
Método criarBoleto agora insere no banco de dados o código retornado …
Browse files Browse the repository at this point in the history
…pela API [Issue #807]
  • Loading branch information
GabrielPintoSouza committed Nov 26, 2024
1 parent a7f8119 commit b51caad
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
7 changes: 5 additions & 2 deletions html/apoio/controller/ContribuicaoLogController.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,16 +108,19 @@ public function criarBoleto() //Talvez seja melhor separar em: criarBoleto, cria
caso o serviço de pagamento tenha sido executado*/
$this->pdo->beginTransaction();
$contribuicaoLogDao = new ContribuicaoLogDAO($this->pdo);
$contribuicaoLogDao->criar($contribuicaoLog);
$contribuicaoLog = $contribuicaoLogDao->criar($contribuicaoLog);

//Registrar na tabela de socio_log
$mensagem = "Boleto gerado recentemente";
$socioDao->registrarLog($contribuicaoLog->getSocio(), $mensagem);

$codigoApi = $servicoPagamento->gerarBoleto($contribuicaoLog);

//Chamada do método de serviço de pagamento requisitado
if (!$servicoPagamento->gerarBoleto($contribuicaoLog)) {
if (!$codigoApi) {
$this->pdo->rollBack();
} else {
$contribuicaoLogDao->alterarCodigoPorId($codigoApi, $contribuicaoLog->getId());
$this->pdo->commit();
}
} catch (PDOException $e) {
Expand Down
15 changes: 15 additions & 0 deletions html/apoio/dao/ContribuicaoLogDAO.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,21 @@ public function criar(ContribuicaoLog $contribuicaoLog){
$stmt->bindParam(':statusPagamento', $contribuicaoLog->getStatusPagamento());

$stmt->execute();

$ultimoId = $this->pdo->lastInsertId();
$contribuicaoLog->setId($ultimoId);

return $contribuicaoLog;
}

public function alterarCodigoPorId($codigo, $id){
$sqlPagarPorId = "UPDATE contribuicao_log SET codigo =:codigo WHERE id=:id";

$stmt = $this->pdo->prepare($sqlPagarPorId);
$stmt->bindParam(':codigo', $codigo);
$stmt->bindParam(':id', $id);

$stmt->execute();
}

public function pagarPorId($id){
Expand Down
5 changes: 4 additions & 1 deletion html/apoio/service/PagarMeBoletoService.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ public function gerarBoleto(ContribuicaoLog $contribuicaoLog)
$responseData = json_decode($response, true);
$pdf_link = $responseData['charges'][0]['last_transaction']['pdf'];

//pegar o código da plataforma
$codigoPagarMe = $responseData['code'];

//armazena copía para segunda via
$this->guardarSegundaVia($pdf_link, $contribuicaoLog);

Expand All @@ -128,7 +131,7 @@ public function gerarBoleto(ContribuicaoLog $contribuicaoLog)
}
}

return true;
return $codigoPagarMe;
}
public function guardarSegundaVia($pdf_link, ContribuicaoLog $contribuicaoLog)
{
Expand Down

0 comments on commit b51caad

Please sign in to comment.