Skip to content

Commit

Permalink
Incluido assinatura do QRCode quando for contingencia EPEC ou FS-DA e…
Browse files Browse the repository at this point in the history
… implementado essas duas formas de contingencia.
  • Loading branch information
icompsoftcleiton committed Jun 28, 2023
1 parent e7334e6 commit d809da2
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/Common/Tools.php
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,7 @@ protected function addQRCode(DOMDocument $dom)

$signed = QRCode::putQRTag(
$dom,
$this->certificate,
$std->QRCode->url
);

Expand Down
6 changes: 6 additions & 0 deletions src/Factories/Contingency.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
17 changes: 12 additions & 5 deletions src/Factories/QRCode.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,33 +16,40 @@
*/

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) {
$cte = $dom->getElementsByTagName('CTeOS')->item(0);
} 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));
Expand Down

0 comments on commit d809da2

Please sign in to comment.