示例#1
0
        void _view_OnGetToken(object sender, EventArgs e)
        {
            long   transactionID = _random.Next();
            string Error;

            Utils.Utilerias Util = new Utils.Utilerias(_view);
            Error = Util.CreateToken(Util.RFC, transactionID, ref token);
            if (!string.IsNullOrEmpty(Error))
            {
                _view.ShowUnknownError(Error);
                return;
            }
            _view.ShowUnknownError(string.Format("Token: {0}", token));
        }
        void _view_onGetAdvices(object sender, EventArgs e)
        {
            using (var Avisos = new SrvClients.ClientesClient())
            {
                Random _random       = new Random();
                Int64  transactionID = _random.Next();
                string token         = string.Empty;

                string          Error;
                Utils.Utilerias Util = new Utils.Utilerias(_view);
                Error = Util.CreateToken(_view.RFC, transactionID, ref token);
                if (!string.IsNullOrEmpty(Error))
                {
                    _view.ShowUnknownError(Error);
                    return;
                }
                try
                {
                    var            respuesta = Avisos.AvisosNuevos(_view.RFC, token, ref transactionID);
                    ListViewItem[] Items     = new ListViewItem[0];
                    foreach (var item in respuesta)
                    {
                        ListViewItem lsvItem = new ListViewItem(item.Mensaje);
                        lsvItem.SubItems.Add(item.Vigencia.ToShortDateString());
                        if (Items.Length == 0 || Items[0] != null)
                        {
                            Array.Resize <ListViewItem>(ref Items, Items.Length + 1);
                        }
                        Items[Items.Length - 1] = lsvItem;
                    }
                    _view.itemsAdvices = Items;
                }
                catch (FaultException <SrvClients.FallaServicio> fallaServicio)
                {
                    using (var errorForm = new Forms.Error(TranslateFault.ToServiceError(fallaServicio.Detail)))
                    {
                        errorForm.ShowDialog();
                    }
                }
                catch (FaultException <SrvClients.FallaSesion> fallaSesion)
                {
                    _view.ShowSessionError(TranslateFault.ToSessionError(fallaSesion.Detail));
                }
                catch (Exception ex)
                { _view.ShowUnknownError(ex.Message); }
            }
        }
        void View_onAltaEmisor(object sender, EventArgs e)
        {
            using (var Cliente = new SrvClients.ClientesClient())
            {
                long   trsId  = _view.TransaccionId;
                long   trsIdO = 0;
                string token  = string.Empty;

                string          Error;
                Utils.Utilerias Util = new Utils.Utilerias(_view);
                Error = Util.CreateTokenAlta(_view.RFCIntegrador, trsId, ref token);
                if (!string.IsNullOrEmpty(Error))
                {
                    _view.ShowUnknownError(Error);
                    return;
                }
                try
                {
                    var Emisor = new SrvClients.AltaEmisor();
                    Emisor.RFC               = _view.RFCEmisor;
                    Emisor.RazonSocial       = _view.RazonSocial;
                    Emisor.CorreoElectronico = _view.CorreoElectronico;
                    var respuesta = Cliente.Registrar(Emisor, _view.RFCIntegrador, token, trsId, out trsIdO);
                    _view.RFCEmisor        = respuesta.RFC;
                    _view.Estatus          = respuesta.Estatus;
                    _view.ClaveCertificado = respuesta.ClaveCertificado;
                }
                catch (FaultException <SrvRepository.FallaServicio> serviceFault)
                {
                    using (var errorForm = new Forms.Error(TranslateFault.ToServiceError(serviceFault.Detail)))
                    {
                        errorForm.ShowDialog();
                    }
                }
                catch (FaultException <SrvRepository.FallaSesion> sessionFault)
                {
                    _view.ShowSessionError(TranslateFault.ToSessionError(sessionFault.Detail));
                }
                catch (Exception ex)
                { _view.ShowUnknownError(ex.Message); }
            }
        }
示例#4
0
        void View_onGetStatusClient(object sender, EventArgs e)
        {
            using (var Client = new SrvClients.ClientesClient())
            {
                Random _random       = new Random();
                Int64  transactionID = _random.Next();
                string token         = string.Empty;

                string          Error;
                Utils.Utilerias Util = new Utils.Utilerias(_view);
                Error = Util.CreateToken(_view.RFC, transactionID, ref token);
                if (!string.IsNullOrEmpty(Error))
                {
                    _view.ShowUnknownError(Error);
                    return;
                }
                try
                {
                    var respuesta = Client.EstatusCuenta(_view.RFC, token, ref transactionID);
                    _view.InvoicesAsigned   = respuesta.TimbresAsignados.ToString();
                    _view.InvoicesRemaining = respuesta.TimbresDisponibles.ToString();
                    //_view.InvoicesUsed=respuesta.TimbresEmitidos;
                    _view.DateStart   = respuesta.FechaInicio;
                    _view.DateEnd     = respuesta.FechaFin;
                    _view.Description = respuesta.Descripcion;
                }
                catch (FaultException <SrvClients.FallaServicio> fallaServicio)
                {
                    using (var errorForm = new Forms.Error(TranslateFault.ToServiceError(fallaServicio.Detail)))
                    {
                        errorForm.ShowDialog();
                    }
                }
                catch (FaultException <SrvClients.FallaSesion> fallaSesion)
                {
                    _view.ShowSessionError(TranslateFault.ToSessionError(fallaSesion.Detail));
                }
                catch (Exception ex)
                { _view.ShowUnknownError(ex.Message); }
            }
        }
示例#5
0
        void View_onGetInvoice(object sender, EventArgs e)
        {
            using (var Comprobante = new SrvRepository.RepositorioClient())
            {
                Int64  transactionID    = _view.transactionID;
                Random _random          = new Random();
                Int64  transactionNueva = _random.Next();
                string token            = string.Empty;

                string          Error;
                Utils.Utilerias Util = new Utils.Utilerias(_view);
                Error = Util.CreateToken(_view.RFC, transactionID, ref token);
                if (!string.IsNullOrEmpty(Error))
                {
                    _view.ShowUnknownError(Error);
                    return;
                }
                try
                {
                    var respuesta = Comprobante.ObtenerComprobante(_view.RFC, token, ref transactionNueva, transactionID, _view.UUID);

                    _view.Invoice = respuesta.DatosXML;
                }
                catch (FaultException <SrvRepository.FallaServicio> serviceFault)
                {
                    using (var errorForm = new Forms.Error(TranslateFault.ToServiceError(serviceFault.Detail)))
                    {
                        errorForm.ShowDialog();
                    }
                }
                catch (FaultException <SrvRepository.FallaSesion> sessionFault)
                {
                    _view.ShowSessionError(TranslateFault.ToSessionError(sessionFault.Detail));
                }
                catch (Exception ex)
                { _view.ShowUnknownError(ex.Message); }
            }
        }
        void View_onAsignarTimbresEmisor(object sender, EventArgs e)
        {
            using (var AsignaTimbre = new SrvClients.ClientesClient())
            {
                long   trsID      = _view.trsID;
                string token      = string.Empty;
                int    SaldoNuevo = 0;

                string          Error;
                Utils.Utilerias Util = new Utils.Utilerias(_view);
                Error = Util.CreateToken(_view.RFCAsignar, trsID, ref token);
                if (!string.IsNullOrEmpty(Error))
                {
                    _view.ShowUnknownError(Error);
                    return;
                }
                try
                {
                    var respuesta = AsignaTimbre.AsignacionTimbres(_view.RFCAsignar, _view.TimbresAsignar, ref token, ref trsID, out SaldoNuevo);
                    _view.SaldoAnterior = respuesta;
                    _view.SaldoNuevo    = SaldoNuevo;
                }
                catch (FaultException <SrvRepository.FallaServicio> serviceFault)
                {
                    using (var errorForm = new Forms.Error(TranslateFault.ToServiceError(serviceFault.Detail)))
                    {
                        errorForm.ShowDialog();
                    }
                }
                catch (FaultException <SrvRepository.FallaSesion> sessionFault)
                {
                    _view.ShowSessionError(TranslateFault.ToSessionError(sessionFault.Detail));
                }
                catch (Exception ex)
                { _view.ShowUnknownError(ex.Message); }
            }
        }
 void View_onRecuperaAcuseCancelacion(object sender, EventArgs e)
 {
     using (var Cancelacion = new SrvCancelacion.CancelacionesClient())
     {
         long            trsId   = _view.TransaccionId;
         string          token   = string.Empty;
         string          Estatus = string.Empty;
         string          Error;
         Utils.Utilerias Util = new Utils.Utilerias(_view);
         Error = Util.CreateToken(_view.RFCEmisor, trsId, ref token);
         if (!string.IsNullOrEmpty(Error))
         {
             _view.ShowUnknownError(Error);
             return;
         }
         try
         {
             var respuesta = Cancelacion.RecuperarAcuses(_view.RFCEmisor, token, ref trsId, _view.UUID, out Estatus);
             _view.AcuseXML = respuesta;
             _view.Estatus  = Estatus;
             _view.UUID     = _view.UUID;
         }
         catch (FaultException <SrvRepository.FallaServicio> serviceFault)
         {
             using (var errorForm = new Forms.Error(TranslateFault.ToServiceError(serviceFault.Detail)))
             {
                 errorForm.ShowDialog();
             }
         }
         catch (FaultException <SrvRepository.FallaSesion> sessionFault)
         {
             _view.ShowSessionError(TranslateFault.ToSessionError(sessionFault.Detail));
         }
         catch (Exception ex)
         { _view.ShowUnknownError(ex.Message); }
     }
 }
示例#8
0
        void _view_UniTestDummyXMLString(object sender, EventArgs e)
        {
            //var rfc = "VACS740221QW6";
            long   transactionID = _random.Next();
            var    token         = String.Empty;
            string Error;

            Utils.Utilerias Util = new Utils.Utilerias(_view);
            Error = Util.CreateToken(Util.RFC, transactionID, ref token);
            if (!string.IsNullOrEmpty(Error))
            {
                _view.ShowUnknownError(Error);
                return;
            }
            try
            {
                #region Build Token
                //using (var securitySrv = new SrvSecurity.SeguridadClient())
                //{
                //    var serviceToken = securitySrv.ObtenerToken(rfc, ref transactionID);
                //    var toHash = String.Format("{0}|{1}", INTEGRATOR_ID, serviceToken);
                //    token = Security.Hash(toHash);
                //}
                #endregion
                transactionID = _random.Next();
                var invoiceXML = new SrvInvoices.ComprobanteXML
                {
                    DatosXML = "<?xml version=\"1.0\" encoding=\"utf-8\"?><cfdi:Comprobante xmlns:cfdi=\"http://www.sat.gob.mx/cfd/3\" xmlns:donat=\"http://www.sat.gob.mx/donat\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" sello=\"oJ3DHNsd+OmVObTITGKKExJn1T/KZl3HxovXk5cXPUSCpb0s3b2eCyoFy3Ko/l0Ni58eUq95Do5w2GjEaLUce++1WGl+s8DOb4XAYI+u+aa9m8lR6Ij22hfx8crFPeWe5knbKvXcN2XONZn/v6vZXmnSreA2nIRV9W2RkPWVLL8=\" certificado=\"MIIEZDCCA0ygAwIBAgIUMDAwMDEwMDAwMDAxMDIyMzIyMjIwDQYJKoZIhvcNAQEFBQAwggE2MTgwNgYDVQQDDC9BLkMuIGRlbCBTZXJ2aWNpbyBkZSBBZG1pbmlzdHJhY2nDs24gVHJpYnV0YXJpYTEvMC0GA1UECgwmU2VydmljaW8gZGUgQWRtaW5pc3RyYWNpw7NuIFRyaWJ1dGFyaWExHzAdBgkqhkiG9w0BCQEWEGFjb2RzQHNhdC5nb2IubXgxJjAkBgNVBAkMHUF2LiBIaWRhbGdvIDc3LCBDb2wuIEd1ZXJyZXJvMQ4wDAYDVQQRDAUwNjMwMDELMAkGA1UEBhMCTVgxGTAXBgNVBAgMEERpc3RyaXRvIEZlZGVyYWwxEzARBgNVBAcMCkN1YXVodGVtb2MxMzAxBgkqhkiG9w0BCQIMJFJlc3BvbnNhYmxlOiBGZXJuYW5kbyBNYXJ0w61uZXogQ29zczAeFw0xMDExMjMyMzMyNDJaFw0xMjExMjIyMzMyNDJaMIIBAzE3MDUGA1UEAxMuSU5URUdSQURPUkEgQURVQU5BTCBZIERFIFNFUlZJQ0lPUyBXT09EV0FSRCBTQzE3MDUGA1UEKRMuSU5URUdSQURPUkEgQURVQU5BTCBZIERFIFNFUlZJQ0lPUyBXT09EV0FSRCBTQzE3MDUGA1UEChMuSU5URUdSQURPUkEgQURVQU5BTCBZIERFIFNFUlZJQ0lPUyBXT09EV0FSRCBTQzElMCMGA1UELRMcSUFTMDMxMTA0R0NBIC8gUkFSTzgyMDUxMVJZODEeMBwGA1UEBRMVIC8gUkFSTzgyMDUxMU1DTU1CRjAwMQ8wDQYDVQQLEwZVTklEQUQwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAMfKk6D8zQ/YC43iBOWsda6l3O65EmG0nWzmeDP0lzQba9QwzK0oxPDdzGXB4RNIr6ek3Ln83/j8r4wDA9kZOdIp6RXtyjzLs+4YMlsPmjkG61It+EKBwoqdrbAB/cSx3E1mlX4BgZ7ERA8d64hQtiORsRPOqLrbrH7tlhcsXfMbAgMBAAGjHTAbMAwGA1UdEwEB/wQCMAAwCwYDVR0PBAQDAgbAMA0GCSqGSIb3DQEBBQUAA4IBAQA9vNpPgwQ5qmgK4/XtfxSmvz21N4Hxx50FTCA8j7g2vJa/I7kqAotXx2xqMs6QKD8KxnWvA2lkgKckv5nHy95jw1/X2mCESw/1dq0K9Oa5dZX/5o5pTRLk/KIpXfCYkGxsR+K/TLyRunRAZEOJbyXcfs6OQ/fLbtkO+abEQhw62nx6fY4E9NSYvcyEd3SFgyxE4hBDjLEqMkKpW6SZkrN/NvsjCmwHghInjQd+17vBjVdcQ5GdpNE8+CUc5cAkIdbRWq+O3M1yqkYTIJAtdtIylmuvu73N6B+4vG7KFpInpHBfSIsUY/ccmKzvzgGoiwe6p3XkPPv4CRktMSJGz6gr\" fecha=\"2011-06-28T18:24:09\" version=\"3.2\" xsi:schemaLocation=\"http://www.sat.gob.mx/cfd/3 http://www.sat.gob.mx/sitio_internet/cfd/3/cfdv32.xsd\" serie=\"8\" folio=\"3\" formaDePago=\"PAGO EN UNA SOLA EXHIBICION\" metodoDePago=\"Efectivo\" noCertificado=\"20001000000100005867\" subTotal=\"7069.00\" TipoCambio=\"1\" Moneda=\"PESO\" total=\"8200.04\" tipoDeComprobante=\"ingreso\" NumCtaPago=\"123456\"  LugarExpedicion=\"manzanillo\"  FolioFiscalOrig=\"23480727-43C3-40C4-A866-356152786D86\" SerieFolioFiscalOrig=\"A\" FechaFolioFiscalOrig=\"2011-12-18T00:00:00\" MontoFolioFiscalOrig=\"125.21\"><cfdi:Emisor rfc=\"AAA010101AAA\" nombre=\"INTEGRADORA ADUANAL Y DE SERVICIOS WOODWARD S.C.\">  <cfdi:DomicilioFiscal calle=\"AV. TENIENTE AZUETA\" noExterior=\"25-1\" colonia=\"BUROCRATA\" localidad=\"MANZANILLO\" municipio=\"MANZANILLO\" estado=\"COLIMA\" pais=\"MEXICO\" codigoPostal=\"28250\"/><cfdi:RegimenFiscal Regimen=\"regimen 1\" /><cfdi:RegimenFiscal Regimen=\"regimen 2\" /></cfdi:Emisor><cfdi:Receptor rfc=\"XEXX010101000\" nombre=\"TRADING SERVICES CORPORATION.\">  <cfdi:Domicilio calle=\"1705 E HILLSIDE RD STE.\" noExterior=\"1\" localidad=\"LAREDO\" referencia=\"LAREDO\" municipio=\"LAREDO\" estado=\"TEXAS\" pais=\"USA\" codigoPostal=\"78041\"/></cfdi:Receptor><cfdi:Conceptos>  <cfdi:Concepto cantidad=\"1\" unidad=\"SERVICIO\" descripcion=\"inicio SERVICIOS COMPLEMENTARIOS\" valorUnitario=\"2000.00\" importe=\"2000.00\"/></cfdi:Conceptos><cfdi:Impuestos totalImpuestosTrasladados=\"1131.04\">  <cfdi:Traslados>    <cfdi:Traslado impuesto=\"IVA\" tasa=\"16\" importe=\"1131.04\"/>  </cfdi:Traslados></cfdi:Impuestos></cfdi:Comprobante>"
                };
                using (var invoiceSrv = new SrvInvoices.ComprobantesClient())
                {
                    var advertencias = invoiceSrv.SellaTimbraXML(ref invoiceXML, Util.RFC, token, ref transactionID);
                    _view.ResultStr = invoiceXML.DatosXML;
                }
                #region Optional steep to get the QR barcode image
                transactionID = _random.Next();
                XDocument doc = new XDocument();
                doc = XDocument.Parse(invoiceXML.DatosXML);
                XElement singature = new XElement("{http://www.sat.gob.mx/TimbreFiscalDigital}TimbreFiscalDigital");
                string   uuid      = doc.Root.Descendants(singature.Name).ToArray()[0].Attribute("UUID").Value;
                using (var repositorySrv = new SrvRepository.RepositorioClient())
                {
                    var infoQR = repositorySrv.ObtenerQR(Util.RFC, token, ref transactionID, uuid);
                    var ms     = new System.IO.MemoryStream(infoQR.Imagen);
                    _view.BarcodeQR = new System.Drawing.Bitmap(ms);
                }
                #endregion
            }
            #region Invoice service exceptions
            catch (FaultException <SrvInvoices.FallaServicio> serviceFault)
            {
                using (var errorForm = new Forms.Error(TranslateFault.ToServiceError(serviceFault.Detail)))
                {
                    errorForm.ShowDialog();
                }
            }
            catch (FaultException <SrvInvoices.FallaSesion> sessionFauld)
            {
                _view.ShowSessionError(TranslateFault.ToSessionError(sessionFauld.Detail));
            }
            catch (FaultException <SrvInvoices.FallaValidacion> validationFault)
            {
                using (var errorForm = new Forms.Error(TranslateFault.ToValidationError(validationFault.Detail)))
                {
                    errorForm.ShowDialog();
                }
            }
            #endregion
            catch (Exception ex)
            {
                _view.ShowUnknownError(ex.Message);
            }
        }
示例#9
0
        void _view_UniTestDunnyInvoice(object sender, EventArgs e)
        {
            //var rfc = "VACS740221QW6";
            long   transactionID = _random.Next();
            var    token         = String.Empty;
            string Error;

            Utils.Utilerias Util = new Utils.Utilerias(_view);
            Error = Util.CreateToken(Util.RFC, transactionID, ref token);
            if (!string.IsNullOrEmpty(Error))
            {
                _view.ShowUnknownError(Error);
                return;
            }
            try
            {
                #region Build Token
                //using (var securitySrv = new SrvSecurity.SeguridadClient())
                //{
                //    var serviceToken = securitySrv.ObtenerToken(rfc, ref transactionID);
                //    var toHash = String.Format("{0}|{1}", INTEGRATOR_ID, serviceToken);
                //    token = Security.Hash(toHash);
                //}
                #endregion
                transactionID = _random.Next();
                #region Generate Dummy Invoice with the service class
                var invoice = new SrvInvoices.Comprobante
                {
                    TipoDeComprobante = SrvInvoices.TipoDeComprobante.Ingreso,
                    Total             = 488.50m,
                    SubTotal          = 466.43m,
                    CondicionesDePago = "Contado",
                    Certificado       = "MIIEdDCCA1ygAwIBAgIUMjAwMDEwMDAwMDAxMDAwMDU4NjcwDQYJKoZIhvcNAQEFBQAwggFvMRgwFgYDVQQDDA9BLkMuIGRlIHBydWViYXMxLzAtBgNVBAoMJlNlcnZpY2lvIGRlIEFkbWluaXN0cmFjacOzbiBUcmlidXRhcmlhMTgwNgYDVQQLDC9BZG1pbmlzdHJhY2nDs24gZGUgU2VndXJpZGFkIGRlIGxhIEluZm9ybWFjacOzbjEpMCcGCSqGSIb3DQEJARYaYXNpc25ldEBwcnVlYmFzLnNhdC5nb2IubXgxJjAkBgNVBAkMHUF2LiBIaWRhbGdvIDc3LCBDb2wuIEd1ZXJyZXJvMQ4wDAYDVQQRDAUwNjMwMDELMAkGA1UEBhMCTVgxGTAXBgNVBAgMEERpc3RyaXRvIEZlZGVyYWwxEjAQBgNVBAcMCUNveW9hY8OhbjEVMBMGA1UELRMMU0FUOTcwNzAxTk4zMTIwMAYJKoZIhvcNAQkCDCNSZXNwb25zYWJsZTogSMOpY3RvciBPcm5lbGFzIEFyY2lnYTAeFw0xMjA3MjcxNzAyMDBaFw0xNjA3MjcxNzAyMDBaMIHbMSkwJwYDVQQDEyBBQ0NFTSBTRVJWSUNJT1MgRU1QUkVTQVJJQUxFUyBTQzEpMCcGA1UEKRMgQUNDRU0gU0VSVklDSU9TIEVNUFJFU0FSSUFMRVMgU0MxKTAnBgNVBAoTIEFDQ0VNIFNFUlZJQ0lPUyBFTVBSRVNBUklBTEVTIFNDMSUwIwYDVQQtExxBQUEwMTAxMDFBQUEgLyBIRUdUNzYxMDAzNFMyMR4wHAYDVQQFExUgLyBIRUdUNzYxMDAzTURGUk5OMDkxETAPBgNVBAsTCFVuaWRhZCAxMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC2TTQSPONBOVxpXv9wLYo8jezBrb34i/tLx8jGdtyy27BcesOav2c1NS/Gdv10u9SkWtwdy34uRAVe7H0a3VMRLHAkvp2qMCHaZc4T8k47Jtb9wrOEh/XFS8LgT4y5OQYo6civfXXdlvxWU/gdM/e6I2lg6FGorP8H4GPAJ/qCNwIDAQABox0wGzAMBgNVHRMBAf8EAjAAMAsGA1UdDwQEAwIGwDANBgkqhkiG9w0BAQUFAAOCAQEATxMecTpMbdhSHo6KVUg4QVF4Op2IBhiMaOrtrXBdJgzGotUFcJgdBCMjtTZXSlq1S4DG1jr8p4NzQlzxsdTxaB8nSKJ4KEMgIT7E62xRUj15jI49qFz7f2uMttZLNThipunsN/NF1XtvESMTDwQFvas/Ugig6qwEfSZc0MDxMpKLEkEePmQwtZD+zXFSMVa6hmOu4M+FzGiRXbj4YJXn9Myjd8xbL/c+9UIcrYoZskxDvMxc6/6M3rNNDY3OFhBK+V/sPMzWWGt8S1yjmtPfXgFs1t65AZ2hcTwTAuHrKwDatJ1ZPfa482ZBROAAX1waz7WwXp0gso7sDCm2/yUVww==",
                    NoCertificado     = "20001000000100005867",
                    FormaDePago       = "EN UNA SOLA EXHIBICIÓN",
                    Fecha             = DateTime.Now,
                    Folio             = "523",
                    Serie             = "C",
                    Version           = "3.2",
                    Sello             = ""
                };

                // ISSUER
                //var emisor = new SrvInvoices.Emisor { Nombre = "PHARMA PLUS SA DE CV", RFC = "AAQM610917QJA" };
                var emisor = new SrvInvoices.Emisor {
                    Nombre = "PHARMA PLUS SA DE CV", RFC = Util.RFC
                };
                var emisorDomicilio = new SrvInvoices.UbicacionFiscal
                {
                    CodigoPostal = "03240",
                    Pais         = "México",
                    Estado       = "MEXICO, D.F.",
                    Municipio    = "Benito Juárez",
                    Localidad    = "Distrito Federal",
                    Colonia      = "ACACIAS",
                    Calle        = "AV. RIO MIXCOAC",
                    NoExterior   = "24"
                };
                emisor.DomicilioFiscal = emisorDomicilio;
                invoice.Emisor         = emisor;

                // RECEIVER
                var receptor = new SrvInvoices.Receptor {
                    Nombre = "JUAN PEREZ PEREZ", RFC = "PEPJ8001019Q8"
                };
                var receptorDomicilio = new SrvInvoices.Ubicacion
                {
                    CodigoPostal = "04360",
                    Pais         = "México",
                    Estado       = "DISTRITO FEDERAL",
                    Municipio    = "COYOACAN",
                    Colonia      = "COPILCO UNIVERSIDAD",
                    Calle        = "AV UNIVERSIDAD",
                    Localidad    = "COYACAN",
                    NoExterior   = "724"
                };
                receptor.Domicilio = receptorDomicilio;
                invoice.Receptor   = receptor;

                // CONCEPTS
                var concepto1 = new SrvInvoices.Concepto {
                    Importe = 244.00m, ValorUnitario = 244.00m, Descripcion = "VIBRAMICINA 100MG 10", Cantidad = 1
                };
                var concepto2 = new SrvInvoices.Concepto {
                    Importe = 137.93m, ValorUnitario = 137.93m, Descripcion = "CLORUTO 500M", Cantidad = 1
                };
                var concepto3 = new SrvInvoices.Concepto {
                    Importe = 84.50m, ValorUnitario = 84.50m, Descripcion = "SEDEPRON 250MG 10", Cantidad = 1
                };
                invoice.Conceptos = new SrvInvoices.Concepto[3] {
                    concepto1, concepto2, concepto3
                };

                // TAXES
                var impuestos            = new SrvInvoices.Impuestos();
                var impuestoTransladado1 = new SrvInvoices.ImpuestosTraslado {
                    Impuesto = SrvInvoices.TipoDeImpuestoTraslado.IVA, Importe = 0.0m, Tasa = 0.00m
                };
                var impuestoTransladado2 = new SrvInvoices.ImpuestosTraslado {
                    Impuesto = SrvInvoices.TipoDeImpuestoTraslado.IVA, Importe = 22.07m, Tasa = 16m
                };
                impuestos.Traslados = new SrvInvoices.ImpuestosTraslado[2] {
                    impuestoTransladado1, impuestoTransladado2
                };
                impuestos.TotalImpuestosTrasladados = 22.07m;
                invoice.Impuestos = impuestos;
                #endregion
                var invoiceXML = new SrvInvoices.ComprobanteXML();
                using (var invoiceSrv = new SrvInvoices.ComprobantesClient())
                {
                    var advertencias = invoiceSrv.SellaTimbra(invoice, Util.RFC, token, ref transactionID, out invoiceXML);
                    _view.ResultStr = invoiceXML.DatosXML;
                }
                #region Optional steep to get the QR barcode image
                transactionID = _random.Next();
                XDocument doc = new XDocument();
                doc = XDocument.Parse(invoiceXML.DatosXML);
                XElement singature = new XElement("{http://www.sat.gob.mx/TimbreFiscalDigital}TimbreFiscalDigital");
                string   uuid      = doc.Root.Descendants(singature.Name).ToArray()[0].Attribute("UUID").Value;
                using (var repositorySrv = new SrvRepository.RepositorioClient())
                {
                    var infoQR = repositorySrv.ObtenerQR(Util.RFC, token, ref transactionID, uuid);
                    var ms     = new System.IO.MemoryStream(infoQR.Imagen);
                    _view.BarcodeQR = new System.Drawing.Bitmap(ms);
                }
                #endregion
            }
            #region Invoice service exceptions
            catch (FaultException <SrvInvoices.FallaServicio> serviceFault)
            {
                using (var errorForm = new Forms.Error(TranslateFault.ToServiceError(serviceFault.Detail)))
                {
                    errorForm.ShowDialog();
                }
            }
            catch (FaultException <SrvInvoices.FallaSesion> sessionFauld)
            {
                _view.ShowSessionError(TranslateFault.ToSessionError(sessionFauld.Detail));
            }
            catch (FaultException <SrvInvoices.FallaValidacion> validationFault)
            {
                using (var errorForm = new Forms.Error(TranslateFault.ToValidationError(validationFault.Detail)))
                {
                    errorForm.ShowDialog();
                }
            }
            #endregion
            catch (Exception ex)
            {
                _view.ShowUnknownError(ex.Message);
            }
        }
示例#10
0
        void _view_OnInvoicesProcessStart(object sender, EventArgs e)
        {
            //var rfc = "AAA701117I84";
            long  transactionID = _random.Next();
            var   token         = String.Empty;
            Int16 contador      = 0;


            string Error;

            Utils.Utilerias Util = new Utils.Utilerias(_view);
            Error = Util.CreateToken(Util.RFC, transactionID, ref token);
            if (!string.IsNullOrEmpty(Error))
            {
                _view.ShowUnknownError(Error);
                return;
            }
            foreach (String fileName in _view.SelectedSourceFiles)
            {
                transactionID = _random.Next();
                do
                {
                    var invoiceXML = new SrvInvoices.ComprobanteXML();
                    using (StreamReader myFile = new StreamReader(fileName))
                    {
                        invoiceXML.DatosXML = myFile.ReadToEnd();
                    }
                    try
                    {
                        using (var invoiceSrv = new SrvInvoices.ComprobantesClient())
                        {
                            var advertencias = invoiceSrv.SellaTimbraXML(ref invoiceXML, Util.RFC, token, ref transactionID);

                            StringBuilder lsName       = new StringBuilder(Path.GetFileName(fileName));
                            StringBuilder lsDir        = new StringBuilder(Path.GetDirectoryName(fileName));
                            StringBuilder lsExt        = new StringBuilder(Path.GetExtension(fileName).ToUpper());
                            StringBuilder lsOutputFile = new StringBuilder(string.Format(@"{0}\{1}{2}{3}", lsDir, lsName, transactionID, lsExt.ToString()));
                            StringBuilder loXML        = new StringBuilder();
                            loXML.AppendLine("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
                            loXML.Append(invoiceXML.DatosXML);
                            using (StreamWriter loSW = new StreamWriter(lsOutputFile.ToString(), false, Encoding.UTF8))
                            {
                                loSW.Write(loXML.ToString());
                            }
                            contador = 0;
                            if (!_view.AddResultFile(lsOutputFile.ToString()))
                            {
                                throw new Exception("Can't add output file to the list");
                            }
                        }
                    }
                    #region Invoice service exceptions
                    catch (FaultException <SrvInvoices.FallaServicio> serviceFault)
                    {
                        using (var errorForm = new Forms.Error(TranslateFault.ToServiceError(serviceFault.Detail)))
                        {
                            errorForm.ShowDialog();
                        }
                    }
                    catch (FaultException <SrvInvoices.FallaSesion> sessionFauld)
                    {
                        //_view.ShowSessionError(TranslateFault.ToSessionError(sessionFauld.Detail));
                        if (sessionFauld.Detail.Descripcion.Contains("El Token no es valido o ya expiro"))
                        {
                            //CreateToken(rfc, transactionID, ref token);
                            Error = Util.CreateToken(Util.RFC, transactionID, ref token);
                            contador++;
                        }
                    }
                    catch (FaultException <SrvInvoices.FallaValidacion> validationFault)
                    {
                        using (var errorForm = new Forms.Error(TranslateFault.ToValidationError(validationFault.Detail)))
                        {
                            errorForm.ShowDialog();
                        }
                    }
                    #endregion
                } while (contador == 1);
            }
        }
示例#11
0
        void _view_OnCancelProcessStart(object sender, EventArgs e)
        {
            var  rfc           = _view.SourceRFC;
            long transactionID = _random.Next();
            var  token         = string.Empty;

            /*if (_view.SelectedSourceUUID.Length == 0 && string.IsNullOrEmpty(_view.SourceUUID))
             * {
             *  _view.ShowUnknownError("No se ha seleccionado ningún UUID para cancelar.");
             *  return;
             * }*/
            if (string.IsNullOrEmpty(_view.SourceUUID))
            {
                _view.ShowUnknownError("No se ha indicado ningún UUID para cancelar.");
                return;
            }
            string Error;

            Utils.Utilerias Util = new Utils.Utilerias(_view);
            Error = Util.CreateToken(rfc, transactionID, ref token);
            if (!string.IsNullOrEmpty(Error))
            {
                _view.ShowUnknownError(Error);
                return;
            }
            try
            {
                #region Build Token
                //using (var securitySrv = new SrvSecurity.SeguridadClient())
                //{
                //    var serviceToken = securitySrv.ObtenerToken(rfc, ref transactionID);
                //    var toHash = String.Format("{0}|{1}", INTEGRATOR_ID, serviceToken);
                //    token = Security.Hash(toHash);
                //}
                #endregion
                //foreach (string UUID in _view.SelectedSourceUUID)
                //{
                //    transactionID = _random.Next();
                //    var cancelInvoice = new SrvRepository.RepositorioClient();
                //    var Result = cancelInvoice.CancelaComprobante(rfc, token, ref transactionID, UUID);
                //    if (Result)
                //    {
                //        _view.ShowResult(String.Format("The UUID:{0} has been canceled.", UUID));
                //    }
                //    else
                //    {
                //        _view.ShowUnknownError(String.Format("Can not cancel de UUID: {0}", UUID));
                //    }
                //}
                if (!string.IsNullOrEmpty(_view.SourceUUID))
                {
                    transactionID = _random.Next();
                    var cancelInvoice = new SrvRepository.RepositorioClient();
                    var Result        = cancelInvoice.CancelaComprobante(rfc, token, ref transactionID, _view.SourceUUID);
                    if (Result)
                    {
                        _view.ShowResult(String.Format("The UUID:{0} has canceled.", _view.SourceUUID));
                    }
                    else
                    {
                        _view.ShowUnknownError(String.Format("Cannot cancel de UUID: {0}", _view.SourceUUID));
                    }
                }
            }
            #region Security service exceptions
            catch (FaultException <SrvSecurity.FallaServicio> serviceFault)
            {
                using (var errorForm = new Forms.Error(TranslateFault.ToServiceError(serviceFault.Detail)))
                {
                    errorForm.ShowDialog();
                }
            }
            catch (FaultException <SrvSecurity.FallaSesion> sessionFauld)
            {
                _view.ShowSessionError(TranslateFault.ToSessionError(sessionFauld.Detail));
            }
            #endregion
            #region Invoice service exceptions
            catch (FaultException <SrvRepository.FallaServicio> serviceFault)
            {
                using (var errorForm = new Forms.Error(TranslateFault.ToServiceError(serviceFault.Detail)))
                {
                    errorForm.ShowDialog();
                }
            }
            catch (FaultException <SrvRepository.FallaSesion> sessionFauld)
            {
                _view.ShowSessionError(TranslateFault.ToSessionError(sessionFauld.Detail));
            }
            #endregion
            catch (Exception ex)
            {
                _view.ShowUnknownError(ex.Message);
            }
        }
示例#12
0
        void _view_OnInvoicesProcessStart(object sender, EventArgs e)
        {
            long transactionID = _random.Next();

            Int16 contador = 0;

            Utils.Utilerias Util = new Utils.Utilerias(_view);

            foreach (String fileName in _view.SelectedSourceFiles)
            {
                transactionID = _random.Next();

                //transactionID = 15778284;

                bool bError = false;
                do
                {
                    if (contador > 2)
                    {
                        bError = true;
                    }
                    else
                    {
                        var invoiceXML = new SrvTimbrado.ComprobanteXML();
                        using (StreamReader myFile = new StreamReader(fileName))
                        {
                            invoiceXML.DatosXML = myFile.ReadToEnd();
                        }
                        try
                        {
                            using (var TimbradoSrv = new SrvTimbrado.TimbradoClient())
                            {
                                var advertencias = TimbradoSrv.TimbraXML(ref invoiceXML, Util.RFC, token, ref transactionID);

                                StringBuilder lsName       = new StringBuilder(Path.GetFileName(fileName));
                                StringBuilder lsDir        = new StringBuilder(Path.GetDirectoryName(fileName));
                                StringBuilder lsExt        = new StringBuilder(Path.GetExtension(fileName).ToUpper());
                                StringBuilder lsOutputFile = new StringBuilder(string.Format(@"{0}\{1}{2}{3}", lsDir, lsName, transactionID, lsExt.ToString()));
                                StringBuilder loXML        = new StringBuilder();
                                //loXML.AppendLine("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
                                loXML.Append(invoiceXML.DatosXML);
                                using (StreamWriter loSW = new StreamWriter(lsOutputFile.ToString(), false, Encoding.UTF8))
                                {
                                    loSW.Write(loXML.ToString());
                                }
                                contador = 0;
                                bError   = false;
                                if (!_view.AddResultFile(lsOutputFile.ToString()))
                                {
                                    throw new Exception("Can't add output file to the list");
                                }
                            }
                        }
                        #region Security service exceptions
                        catch (FaultException <SrvSecurity.FallaServicio> serviceFault)
                        {
                            using (var errorForm = new Forms.Error(TranslateFault.ToServiceError(serviceFault.Detail)))
                            {
                                errorForm.ShowDialog();
                            }
                            bError = true;
                        }
                        catch (FaultException <SrvSecurity.FallaSesion> sessionFauld)
                        {
                            _view.ShowSessionError(TranslateFault.ToSessionError(sessionFauld.Detail));
                            bError = true;
                        }
                        #endregion
                        #region Invoice service exceptions
                        catch (FaultException <SrvTimbrado.FallaServicio> serviceFault)
                        {
                            using (var errorForm = new Forms.Error(TranslateFault.ToServiceError(serviceFault.Detail)))
                            {
                                errorForm.ShowDialog();
                            }
                            bError = true;
                        }
                        catch (FaultException <SrvTimbrado.FallaSesion> sessionFauld)
                        {
                            //_view.ShowSessionError(TranslateFault.ToSessionError(sessionFauld.Detail));
                            if (sessionFauld.Detail.Descripcion.Contains("El Token no es valido o ya expiro"))
                            {
                                Util.CreateToken(Util.RFC, transactionID, ref token);
                                contador++;
                            }
                            _view.ShowSessionError(TranslateFault.ToSessionError(sessionFauld.Detail));
                        }
                        catch (FaultException <SrvTimbrado.FallaValidacion> validationFault)
                        {
                            using (var errorForm = new Forms.Error(TranslateFault.ToValidationError(validationFault.Detail)))
                            {
                                errorForm.ShowDialog();
                            }
                            bError = true;
                        }
                        #endregion
                    }

                    if (bError)
                    {
                        contador = 0;
                    }
                } while (contador > 0);
            }
        }
示例#13
0
        void _view_OnSealandStampandStamp(object sender, EventArgs e)
        {
            long transactionID = _random.Next();

            Int16 contador = 0;

            Utils.Utilerias Util = new Utils.Utilerias();

            foreach (String fileName in _view.SelectedSourceFiles)
            {
                transactionID = _random.Next();
                StringBuilder loXML  = new StringBuilder();
                bool          bError = false;
                #region sellado y timbrado
                do
                {
                    var invoiceXML = new SrvInvoices.ComprobanteXML();
                    using (StreamReader myFile = new StreamReader(fileName))
                    {
                        invoiceXML.DatosXML = myFile.ReadToEnd();
                    }
                    if (contador > 3)
                    {
                        _view.ShowUnknownError("Error con el token, se hicieron 3 intentos y fallo.");
                        bError = true;
                    }
                    else
                    {
                        try
                        {
                            using (var invoiceSrv = new SrvInvoices.ComprobantesClient())
                            {
                                var advertencias = invoiceSrv.SellaTimbraXML(ref invoiceXML, Util.RFC, token, ref transactionID);
                                contador = 0;
                                // loXML.AppendLine("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
                                loXML.Append(invoiceXML.DatosXML);
                                XDocument    doc       = new XDocument();
                                byte[]       byteArray = Encoding.ASCII.GetBytes(loXML.ToString());
                                MemoryStream stream    = new MemoryStream(byteArray);
                                doc = System.Xml.Linq.XDocument.Load(stream);
                                //var record = from item in doc.Root.Elements("Complemento") select item;
                                //XElement singature = new XElement("{http://www.sat.gob.mx/TimbreFiscalDigital}TimbreFiscalDigital");
                                //doc.Root.Descendants(singature.Name).Remove();
                                loXML = new StringBuilder();
                                loXML.AppendLine("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
                                loXML.AppendLine(doc.ToString());
                                bError = false;

                                //doc.Descendants("Complemento").Where(p => p.Attribute("") != null).Remove();
                                StringBuilder lsName       = new StringBuilder(Path.GetFileName(fileName));
                                StringBuilder lsDir        = new StringBuilder(Path.GetDirectoryName(fileName));
                                StringBuilder lsExt        = new StringBuilder(Path.GetExtension(fileName).ToUpper());
                                StringBuilder lsOutputFile = new StringBuilder(string.Format(@"{0}\{1}{2}{3}", lsDir, lsName, transactionID, lsExt.ToString()));
                                using (StreamWriter loSW = new StreamWriter(lsOutputFile.ToString(), false, Encoding.UTF8))
                                {
                                    loSW.Write(loXML.ToString());
                                }

                                if (!_view.AddResultFile(lsOutputFile.ToString()))
                                {
                                    throw new Exception("Can't add output file to the list");
                                }
                            }
                        }
                        #region Invoice service exceptions
                        catch (FaultException <SrvInvoices.FallaServicio> serviceFault)
                        {
                            using (var errorForm = new Forms.Error(TranslateFault.ToServiceError(serviceFault.Detail)))
                            {
                                errorForm.ShowDialog();
                            }
                            guardarLog(fileName, string.Format("Error #: {0}\nDescription:{1}", serviceFault.Detail.Numero, serviceFault.Detail.Descripcion));
                            bError = true;
                        }
                        catch (FaultException <SrvInvoices.FallaSesion> sessionFauld)
                        {
                            //_view.ShowSessionError(TranslateFault.ToSessionError(sessionFauld.Detail));
                            if (sessionFauld.Detail.Descripcion.Contains("El Token no es valido o ya expiro"))
                            {
                                Util.CreateToken(Util.RFC, transactionID, ref token);
                                contador++;
                            }
                        }
                        catch (FaultException <SrvInvoices.FallaValidacion> validationFault)
                        {
                            using (var errorForm = new Forms.Error(TranslateFault.ToValidationError(validationFault.Detail)))
                            {
                                errorForm.ShowDialog();
                            }
                            guardarLog(fileName, string.Format("Error #: {0}\nDescription:{1}", validationFault.Detail.Numero, validationFault.Detail.Descripcion));
                            bError = true;
                        }
                        #endregion
                    }

                    if (bError == true)
                    {
                        contador = 0;
                    }
                } while (contador > 0);
                #endregion
            }
        }