diff --git a/vendor/controller/api_sicoob/ApiSicoob.class.php b/vendor/controller/api_sicoob/ApiSicoob.class.php index 2897668..e66afba 100644 --- a/vendor/controller/api_sicoob/ApiSicoob.class.php +++ b/vendor/controller/api_sicoob/ApiSicoob.class.php @@ -33,10 +33,23 @@ class ApiSicoob private $urlApiCobrancaBancaria = null; private $info = null; private $urlToken = null; - private $pem = null; - private $key = null; - private $pass = null; + private $urlApi = null; + private $cert_pem = null; + private $cert_key = null; + private $cert_pass = null; private $token = null; + private $scope = null; + private $numero_contrato = null; + private $modalidade = null; + private $numero_conta_corrente = null; + private $especie_documento = null; + private $numero_cpfcnpj = null; + private $nome = null; + private $instrucao1 = null; + private $instrucao2 = null; + private $multa = null; + private $mora = null; + private $prazo_boleto = null; private $nameFile = null; private $dir = null; private $ch = null; @@ -46,16 +59,30 @@ class ApiSicoob public function __construct() { - /** Instânciamento de classes */ - $this->Main = new Main(); - + /** Carrega as configurações */ + $this->config = $this->LoadConfig(); + /** Parametros obrigatórios */ - $this->urlToken = 'https://auth.sicoob.com.br/auth/realms/cooperado/protocol/openid-connect/token'; - $this->urlApiCobrancaBancaria = 'https://api.sicoob.com.br/cobranca-bancaria/v2/'; - $this->clientId = '419105bb-bb40-42d3-ad67-971d850353da'; - $this->pem = 'cert/Chavepublica.pem'; - $this->key = 'cert/Chavepublica.key'; - $this->pass = '@Sun147oi.'; + $this->urlToken = $this->config->{'app'}->{'ticket'}->{'url_token'}; + $this->urlApi = $this->config->{'app'}->{'ticket'}->{'url_api_cobranca_bancaria'}; + $this->clientId = $this->config->{'app'}->{'ticket'}->{'client_id'}; + $this->cert_pem = $this->config->{'app'}->{'ticket'}->{'cert_pem'}; + $this->cert_key = $this->config->{'app'}->{'ticket'}->{'cert_key'}; + $this->cert_pass = $this->config->{'app'}->{'ticket'}->{'cert_pass'}; + $this->numero_contrato = $this->config->{'app'}->{'ticket'}->{'numero_contrato'}; + $this->modalidade = $this->config->{'app'}->{'ticket'}->{'modalidade'}; + $this->numero_conta_corrente = $this->config->{'app'}->{'ticket'}->{'numeroContaCorrente'}; + $this->especie_documento = $this->config->{'app'}->{'ticket'}->{'codigoEspecieDocumento'}; + $this->numero_cpfcnpj = $this->config->{'app'}->{'ticket'}->{'numero_cpfcnpj'}; + $this->nome = $this->config->{'app'}->{'ticket'}->{'nome'}; + $this->instrucao1 = $this->config->{'app'}->{'ticket'}->{'instrucao1'}; + $this->instrucao2 = $this->config->{'app'}->{'ticket'}->{'instrucao2'}; + $this->multa = $this->config->{'app'}->{'ticket'}->{'multa'}; + $this->mora = $this->config->{'app'}->{'ticket'}->{'mora'}; + $this->prazo_boleto = $this->config->{'app'}->{'ticket'}->{'prazo_boleto'}; + $this->scope = $this->config->{'app'}->{'ticket'}->{'scope'}; + + /** Pasta padrão de arquivos temporários */ $this->dir = 'temp/'; } @@ -69,19 +96,20 @@ class ApiSicoob public function accessToken(): void { + /** Inicio do acesso ao endpoint */ $this->ch = curl_init(); curl_setopt_array($this->ch, [ CURLOPT_URL => $this->urlToken, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_RETURNTRANSFER => true, CURLOPT_CUSTOMREQUEST => "POST", - CURLOPT_SSLCERT => $this->pem, - CURLOPT_SSLKEY => $this->key, - CURLOPT_SSLKEYPASSWD => $this->pass, + CURLOPT_SSLCERT => $this->cert_pem, + CURLOPT_SSLKEY => $this->cert_key, + CURLOPT_SSLKEYPASSWD => $this->cert_pass, CURLOPT_HTTPHEADER => array( "Accept: application/json", "Content-Type: application/x-www-form-urlencoded"), - CURLOPT_POSTFIELDS => "grant_type=client_credentials&client_id={$this->clientId}&scope=cobranca_boletos_consultar%20cobranca_boletos_incluir%20cobranca_boletos_pagador%20cobranca_boletos_segunda_via%20cobranca_boletos_descontos%20cobranca_boletos_abatimentos%20cobranca_boletos_valor_nominal%20cobranca_boletos_seu_numero%20cobranca_boletos_especie_documento%20cobranca_boletos_baixa" + CURLOPT_POSTFIELDS => "grant_type=client_credentials&client_id={$this->clientId}&scope={$this->scope}" ] ); @@ -102,6 +130,7 @@ class ApiSicoob /** Fecha a requisição anteriormente aberta */ curl_close($this->ch); + } /** @@ -128,105 +157,11 @@ class ApiSicoob switch($this->escoposDaAPI){ - case 'cobranca_boletos_incluir' : # Incluir boletos - - $this->ch = curl_init(); - curl_setopt_array($this->ch, array( - CURLOPT_URL => $this->urlApiCobrancaBancaria.'boletos', - CURLOPT_RETURNTRANSFER => true, - CURLOPT_ENCODING => '', - CURLOPT_MAXREDIRS => 10, - CURLOPT_TIMEOUT => 0, - CURLOPT_FOLLOWLOCATION => true, - CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, - CURLOPT_CUSTOMREQUEST => "POST", - CURLOPT_SSLCERT => $this->pem, - CURLOPT_SSLKEY => $this->key, - CURLOPT_SSLKEYPASSWD => $this->pass, - CURLOPT_POSTFIELDS =>json_encode($this->params, JSON_PRETTY_PRINT), - CURLOPT_HTTPHEADER => array( - "Content-Type: application/json", - "Authorization: Bearer ".$this->response->access_token, - "Accept: application/json", - "client_id: ".$this->clientId - ), - )); - - /** Envia a requisição */ - $this->response = json_decode(curl_exec($this->ch)); - - /** Carrea as informações da requisição */ - $this->info = curl_getinfo($this->ch); - - /** Caso a requisição não tenha sido positiva, informo o erro */ - if($this->response->resultado[0]->status->codigo != 200){ - - /** Adição de elemento de erro*/ - array_push($this->errors, 'Status :: ('.$this->response->resultado[0]->status->codigo.') '.$this->response->resultado[0]->status->mensagem); - - }else{ - - /** Gera o pdf do boleto */ - $this->fp = fopen($this->dir.$this->nameFile, 'w+'); - fwrite($this->fp, base64_decode($this->response->resultado[0]->boleto->pdfBoleto)); - fclose($this->fp); - - /** Verifica se o arquivo foi gerado com sucesso */ - if(!is_file($this->dir.$this->nameFile)){ - - /** Adição de elemento de erro*/ - array_push($this->errors, 'Erro :: Não foi possível gerar o PDF do boleto'); - } - - } - - /** Fecha a requisição anteriormente aberta */ - curl_close($this->ch); - - break; - - case 'cobranca_boletos_listar_por_pagador' : # Serviço para listagem de boletos por pagador - - $this->ch = curl_init(); - curl_setopt_array($this->ch, array( - CURLOPT_URL => $this->urlApiCobrancaBancaria.'boletos/pagadores/'.$this->params[0], - CURLOPT_RETURNTRANSFER => true, - CURLOPT_ENCODING => '', - CURLOPT_MAXREDIRS => 10, - CURLOPT_TIMEOUT => 0, - CURLOPT_FOLLOWLOCATION => true, - CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, - CURLOPT_SSLCERT => $this->pem, - CURLOPT_SSLKEY => $this->key, - CURLOPT_SSLKEYPASSWD => $this->pass, - CURLOPT_HTTPHEADER => array( - "Content-Type: application/json", - "Authorization: Bearer ".$this->response->access_token, - "Accept: application/json", - "client_id: ".$this->clientId - ), - )); - - /** Envia a requisição */ - $this->response = json_decode(curl_exec($this->ch)); - - /** Carrea as informações da requisição */ - $this->info = curl_getinfo($this->ch); - - /** Verifica o status do retorno */ - if($this->info['http_code'] != 200){ - - /** Adição de elemento de erro*/ - array_push($this->errors, 'Status :: ('.$this->info['http_code'].') Nenhum boleto localizado para ser listado'); - } - - break; - - case 'cobranca_boletos_consultar_boleto' : # Serviço para consultar boleto + case 'consultar_boleto' : # Serviço para consultar boleto $this->ch = curl_init(); curl_setopt_array($this->ch, array( - CURLOPT_URL => $this->urlApiCobrancaBancaria.'boletos'.$this->params[0], + CURLOPT_URL => $this->urlApiCobrancaBancaria.'boletos'.$this->params, CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, @@ -338,7 +273,16 @@ class ApiSicoob } - } + } + + /** Função para carregar as informações */ + private function LoadConfig() + { + + /** Carrego o arquivo de configuração */ + return (object)json_decode(file_get_contents('config/config.json')); + + } public function __destruct() { diff --git a/vendor/view/financial_movements/financial_movements_ticket_consult.php b/vendor/view/financial_movements/financial_movements_ticket_consult.php index dfb6e21..a70de5a 100644 --- a/vendor/view/financial_movements/financial_movements_ticket_consult.php +++ b/vendor/view/financial_movements/financial_movements_ticket_consult.php @@ -29,77 +29,99 @@ try{ /** Carrega os dados da Sicoob */ $sicoobResponse = json_decode($FinancialMovementsResult->sicoob_response); - /** Parametros a serem enviados */ - $params = '?numeroContrato='.$Main->LoadConfigPublic()->app->ticket->numero_contrato; - $params .= '&modalidade=1'; - $params .= '&linhaDigitavel='.$sicoobResponse->resultado[0]->boleto->linhaDigitavel; - $params .= '&codigoBarras='.$sicoobResponse->resultado[0]->boleto->codigoBarras; - $params .= '&nossoNumero='.$sicoobResponse->resultado[0]->boleto->nossoNumero; + // Verifica se existe o objeto "resultado" + if (isset($sicoobResponse['resultado'])) { - /** REQUISIÇÃO RESPONSÁVEL EM GERAR O TOKEN */ - $ApiSicoob->accessToken(); + // Carrega apenas os resultados + $resultado = $sicoobResponse['resultado']; - /** Verifica se foi retornado erros */ - if(empty($ApiSicoob->getErrors())){ - - /** Envia a solicitação */ - $ApiSicoob->sendService('cobranca_boletos_consultar_boleto', [$params], NULL); - - - /** Verifica possíveis erros */ - if(empty($ApiSicoob->getErrors())){ + // Pega os campos (se existirem) + $numeroCliente = $resultado['numeroCliente'] ?? null; + $codigoModalidade = $resultado['codigoModalidade'] ?? null; + $linhaDigitavel = $resultado['linhaDigitavel'] ?? null; + $codigoBarras = $resultado['codigoBarras'] ?? null; + $nossoNumero = $resultado['nossoNumero'] ?? null; + $numeroContratoCobranca = $resultado['numeroContratoCobranca'] ?? null; + + /** Prepara os paramentros a serem enviados */ + $params = '?'; + $params .= 'numeroCliente='.$numeroCliente; + $params .= '&codigoModalidade='.$codigoModalidade; + $params .= '&linhaDigitavel='.$linhaDigitavel; + $params .= '&codigoBarras='.$codigoBarras; + $params .= '&nossoNumero='.$nossoNumero; + $params .= '&numeroContratoCobranca='.$numeroContratoCobranca; + + /** REQUISIÇÃO RESPONSÁVEL EM GERAR O TOKEN */ + $ApiSicoob->accessToken(); + + /** Verifica se foi retornado erros */ + if(empty($ApiSicoob->getErrors())){ + + /** Envia a solicitação */ + $ApiSicoob->sendService('consultar_boleto', $params, NULL); + + + /** Verifica possíveis erros */ + if(empty($ApiSicoob->getErrors())){ - /** Carrega o resultado da consulta */ - $response = $ApiSicoob->getResponseObject(); + /** Carrega o resultado da consulta */ + $response = $ApiSicoob->getResponseObject(); - // print_r($response); - // exit; + // print_r($response); + // exit; - /** Verifica se existe historico a ser listado */ - if(count($response->resultado->listaHistorico) > 0){ + /** Verifica se existe historico a ser listado */ + if(count($response->resultado->listaHistorico) > 0){ - $list = $FinancialMovementsResult->fantasy_name; - $list .= ''; + } + + /** Informa o resultado positivo **/ + $result = [ + + 'cod' => 200, + 'title' => $FinancialMovementsResult->description, + 'type' => '', + 'message' => $list, + + ]; + + /** Envio **/ + echo json_encode($result); + + /** Paro o procedimento **/ + exit; + + + } else { + + /** Retorna a mensagem com seu respectivo erro **/ + throw new InvalidArgumentException($ApiSicoob->getErrors(), 0); } - /** Informa o resultado positivo **/ - $result = [ - - 'cod' => 200, - 'title' => $FinancialMovementsResult->description, - 'type' => '', - 'message' => $list, - - ]; - - /** Envio **/ - echo json_encode($result); - - /** Paro o procedimento **/ - exit; - - } else { /** Retorna a mensagem com seu respectivo erro **/ - throw new InvalidArgumentException($ApiSicoob->getErrors(), 0); - } + throw new InvalidArgumentException($ApiSicoobValidate->getErrors(), 0); + } } else { - + /** Retorna a mensagem com seu respectivo erro **/ - throw new InvalidArgumentException($ApiSicoobValidate->getErrors(), 0); - } + throw new InvalidArgumentException('Não há dados de boletos a serem enviados', 0); + } } else {