public async Task <retEnvEvento> ManifestarAsync(ChaveFiscal chaveNFe, eTipoEventoNFe tipoEvento, string justificativa = null) { if (tipoEvento != eTipoEventoNFe.CienciaOperacao && tipoEvento != eTipoEventoNFe.ConfirmacaoOperacao && tipoEvento != eTipoEventoNFe.DesconhecimentoOperacao && tipoEvento != eTipoEventoNFe.OperacaoNaoRealizada) { throw new Exception("Evento não permitido nesse serviço"); } var xmlEvento = GerarXmlEvento(chaveNFe.Chave, tipoEvento, justificativa); var arqEnv = Path.Combine("Logs", Arquivo.MontarNomeArquivo("ped-eve.xml", config)); await storage.SaveAsync(arqEnv, xmlEvento); await storage.SaveAsync($"{DateTime.Now.Ticks}-ped-eve.xml", xmlEvento); Schemas.ValidarSchema(eTipoServico.ManifestacaoDestinatario, xmlEvento, config); var envelope = SoapEnvelopeFabrica.FabricarEnvelope(eTipoServico.ManifestacaoDestinatario, xmlEvento); var sefazUrl = FabricarUrl.ObterUrl(eTipoServico.ManifestacaoDestinatario, config.TipoAmbiente, eModeloDocumento.NFe, eUF.AN); var xmlRetorno = await transmitir.TransmitirAsync(sefazUrl, envelope); var xmlRetLimpo = Soap.LimparEnvelope(xmlRetorno, "retEnvEvento").OuterXml; var arqRet = Path.Combine("Logs", Arquivo.MontarNomeArquivo("ret-eve.xml", config)); await storage.SaveAsync(arqRet, xmlRetLimpo); var retEnvEvento = XmlUtils.XmlStringParaClasse <retEnvEvento>(xmlRetLimpo); return(retEnvEvento); }
private string GerarXmlEvento(string chaveAcesso, eTipoEventoNFe tipoEvento, string justificativa = null) { if (tipoEvento == eTipoEventoNFe.OperacaoNaoRealizada && justificativa == null) { throw new ArgumentNullException("Justificativa deve ser informada"); } if (tipoEvento != eTipoEventoNFe.OperacaoNaoRealizada) { justificativa = null; } var infEvento = new infEventoEnv { chNFe = chaveAcesso, CNPJ = config.Emitente.CNPJ, CPF = config.Emitente.CPF, cOrgao = eUF.AN, dhEvento = DateTime.Now, nSeqEvento = 1, tpAmb = config.TipoAmbiente, tpEvento = tipoEvento, verEvento = config.VersaoManifestacaoDestinatario.Descricao(), Id = "ID" + ((int)tipoEvento) + chaveAcesso + nSeqEvento.ToString().PadLeft(2, '0'), detEvento = new detEvento() { versao = config.VersaoManifestacaoDestinatario.Descricao(), descEvento = tipoEvento.Descricao().RemoverAcentos() } }; var evento = new evento { versao = config.VersaoManifestacaoDestinatario.Descricao(), infEvento = infEvento }; evento.Assinar(ObterCertificado.Obter(config.ConfigCertificado), config.ConfigCertificado.SignatureMethodSignedXml, config.ConfigCertificado.DigestMethodReference); var pedEvento = new envEvento { versao = config.VersaoManifestacaoDestinatario.Descricao(), idLote = 1, evento = new List <evento> { evento } }; var xmlEvento = XmlUtils.ClasseParaXmlString <envEvento>(pedEvento); return(xmlEvento); }