/** * 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; }
/** * 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); }
/** * 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; } }
/** * Retorna o primeiro child. * * @return XML */ public function first() { return XML::createByXml($this->elem->firstChild->C14N()); }