Exemplo n.º 1
0
 /**
  * Retorna o XML protocolado da NFe.
  *
  * @return string
  */
 public function getXML()
 {
     if ($this->isError()) {
         return '';
     }
     $versao = $this->retorno->getElementsByTagName('retEnviNFe')->item(0)->getAttribute('versao');
     $urlPortal = $this->retorno->getElementsByTagName('retEnviNFe')->item(0)->getAttribute('xmlns');
     // Prot
     $prot = $this->retorno->getElementsByTagName('protNFe')->item(0)->C14N();
     $prot = preg_replace('/\\s+/', ' ', preg_replace('%xmlns:[a-z]+="[a-zA-Z0-9:/.-]+"%', '', $prot));
     $params = [];
     $params['{{portal}}'] = $urlPortal;
     $params['{{versao}}'] = $versao;
     $params['{{xml}}'] = $this->xml->C14N();
     $params['{{prot}}'] = $prot;
     $xml = file_get_contents(__DIR__ . '/../Templates/nfeAutRetorno.xml');
     $xml = strtr($xml, $params);
     return $xml;
 }
Exemplo n.º 2
0
 /**
  * Retorna o codigo de barras em formato image inline.
  *
  * @param XML $nfe
  * @return string
  */
 protected function getBarCode(XML $nfe)
 {
     $generator = new \Picqer\Barcode\BarcodeGeneratorPNG();
     $buffer = $generator->getBarcode($nfe->getChNFeTag('infEvento', 'ID')->value(), $generator::TYPE_CODE_128_C, 1, 40);
     return 'data:image/png;base64,' . base64_encode($buffer);
 }
Exemplo n.º 3
0
Arquivo: NFe.php Projeto: phpnfe/nfe
 /**
  * Fazer requisição SOAP.
  *
  * @param MethodSefaz $method
  * @param $header
  * @param $body
  * @return DOMDocument
  * @throws \Exception
  */
 protected function soap(MethodSefaz $method, $header, $body)
 {
     $dir = sys_get_temp_dir() . DIRECTORY_SEPARATOR . uniqid();
     try {
         // Criar diretorio temporario.
         $this->file->makeDirectory($dir);
         // Salvar certificados na pasta temp criada.
         $this->certificado->salvaChave($dir);
         $client = new Soap\CurlSoap($dir . '/pri.key', $dir . '/pub.key', $dir . '/cert.key');
         $resp = $client->send($method->url, $method->getNamespace(), $header, $body, $method->method);
         $xml = XML::createByXml($resp);
         $this->file->deleteDirectory($dir);
         return $xml;
     } catch (\Exception $e) {
         $this->file->deleteDirectory($dir);
         throw $e;
     }
 }
Exemplo n.º 4
0
 /**
  * Retorna o primeiro child.
  *
  * @return XML
  */
 public function first()
 {
     return XML::createByXml($this->elem->firstChild->C14N());
 }