Skip to content

Commit

Permalink
Merge pull request #1016 from robmachado/master
Browse files Browse the repository at this point in the history
Issue #1015 Evento de Insucesso na Entrega
  • Loading branch information
robmachado committed Jan 26, 2024
2 parents a423a32 + 7b15fd8 commit 34f4145
Show file tree
Hide file tree
Showing 15 changed files with 966 additions and 1 deletion.
2 changes: 2 additions & 0 deletions examples/5.0testSefazStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@

$soap = new \NFePHP\NFe\Tests\Common\SoapFake();
$soap->disableCertValidation(true);
$soap->protocol(6);
$soap->httpVersion('1.1');

//intancia a classe tools
$tools = new Tools($configJson, Certificate::readPfx($content, 'associacao'));
Expand Down
75 changes: 75 additions & 0 deletions examples/EventoInsucessoEntrega.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php

error_reporting(E_ALL);
ini_set('display_errors', 'On');
require_once '../bootstrap.php';

use NFePHP\NFe\Tools;
use NFePHP\Common\Certificate;
use NFePHP\Common\Soap\SoapFake;

//tanto o config.json como o certificado.pfx podem estar
//armazenados em uma base de dados, então não é necessário
///trabalhar com arquivos, este script abaixo serve apenas como
//exemplo durante a fase de desenvolvimento e testes.
$arr = [
"atualizacao" => "2016-11-03 18:01:21",
"tpAmb" => 2,
"razaosocial" => "SUA RAZAO SOCIAL LTDA",
"cnpj" => "99999999999999",
"siglaUF" => "SP",
"schemes" => "PL_009_V4",
"versao" => '4.00',
"tokenIBPT" => "AAAAAAA",
"CSC" => "GPB0JBWLUR6HWFTVEAS6RJ69GPCROFPBBB8G",
"CSCid" => "000001",
"proxyConf" => [
"proxyIp" => "",
"proxyPort" => "",
"proxyUser" => "",
"proxyPass" => ""
]
];
//monta o config.json
$configJson = json_encode($arr);

//carrega o conteudo do certificado.
$content = file_get_contents('fixtures/expired_certificate.pfx');

try {
//intancia a classe tools
$tools = new Tools($configJson, Certificate::readPfx($content, 'associacao'));
//seta o modelo para 55
$tools->model('55');

$soap = new SoapFake();
$soap->disableCertValidation();
$tools->loadSoapClass($soap);

$std = new \stdClass();
$std->cancelar = true; //não é um evento de Cancelamento de Insucesso de Entrega
$std->protocolo = '123456789012345';
$std->chNFe = '35200714403043000122550010000056591412970518'; //chave de 44 digitos da nota do fornecedor
$std->verAplic = '1.2.3'; //versão da aplicação que está gerando o evento
$std->nSeqEvento = 1; //numero sequencial do evento, incrementar ao incluir outros ou remover
$std->data_tentativa = '2024-05-30T13:22:50-03:00'; //data da ultima tentativa de entrega
$std->tentativas = 3;
$std->tipo_motivo = 4;
//Motivo do insucesso:
//1 – Recebedor não encontrado
//2 – Recusa do recebedor
//3 – Endereço inexistente
//4 – Outros (exige informar justificativa)
$std->justificativa = 'Local sem acesso devido a deslizamento de terra';
$std->latitude = "-23.622600";
$std->longitude = "-46.424870";
$std->imagem = 'kakakakakakakakak'; // aqui pode ser colocada uma imagem ou uma string que fará parte do hash

$response = $tools->sefazInsucessoEntrega($std);

$fake = NFePHP\NFe\Common\FakePretty::prettyPrint($response);
echo $fake;

} catch (\Exception $e) {
echo $e->getMessage();
}
9 changes: 9 additions & 0 deletions schemes/PL_009_V4/EventoCancInsucessoNFe_v1.00.xsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://www.portalfiscal.inf.br/nfe" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" targetNamespace="http://www.portalfiscal.inf.br/nfe" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:include schemaLocation="leiauteEventoCancInsucessoNFe_v1.00.xsd"/>
<xs:element name="evento" type="TEvento">
<xs:annotation>
<xs:documentation>Schema XML de validação do evento de Cancelamento do Comprovante de Entrega da NFe</xs:documentation>
</xs:annotation>
</xs:element>
</xs:schema>
9 changes: 9 additions & 0 deletions schemes/PL_009_V4/EventoInsucessoNFe_v1.00.xsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://www.portalfiscal.inf.br/nfe" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" targetNamespace="http://www.portalfiscal.inf.br/nfe" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:include schemaLocation="leiauteEventoInsucessoNFe_v1.00.xsd"/>
<xs:element name="evento" type="TEvento">
<xs:annotation>
<xs:documentation>Schema XML de validação do evento de Insucesso na entrega da NF-e</xs:documentation>
</xs:annotation>
</xs:element>
</xs:schema>
107 changes: 107 additions & 0 deletions schemes/PL_009_V4/e110192_v1.00.xsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- edited with XMLSpy v2008 (http://www.altova.com) by sas-softwares@procergs.rs.gov.br (PROCERGS) -->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://www.portalfiscal.inf.br/nfe" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" targetNamespace="http://www.portalfiscal.inf.br/nfe" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:include schemaLocation="tiposBasico_v1.03.xsd"/>
<xs:element name="detEvento">
<xs:annotation>
<xs:documentation>Schema XML de validação do evento de Comprovante de Entrega da NF-e</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:element name="descEvento">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="Insucesso na Entrega da NF-e"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="cOrgaoAutor" type="TCOrgaoIBGE"/>
<xs:element name="verAplic" type="TVerAplic">
<xs:annotation>
<xs:documentation>Versão do Aplicativo do Autor do Evento</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="dhTentativaEntrega" type="TDateTimeUTC">
<xs:annotation>
<xs:documentation>Data e hora do final da tentativa entrega. Formato AAAA-MMDDThh:mm:ssTZD
</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="nTentativa" minOccurs="0">
<xs:simpleType>
<xs:annotation>
<xs:documentation>Número da tentativa de entrega que não teve sucesso</xs:documentation>
</xs:annotation>
<xs:restriction base="xs:string">
<xs:pattern value="[0-9]{1,3}"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="tpMotivo">
<xs:simpleType>
<xs:annotation>
<xs:documentation>Motivo do insucesso - 1 – Recebedor não encontrado
2 – Recusa do recebedor
3 – Endereço inexistente
4 – Outros (exige informar justificativa) </xs:documentation>
</xs:annotation>
<xs:restriction base="xs:string">
<xs:whiteSpace value="preserve"/>
<xs:enumeration value="1"/>
<xs:enumeration value="2"/>
<xs:enumeration value="3"/>
<xs:enumeration value="4"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="xJustMotivo" minOccurs="0">
<xs:annotation>
<xs:documentation>Justificativa do motivo do insucesso. Informar apenas para tpMotivo=4 </xs:documentation>
</xs:annotation>
<xs:simpleType>
<xs:restriction base="TString">
<xs:maxLength value="250"/>
<xs:minLength value="25"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="latGPS" type="TLatitude" minOccurs="0">
<xs:annotation>
<xs:documentation>Latitude do ponto de entrega</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="longGPS" type="TLongitude" minOccurs="0">
<xs:annotation>
<xs:documentation>Longitude do ponto de entrega</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="hashTentativaEntrega">
<xs:annotation>
<xs:documentation>Hash (SHA1) no formato Base64 resultante da concatenação: Chave de acesso da NFe + Base64 da imagem capturada da entrega (Exemplo: imagem capturada da assinatura eletrônica, digital do recebedor, foto, etc)</xs:documentation>
<xs:documentation>O hashCSRT é o resultado das funções SHA-1 e base64 do token CSRT fornecido pelo fisco + chave de acesso do DF-e. (Implementação em futura NT)
Observação: 28 caracteres são representados no schema como 20 bytes do tipo base64Binary</xs:documentation>
</xs:annotation>
<xs:simpleType>
<xs:restriction base="xs:base64Binary">
<xs:length value="20"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="dhHashTentativaEntrega" type="TDateTimeUTC" minOccurs="0">
<xs:annotation>
<xs:documentation>Data e hora da geração do hash da tentativa de entrega. Formato AAAA-MMDDThh:mm:ssTZD.
</xs:documentation>
</xs:annotation>
</xs:element>
</xs:sequence>
<xs:attribute name="versao" use="required">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:whiteSpace value="preserve"/>
<xs:enumeration value="1.00"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:complexType>
</xs:element>
</xs:schema>
40 changes: 40 additions & 0 deletions schemes/PL_009_V4/e110193_v1.00.xsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- edited with XMLSpy v2008 (http://www.altova.com) by sas-softwares@procergs.rs.gov.br (PROCERGS) -->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://www.portalfiscal.inf.br/nfe" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" targetNamespace="http://www.portalfiscal.inf.br/nfe" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:include schemaLocation="tiposBasico_v1.03.xsd"/>
<xs:element name="detEvento">
<xs:annotation>
<xs:documentation>Schema XML de validação do evento de Cancelamento do Comprovante de Entrega da NF-e</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:element name="descEvento">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="Cancelamento Insucesso na Entrega da NF-e"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="cOrgaoAutor" type="TCOrgaoIBGE"/>
<xs:element name="verAplic" type="TVerAplic">
<xs:annotation>
<xs:documentation>Versão do Aplicativo do Autor do Evento</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="nProtEvento" type="TProt">
<xs:annotation>
<xs:documentation>Número do Protocolo de Autorização do Evento da NF-e a que se refere este cancelamento.</xs:documentation>
</xs:annotation>
</xs:element>
</xs:sequence>
<xs:attribute name="versao" use="required">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:whiteSpace value="preserve"/>
<xs:enumeration value="1.00"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:complexType>
</xs:element>
</xs:schema>
10 changes: 10 additions & 0 deletions schemes/PL_009_V4/envEventoCancInsucessoNFe_v1.00.xsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- edited with XMLSpy v2008 (http://www.altova.com) by sas-softwares@procergs.rs.gov.br (PROCERGS) -->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://www.portalfiscal.inf.br/nfe" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" targetNamespace="http://www.portalfiscal.inf.br/nfe" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:include schemaLocation="leiauteEventoCancInsucessoNFe_v1.00.xsd"/>
<xs:element name="envEvento" type="TEnvEvento">
<xs:annotation>
<xs:documentation>Schema XML de validação do lote de envio do evento de Cancelamento de Insucesso na Entrega da NF-e</xs:documentation>
</xs:annotation>
</xs:element>
</xs:schema>
10 changes: 10 additions & 0 deletions schemes/PL_009_V4/envEventoInsucessoNFe_v1.00.xsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- edited with XMLSpy v2008 (http://www.altova.com) by sas-softwares@procergs.rs.gov.br (PROCERGS) -->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://www.portalfiscal.inf.br/nfe" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" targetNamespace="http://www.portalfiscal.inf.br/nfe" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:include schemaLocation="leiauteEventoInsucessoNFe_v1.00.xsd"/>
<xs:element name="envEvento" type="TEnvEvento">
<xs:annotation>
<xs:documentation>Schema XML de validação do lote de envio do evento de Insucesso na Entrega da NF-e</xs:documentation>
</xs:annotation>
</xs:element>
</xs:schema>
Loading

0 comments on commit 34f4145

Please sign in to comment.