예제 #1
0
        /// <summary>
        /// Sign the comprobante document
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="oComprobante"></param>
        /// <returns></returns>
        public virtual SignDocumentResult <ICFDINomProvider> SignDocument(ICFDINomProvider cFDINomProvider,
                                                                          byte[] certificateCER, byte[] privateKey, string password)
        {
            //Instance CFDI Provider - Arrange
            SignDocumentResult <ICFDINomProvider> signDocumentResult = new SignDocumentResult <ICFDINomProvider>();
            var digitalSign = new Cotorra.DigitalSign.DigitalSign();

            //Certificate B64 y Certificate Number
            signDocumentResult.CertificateB64    = digitalSign.GetCerticate(certificateCER);
            signDocumentResult.CertificateNumber = digitalSign.GetCertificateNumber(certificateCER);


            //Complete CFDI
            cFDINomProvider.Certificado   = signDocumentResult.CertificateB64;
            cFDINomProvider.NoCertificado = signDocumentResult.CertificateNumber;

            //Get XML
            var xml = CreateXml(cFDINomProvider, false);

            //Get Original String
            var originalString = GetOriginalString(xml);

            //Sign Document
            signDocumentResult.SignString = digitalSign.Sign(originalString, privateKey, password);
            cFDINomProvider.Sello         = signDocumentResult.SignString;


            //CFDIProvider
            signDocumentResult.CFDI           = cFDINomProvider;
            signDocumentResult.OriginalString = originalString;

            return(signDocumentResult);
        }
예제 #2
0
        public async Task <SignDocumentResult <ICFDINomProvider> > StampDocumetAsync(
            SignDocumentResult <ICFDINomProvider> signDocumentResult, FiscalStampingVersion fiscalStampingVersion, string xml)
        {
            var stampingResult = String.Empty;

            var stampingRequest_CFDI33Nom12 = new StampingRequest_CFDI33Nom12();

            stampingRequest_CFDI33Nom12.Version         = VERSION;
            stampingRequest_CFDI33Nom12.PACDocumentType = PAC_DOCUMENT_TYPE;
            stampingRequest_CFDI33Nom12.Body            = new CFDIRequest_CFDI33Nom12()
            {
                XmlString = xml
            };
            stampingRequest_CFDI33Nom12.AdditionalInformation.Add(new AdditionalInformation_CFDI33Nom12(PAC_ATTRIBUTE_TITLE_RFC, signDocumentResult.EmployerRFC));
            stampingRequest_CFDI33Nom12.AdditionalInformation.Add(new AdditionalInformation_CFDI33Nom12(PAC_ATTRIBUTE_TITLE_PRODUCT, PAC_ATTRIBUTE_VALUE_PRODUCT));
            stampingRequest_CFDI33Nom12.AdditionalInformation.Add(new AdditionalInformation_CFDI33Nom12(PAC_ATTRIBUTE_TITLE_PRODUCT_VERSION, PAC_ATTRIBUTE_VALUE_PRODUCT_VERSION));
            stampingRequest_CFDI33Nom12.AdditionalInformation.Add(new AdditionalInformation_CFDI33Nom12(PAC_ATTRIBUTE_TITLE_PRODUCT_TYPE, PAC_ATTRIBUTE_VALUE_PRODUCT_TYPE));
            stampingRequest_CFDI33Nom12.Token = "";

            //call service async
            await ServiceHelperExtensions.CallRestServiceAsync(Format.JSON, RestMethod.POST, null,
                                                               new Uri($"{StampingUri}"), new object[] { stampingRequest_CFDI33Nom12 })
            .ContinueWith((i) =>
            {
                if (i.Result.Contains("FAIL") || i.Result.Contains("An error has occurred"))
                {
                    throw new CotorraException(90001, "90001", i.Result, null);
                }

                stampingResult = i.Result;
            });

            var stampingResult_CFDI33Nom12 = JsonSerializer.DeserializeObject <StampingResult_CFDI33Nom12>(stampingResult);

            //TFD
            var responseList = stampingResult_CFDI33Nom12.ResponseList_CFDI33Nom12.FirstOrDefault();
            var tfd          = SerializerXml.DeserializeObject <TimbreFiscalDigital>(responseList.ResponseValue);

            var complementos = (signDocumentResult.CFDI as Comprobante).Complemento.ToList();

            //complementos.Add(new ComprobanteComplemento() { Any = new XmlElement[1] { GetElement(CreateXmlNom(tfd)) } });
            (signDocumentResult.CFDI as Comprobante).Complemento = complementos.ToArray();

            signDocumentResult.UUID = Guid.Parse(tfd.UUID);

            return(signDocumentResult);
        }
        public async Task <SignDocumentResult <ICFDINomProvider> > StampDocumetAsync(
            SignDocumentResult <ICFDINomProvider> signDocumentResult, FiscalStampingVersion fiscalStampingVersion, string xml)
        {
            //call service async
            CFDIWrapperResult result = null;
            var xmlSerialized        = JsonConvert.SerializeObject(xml);

            await CallServiceAsync(Format.JSON, RestMethod.POST, _cotorraiWrapperCFDIToken,
                                   new Uri($"{_cotorraiWrapperPACUrl}/fiscal/stamping/stamp"), xmlSerialized)
            .ContinueWith((i) =>
            {
                if (i.Exception != null)
                {
                    throw i.Exception;
                }

                result = i.Result;
            });

            if (result.status == "400" && result.errors == null)
            {
                //TFD Fix string input :(
                var xmlTFD = result.detail.Remove(0, 1);
                xmlTFD = xmlTFD.Remove(xmlTFD.Length - 1, 1);
                xmlTFD = xmlTFD.Replace("\\\"", "\"");
                signDocumentResult.WithErrors = false;
                signDocumentResult.TFD        = xmlTFD;
            }
            else if (result.status == "400" && result.errors != null)
            {
                signDocumentResult.WithErrors = true;
                signDocumentResult.Details    = result.errors.FirstOrDefault();
            }
            else
            {
                signDocumentResult.WithErrors = true;
                signDocumentResult.Details    = $"Ocurrió un error no esperado en el timbrado: {result.detail}";
            }

            return(signDocumentResult);
        }
예제 #4
0
        /// <summary>
        /// Valida el xml (validación de estructura - 301)
        /// </summary>
        /// <param name="xml"></param>
        /// <returns></returns>
        public async Task <string> ValidateCFDIAsync(SignDocumentResult <ICFDINomProvider> signDocumentResult)
        {
            var           xml       = _fiscalStampingCFDIv33Nomv12.CreateXml <ICFDINomProvider>(signDocumentResult.CFDI);
            List <string> xsdsFiles = new List <string> {
                Path.Combine(_xsdPath, "catNomina.xsd"),
                Path.Combine(_xsdPath, "nomina12.xsd"),
                Path.Combine(_xsdPath, "cfdv33.xsd"),
            };

            var xdoc    = XDocument.Parse(xml);
            var schemas = new XmlSchemaSet();

            foreach (var xsdFile in xsdsFiles)
            {
                using (FileStream stream = File.OpenRead(xsdFile))
                {
                    schemas.Add(XmlSchema.Read(stream, (s, e) =>
                    {
                        var x = e.Message;
                    }));
                }
            }

            StringBuilder sb = new StringBuilder();

            try
            {
                xdoc.Validate(schemas, (s, e) =>
                {
                    sb.AppendLine($"Line : {e.Exception.LineNumber}, Message : {e.Exception.Message} ");
                });
            }
            catch (XmlSchemaValidationException ex)
            {
                sb.AppendLine(ex.Message);
            }

            return(sb.ToString());
        }
예제 #5
0
        public async Task <SignDocumentResult <ICFDINomProvider> > StampDocumetAsync(
            SignDocumentResult <ICFDINomProvider> signDocumentResult, FiscalStampingVersion fiscalStampingVersion, string xml)
        {
            //TFD
            var tfd = new Cotorra.Schema.CFDI33Nom12.TimbreFiscalDigital();

            tfd.FechaTimbrado    = DateTime.Now;
            tfd.Leyenda          = "";
            tfd.NoCertificadoSAT = "00001000000404486074";
            tfd.SelloCFD         = "RIibW8tNhsl7aOeLKuyzi7dm5a2t+2FTsVjG4602lX2lcCQdMtosfwmJuBhUCYaYM9eNzcqtyXljEf0nsmsDI+ZL8LGMKmrMoiQDsgxaX0BZ77lU06d1SxweHYryR47qI+FwNogv1wqnWUiySlvs9H9LlAgJFZp2oAOaLLhaYwrSS62tjcULRUY8mev6ImXThLwzq6GESqzsHYL26bkzyRFtATXhhO8nQfYS8gB1o3JPkhdTvc7s7cdgjBIRreKc4cBxZZtkLnjx51NcVFvDqvfKdreKp45d+zlmpp/9lY65Irf/MY2/mlT4/aZyM/ZFC11HQ+KD/Pl3c4hfM1yGsQ==";
            tfd.SelloSAT         = "Im6lw1+tKaaUdBK457eijgixdRYm39ch2hV0CLZxf0td6fx64C0HtmNEwJ8xw/WtSCD/VQMgsF8s3InJBcGUIUgIf4LYdd+sKdR2qzpr9IXk/+xDYBrQNaos8COUhH/LecB0el9EUYWLcnv6ranMDZHUlXpCo+iG7zx1S9LDc4AC1jQVrNzBL60EelSznmLr8Gw33HRu4AWjnWua+BWwrIXqzKvdO/PnaLiH/PhQUcGzHYjm5MC6cimAToF+gnN1yyy9h1yETI8kQtaaWNoTqK6f8QyMqe/jR+CD7JAVNCsHbDKR10iNCdVJzDgvcdmDFdrZp6ZyXIBWWAAWyAOldw==";
            tfd.RfcProvCertif    = "MAS0810247C0";
            tfd.UUID             = Guid.NewGuid().ToString().ToUpper();
            tfd.Version          = "1.1";

            var complementos = (signDocumentResult.CFDI as Comprobante).Complemento.ToList();

            //complementos.Add(new ComprobanteComplemento() { Any = new XmlElement[1] { GetElement(CreateXmlNom(tfd)) } });
            (signDocumentResult.CFDI as Comprobante).Complemento = complementos.ToArray();

            signDocumentResult.UUID = Guid.Parse(tfd.UUID);

            return(signDocumentResult);
        }
예제 #6
0
 /// <summary>
 /// Stamp Document (lo implementa su hijo)
 /// </summary>
 /// <param name="signDocumentResult"></param>
 /// <returns></returns>
 public virtual async Task <SignDocumentResult <ICFDINomProvider> > StampDocumetAsync(SignDocumentResult <ICFDINomProvider> signDocumentResult)
 {
     throw new NotImplementedException();
 }