public async Task <object> AssinarDocumentoAsync(dynamic parametros) { var result = new AssinaturaResponse(); if (parametros == null) { result.Notifications.Add("Configuração é requerida."); return(Task.FromResult <object>(result.ToDynamic())); } var source = (object)parametros; var arg = new AssinaturaRequest { UrlDocument = source.GetValue <string>("UrlDocument"), SerialNumber = source.GetValue <string>("SerialNumber"), Password = source.GetValue <string>("Password"), ActionType = (EnumTipoAcao)source.GetValue <int>("ActionType", 0), CertificateType = (EnumTipoCertificado)source.GetValue <int>("CertificateType", 0) }; var servico = source.GetValue <int?>("Servico", null); if (servico != null) { arg.Servico = (ServicoNFe)servico; } result = await AssinarDocumentoAsync(arg); return(Task.FromResult <object>(result.ToDynamic())); }
internal async Task <AssinaturaResponse> AssinarDocumentoAsync(AssinaturaRequest request) { try { var response = ValidarRequest(request); if (!response.Success) { return(response); } var document = await _util.DownloadDocumentAsync(request.UrlDocument); //var documentValido = ValidarDocumento(document, request.SerialNumber); //if (documentValido.Item1) //{ document = Signature(document, request); return(new AssinaturaResponse { Data = document }); //} //response.Notifications.Add(documentValido.Item2); //return response; } catch (Exception ex) { var response = new AssinaturaResponse(); response.Notifications.Add("Erro ao assinar xml."); response.Details.Add($"Erro: {ex.ToString()}"); return(response); } }
internal string Signature(string xmlNFe, AssinaturaRequest request) { if (request.ActionType == EnumTipoAcao.AssinaturaDocumento) { if (request.Servico == ServicoNFe.NFeAutorizacao) { return(AssinarXmlTransmissao(xmlNFe, request.SerialNumber, request.Password, request.CertificateType)); } else { if (request.Servico == ServicoNFe.RecepcaoEventoCancelmento || request.Servico == ServicoNFe.RecepcaoEventoCartaCorrecao) { return(AssinarXml <envEvento>(xmlNFe, request.SerialNumber, request.Password, request.CertificateType)); } else { return(AssinarXml <inutNFe>(xmlNFe, request.SerialNumber, request.Password, request.CertificateType)); } } } return(default);
internal static AssinaturaResponse ValidarRequest(AssinaturaRequest request) { var response = new AssinaturaResponse(); if (request == null) { response.Notifications.Add("Parametros não informado."); return(response); } if (string.IsNullOrEmpty(request?.UrlDocument)) { response.Notifications.Add("Documento é requerido."); return(response); } if (request?.CertificateType == EnumTipoCertificado.Nenhum) { response.Notifications.Add("Certificado digital é requerido."); return(response); } if (string.IsNullOrEmpty(request?.SerialNumber) || (request?.CertificateType == EnumTipoCertificado.A3 && string.IsNullOrEmpty(request?.Password))) { response.Notifications.Add($"{(string.IsNullOrEmpty(request?.SerialNumber) ? "Serial Number" : "Password")} do Certificado digital é requerido."); return(response); } if (request?.ActionType == null || request?.ActionType == EnumTipoAcao.Nenhum) { response.Notifications.Add("Tipo da ação é requerida."); return(response); } return(response); }