diff --git a/src/Common/Tools.php b/src/Common/Tools.php index b89c38e..39969c3 100644 --- a/src/Common/Tools.php +++ b/src/Common/Tools.php @@ -655,6 +655,7 @@ protected function addQRCode(DOMDocument $dom) $signed = QRCode::putQRTag( $dom, + $this->certificate, $std->QRCode->url ); diff --git a/src/Factories/Contingency.php b/src/Factories/Contingency.php index 4f728ef..876a019 100644 --- a/src/Factories/Contingency.php +++ b/src/Factories/Contingency.php @@ -159,6 +159,12 @@ private function configBuild($timestamp, $motive, $type) case 'SVSP': $tpEmis = 8; break; + case 'EPEC': + $tpEmis = 4; + break; + case 'FA-DA': + $tpEmis = 5; + break; default: if ($type == '') { $tpEmis = 1; diff --git a/src/Factories/QRCode.php b/src/Factories/QRCode.php index bffe3b3..937a9a4 100644 --- a/src/Factories/QRCode.php +++ b/src/Factories/QRCode.php @@ -16,20 +16,23 @@ */ use DOMDocument; -use NFePHP\CTe\Exception\DocumentsException; +use NFePHP\Common\Certificate; class QRCode { /** * putQRTag * @param DOMDocument $dom CTe + * @param Certificate $certificate * @param string $url * @return string */ public static function putQRTag( \DOMDocument $dom, - $url = '' - ) { + $certificate, + $url = '' + ) + { $mod = $dom->getElementsByTagName('mod')->item(0)->nodeValue; # se for CTe-OS, pega a tag raiz correspondente if ($mod == 67) { @@ -37,12 +40,16 @@ public static function putQRTag( } else { $cte = $dom->getElementsByTagName('CTe')->item(0); } - $infCte = $dom->getElementsByTagName('infCte')->item(0); $ide = $dom->getElementsByTagName('ide')->item(0); $chCTe = preg_replace('/[^0-9]/', '', $infCte->getAttribute("Id")); $tpAmb = $ide->getElementsByTagName('tpAmb')->item(0)->nodeValue; - $urlQRCode = "$url?chCTe=$chCTe&tpAmb=$tpAmb"; + $tpEmis = $ide->getElementsByTagName('tpEmis')->item(0)->nodeValue; + $sign = ''; + if (in_array($tpEmis, [4, 5])) { + $sign = "&sign=" . base64_encode($certificate->sign($chCTe)); + } + $urlQRCode = "$url?chCTe=$chCTe&tpAmb=$tpAmb{$sign}"; $infCTeSupl = $dom->createElement("infCTeSupl"); $qrCode = $infCTeSupl->appendChild($dom->createElement('qrCodCTe')); $qrCode->appendChild($dom->createCDATASection($urlQRCode));