Пример #1
0
        private static async Task ManifestarCienciaOperacao()
        {
            try
            {
                Console.WriteLine("Informe a chave da NFe para download:");
                string chave = Console.ReadLine();

                using (var _certificado = CertificadoDigital.ObterCertificado(_configuracoes.CfgServico.Certificado))
                    using (var servicoNFe = new ServicosNFe(_configuracoes.CfgServico, _certificado))
                    {
                        var retornoManifestacao = servicoNFe.RecepcaoEventoManifestacaoDestinatario(idlote: 1,
                                                                                                    sequenciaEvento: 1,
                                                                                                    chavesNFe: new string[] { chave },
                                                                                                    nFeTipoEventoManifestacaoDestinatario: NFeTipoEvento.TeMdCienciaDaOperacao,
                                                                                                    cpfcnpj: _configuracoes.Emitente.CNPJ,
                                                                                                    justificativa: null);

                        Console.WriteLine($"Retorno da manifestação: {retornoManifestacao.RetornoStr}");
                    }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Пример #2
0
        private static async Task DownloadXml()
        {
            try
            {
                Console.WriteLine("Informe a chave da NFe para download:");
                string chave = Console.ReadLine();

                Console.WriteLine("Deseja manifestar a NFe? (S/N)");
                bool manifestar = string.Equals(Console.ReadLine().Trim().ToLower(), "s");


                using (var _certificado = CertificadoDigital.ObterCertificado(_configuracoes.CfgServico.Certificado))
                    using (var servicoNFe = new ServicosNFe(_configuracoes.CfgServico, _certificado))
                    {
                        if (manifestar)
                        {
                            try
                            {
                                var retornoManifestacao = servicoNFe.RecepcaoEventoManifestacaoDestinatario(idlote: 1,
                                                                                                            sequenciaEvento: 1,
                                                                                                            chavesNFe: new string[] { chave },
                                                                                                            nFeTipoEventoManifestacaoDestinatario: NFeTipoEvento.TeMdCienciaDaOperacao,
                                                                                                            cpfcnpj: _configuracoes.Emitente.CNPJ,
                                                                                                            justificativa: null);

                                Console.WriteLine($"Retorno da manifestação: {retornoManifestacao.RetornoStr}");
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine($"Manifestação: {ex.Message}");
                            }
                        }

                        var retornoNFeDistDFe = servicoNFe.NfeDistDFeInteresse(ufAutor: _configuracoes.EnderecoEmitente.UF.ToString(), documento: _configuracoes.Emitente.CNPJ, chNFE: chave);
                        if (retornoNFeDistDFe.Retorno.loteDistDFeInt == null)
                        {
                            await Task.Delay(2000); //https://github.com/ZeusAutomacao/DFe.NET/issues/568#issuecomment-339862458

                            retornoNFeDistDFe = servicoNFe.NfeDistDFeInteresse(ufAutor: _configuracoes.EnderecoEmitente.UF.ToString(), documento: _configuracoes.Emitente.CNPJ, chNFE: chave);

                            if (retornoNFeDistDFe.Retorno.loteDistDFeInt == null)
                            {
                                throw new Exception(retornoNFeDistDFe.Retorno.xMotivo);
                            }
                        }

                        if ((retornoNFeDistDFe.Retorno.loteDistDFeInt.Count()) > 0)
                        {
                            var    xmlBytes = retornoNFeDistDFe.Retorno.loteDistDFeInt[0].XmlNfe;
                            string xmlStr   = Compressao.Unzip(xmlBytes);

                            Console.WriteLine($"Xml: {xmlStr}");
                        }
                    }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Пример #3
0
        public bool ManifestDfe(int idLote, int seqEvent, string accessKey, Company company,
                                int eventCodeManifest = 0, string reason = null)
        {
            TipoEventoManifestacaoDestinatario eventCode;

            switch (eventCodeManifest)
            {
            case 0:
                eventCode = TipoEventoManifestacaoDestinatario.TeMdCienciaDaEmissao;
                break;

            case 1:
                eventCode = TipoEventoManifestacaoDestinatario.TeMdConfirmacaoDaOperacao;
                break;

            case 2:
                eventCode = TipoEventoManifestacaoDestinatario.TeMdDesconhecimentoDaOperacao;
                break;

            case 3:
                eventCode = TipoEventoManifestacaoDestinatario.TeMdOperacaoNaoRealizada;
                break;

            default:
                throw new Exception("Código de Manifestação não identificado!");
            }

            var configCertificado = GetCertificateForConfig(company.CertificateSerialNumber, company.CertificatePassword);

            ConfiguraServico(GetEstateForConfig(company.Estate), ModeloDocumento.NFe,
                             NFe.Classes.Informacoes.Identificacao.Tipos.TipoAmbiente.taProducao, TipoEmissao.teNormal, 10000,
                             SecurityProtocolType.Ssl3, configCertificado);

            using (var servicoNFe = new ServicosNFe(_configServico))
            {
                var retornoNFeDistDFe = servicoNFe.RecepcaoEventoManifestacaoDestinatario(idLote, seqEvent, accessKey,
                                                                                          eventCode, company.Cnpj, reason);

                if (retornoNFeDistDFe.Retorno.cStat == 128)
                {
                    return(true);
                }
            }

            return(false);
        }