Skip to content

Commit

Permalink
Merge pull request #6 from Marcelo-k-USP/issue_6
Browse files Browse the repository at this point in the history
Retorna detalhes de eventuais erros ocorridos no webservice
  • Loading branch information
thiagogomesverissimo authored Dec 15, 2024
2 parents fdfc47e + 6a2e103 commit 43013b9
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion src/Boleto.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function gerar($data) {
$erro = $this->clienteSoap->getError();

if ($erro) {
$return['value'] = utf8_encode($erro);
$return['value'] = utf8_encode($erro) . ' - ' . $this->obterDetalheErro($this->clienteSoap->response);
} else {
$return['status'] = True;
if(!empty($request) && is_array($request)) {
Expand All @@ -65,6 +65,35 @@ public function gerar($data) {
return $return;
}

private function obterDetalheErro($rawResponse) {
$step = 0;

try {
$step = 10;
$startPos = strpos($rawResponse, '<?xml');

$step = 20;
$xmlContent = substr($rawResponse, $startPos);

$step = 30;
$xml = new \SimpleXMLElement($xmlContent);

$step = 40;
$xml->registerXPathNamespace('S', 'http://schemas.xmlsoap.org/soap/envelope/');

$step = 50;
$xml->registerXPathNamespace('ns2', 'http://ws.boleto.usp/');

$step = 60;
$faultDetail = $xml->xpath('//S:Fault/detail/ns2:WSException')[0];

$step = 70;
return (string) $faultDetail;
} catch (\Exception $e) {
return 'Não foi possível obter detalhe do erro ocorrido no WSBoleto, pois ocorreu o erro ' . $e->getMessage() . ' no passo ' . $step . ' do método obterDetalheErro do uspdev/boleto/Boleto.php. O XML recebido foi: ' . json_encode($xmlContent);
}
}

/**
* Retorna a situacao atual do boleto (emitido, pago, cancelado, etc)
*
Expand Down

0 comments on commit 43013b9

Please sign in to comment.