NFePHP\NFe\ToolsNFe::sefazConsultaRecibo PHP Метод

sefazConsultaRecibo() публичный Метод

sefazConsultaRecibo Consulta a situação de um Lote de NFe enviadas pelo recibo desse envio
public sefazConsultaRecibo ( string $recibo = '', string $tpAmb = '2', array &$aRetorno = [], $saveMensagens = true ) : string
$recibo string
$tpAmb string
$aRetorno array
Результат string
    public function sefazConsultaRecibo($recibo = '', $tpAmb = '2', &$aRetorno = array(), $saveMensagens = true)
    {
        if ($recibo == '') {
            $msg = "Deve ser informado um recibo.";
            throw new Exception\InvalidArgumentException($msg);
        }
        if ($tpAmb == '') {
            $tpAmb = $this->aConfig['tpAmb'];
        }
        $siglaUF = $this->aConfig['siglaUF'];
        //carrega serviço
        $servico = 'NfeRetAutorizacao';
        $this->zLoadServico('nfe', $servico, $siglaUF, $tpAmb);
        if ($this->urlService == '') {
            $msg = "A consulta de NFe não está disponível na SEFAZ {$siglaUF}!!!";
            throw new Exception\RuntimeException($msg);
        }
        $cons = "<consReciNFe xmlns=\"{$this->urlPortal}\" versao=\"{$this->urlVersion}\">" . "<tpAmb>{$tpAmb}</tpAmb>" . "<nRec>{$recibo}</nRec>" . "</consReciNFe>";
        //validar mensagem com xsd
        //if (! $this->validarXml($cons)) {
        //    $msg = 'Falha na validação. '.$this->error;
        //    throw new Exception\RuntimeException($msg);
        //}
        //montagem dos dados da mensagem SOAP
        $body = "<nfeDadosMsg xmlns=\"{$this->urlNamespace}\">{$cons}</nfeDadosMsg>";
        //envia a solicitação via SOAP
        $retorno = $this->oSoap->send($this->urlService, $this->urlNamespace, $this->urlHeader, $body, $this->urlMethod);
        $this->soapDebug = $this->oSoap->soapDebug;
        //salva mensagens
        if ($saveMensagens) {
            $lastMsg = $this->oSoap->lastMsg;
            $filename = "{$recibo}-consReciNFe.xml";
            $this->zGravaFile('nfe', $tpAmb, $filename, $lastMsg);
            $filename = "{$recibo}-retConsReciNFe.xml";
            $this->zGravaFile('nfe', $tpAmb, $filename, $retorno);
        }
        //tratar dados de retorno
        $aRetorno = ReturnNFe::readReturnSefaz($servico, $retorno);
        //podem ser retornados nenhum, um ou vários protocolos
        //caso existam protocolos protocolar as NFe e movelas-las para a
        //pasta enviadas/aprovadas/anomes
        return (string) $retorno;
    }

Usage Example

Пример #1
0
<?php

error_reporting(E_ALL);
ini_set('display_errors', 'On');
include_once '../../bootstrap.php';
use NFePHP\NFe\ToolsNFe;
$nfe = new ToolsNFe('../../config/config.json');
$nfe->setModelo('55');
$aResposta = array();
$tpAmb = '2';
$recibo = '521000011732162';
$retorno = $nfe->sefazConsultaRecibo($recibo, $tpAmb, $aResposta);
echo '<br><br><pre>';
echo htmlspecialchars($nfe->soapDebug);
echo '</pre><br><br><pre>';
print_r($aResposta);
echo "</pre><br>";