Skip to content

API Web

Rafael Dorantes edited this page Oct 24, 2022 · 10 revisions

Operaciones Generales del CFDI

Clientes

Nuevo Cliente

 var cliente = facturama.Clients.Create(new Client
                {
                    Id = "",
                    Email = "ejemplo@ejemplo.com.mx",
                    EmailOp1 = "ejemplo2@ejemplo.com.mx",
                    EmailOp2 = "ejemplo3@ejemplo.com.mx",
                    Rfc = "CACX7605101P8",
                    Name = "XOCHILT CASAS CHAVEZ",
                    TaxResidence = null,
                    NumRegIdTrib = null,
                    FiscalRegime="605",
                    TaxZipCode = "10740",
                    CfdiUse = "G03",
                    Address = new Address
                    {
                        Street = "Calle de pruebas",
                        ExteriorNumber = "123",
                        InteriorNumber = "B",
                        Neighborhood = "Santa Teresa",
                        ZipCode = "10740",
                        Locality = "Ciudad de México",
                        Municipality = "La Magdalena Contreras",
                        State = "Distrito Federal",
                        Country = "Mex",
                    }

                });

Listar Clientes

Solo devuelve los 100 primeros registros.

Metodo List()

var clientes = facturama.clients.List();
var totalClients = clientes.Count;
Console.WriteLine(totalClients);

Metodo List2("Parámetros")

var start = 0;
var lenght = 100;
var search = "XAXX010101000";

var clientes = facturama.Clients.List2($"start={start}&lenght={lenght}&search={search}");

Console.WriteLine(clientes.Length);

Eliminar CLientes

var cliente_ID="3PzybenYOxj9bpbpBakv0w2";
facturama.Clients.Remove(cliente_Id); 

Editar CLientes

var cliente_Id = "3PzybenYOxj9bpbpBakv0w2";
var cliente = facturama.Clients.Retrieve(cliente_Id); 

cliente.Rfc = "IAÑL750210963";

facturama.Clients.Update(cliente, cliente.Id);      // Actualizar datos
cliente = facturama.Clients.Retrieve(cliente.Id);

Productos

Product product = new Product()
                {
                    Unit = "Servicio",
                    UnitCode = "E48",
                    IdentificationNumber = "WEB003",
                    Name = "Sitio Web CMS",
                    Description = "Desarrollo de Sitio informativo, de una paginas",
                    //Category="",
                    Price = 6500.0000M,
                    CodeProdServ = "43232408",
                    // NameCodeProdServ= "Software de desarrollo de plataformas web",
                    CuentaPredial = "123456",
                    Taxes = new[]
                   {
                       new Tax
                       {
                           Name="IVA",
                           Rate=0.16m,
                           IsRetention=false,
                       },
                       new Tax
                       {
                           Name="ISR",
                           Rate=0.1m,
                           IsRetention=false,
                       },
                       new Tax
                       {
                           Name="IVA",
                           Rate=0.106667m,
                           IsRetention=true,
                       }
                   }

                };
                product = facturama.Products.Create(product);

Lugar de Expedición

var branchoffice = new BranchOffice
            {
                Name="Nueva Sucursal",
                Description="Descripcion de la sucursal",
                Address = new Address
                {
                    Street = "Av. del Sauce",
                    ExteriorNumber = "120",
                    InteriorNumber = "",
                    Neighborhood = "Las Flores",
                    ZipCode = "78116",
                    Locality = "",
                    Municipality = "San Luis Potosi",
                    State = "San Luis Potosi",
                    Country = "México"
                }

            };
            branchoffice= facturama.BranchOffices.Create(branchoffice);

CFDI 3.3

Tipo Ingreso

CFDI 3.3

var cfdi = new Cfdi
{
    Serie = "R",
    Currency = "MXN",
    ExpeditionPlace = "78116",
    PaymentConditions = "CREDITO A SIETE DIAS",
    CfdiType = CfdiType.Ingreso,
    PaymentForm = "03",
    PaymentMethod = "PUE",
    Receiver = new Receiver
    {
        Rfc = "RSS2202108U5",
        Name = "RADIAL SOFTWARE SOLUTIONS",
        CfdiUse = "P01"
    },
    Items = new List<Item>
    {
        new Item
        {
            ProductCode = "10101504",
            IdentificationNumber = "EDL",
            Description = "Estudios de viabilidad",
            Unit = "NO APLICA",
            UnitCode = "MTS",
            UnitPrice = 50.00m,
            Quantity = 2.00m,
            Subtotal = 100.00m,
            Taxes = new List<Tax>
            {
                new Tax
                {

                    Total = 16.00m,
                    Name = "IVA",
                    Base = 100.00m,
                    Rate = 0.160000m,
                    IsRetention = false
                }
            },
            Total = 116.0m
        }
    }
};
var cfdiCreated = facturama.Cfdis.Create(cfdi);

Complemento de Pago 1.0

            Cfdi cfdi = new Cfdi
            {
            
            cfdi.NameId = "14";

            Receiver receiver = new Receiver
            {
                CfdiUse = "P01",
                Name = "URE180429TM6",
                Rfc = "URE180429TM6"
            };
            cfdi.Receiver = receiver;

            cfdi.ExpeditionPlace = "78140"            
            cfdi.Date = null; // Puedes especificar una fecha por ejemplo:  DateTime.Now
            cfdi.CfdiType = CfdiType.Pago;

            // Complemento de pago ---
            Complement complement = new Complement();

            // Pueden representarse más de un pago en un solo CFDI
            List<Facturama.Models.Complements.Payment> lstPagos = new List<Facturama.Models.Complements.Payment>();
            Facturama.Models.Complements.Payment pago = new Facturama.Models.Complements.Payment();

            pago.Date = DateTime.Now.AddHours(-6).ToString("yyyy-MM-dd HH:mm:ss");
            Facturama.Models.Response.Catalogs.CatalogViewModel paymentForm = facturama.Catalogs.PaymentForms.Where(p => p.Name.Equals("Efectivo")).First();
            pago.PaymentForm = paymentForm.Value;
            pago.Currency = "MXN";          
            pago.Amount = 100.00m;
            List<Facturama.Models.Complements.RelatedDocument> lstRelatedDocuments = new List<Facturama.Models.Complements.RelatedDocument>();
            Facturama.Models.Complements.RelatedDocument relatedDocument = new Facturama.Models.Complements.RelatedDocument
            {
                Uuid = "27568D31-E579-442F-BA77-798CBF30BD7D", 
                Serie = "A",//cfdiInicial.Serie, // "EA"
                Folio = "34853",
                Currency = "MXN";,
                PaymentMethod = "PUE", // En el complemento de pago tiene que ser PUE
                PartialityNumber = 1,
                PreviousBalanceAmount = 100.00m,
                AmountPaid = 100.00m,
            };
            lstRelatedDocuments.Add(relatedDocument);

            pago.RelatedDocuments = lstRelatedDocuments;

            lstPagos.Add(pago);

            complement.Payments = lstPagos;

            cfdi.Complement = complement;

        };
        var cfdiCreated = facturama.Cfdis.Create(cfdi);
        Console.WriteLine($"Se creo exitosamente el CFDI 3.3 con ID: {cfdiCreated.Id} y folío fiscal: {cfdiCreated.Complement.TaxStamp.Uuid}");

CFDI 4.0

Tipo Ingreso

var cfdi = new Cfdi
{
    Serie = "R",
    Currency = "MXN",
    ExpeditionPlace = "78116",
    PaymentConditions = "CREDITO A SIETE DIAS",
    CfdiType = CfdiType.Ingreso,
    PaymentForm = "03",
    PaymentMethod = "PUE",
    Receiver = new Receiver
    {
        Rfc = "EKU9003173C9",
        Name = "ESCUELA KEMPER URGATE",
        CfdiUse = "P01",
        FiscalRegime="603",
        TaxZipCode="26015"
    },
    Items = new List<Item>
    {
        new Item
        {
            ProductCode = "10101504",
            IdentificationNumber = "EDL",
            Description = "Estudios de viabilidad",
            Unit = "NO APLICA",
            UnitCode = "MTS",
            UnitPrice = 50.00m,
            Quantity = 2.00m,
            Subtotal = 100.00m,
            TaxObject="02", 
            Taxes = new List<Tax>
            {
                new Tax
                {

                    Total = 16.00m,
                    Name = "IVA",
                    Base = 100.00m,
                    Rate = 0.160000m,
                    IsRetention = false
                }
            },
            Total = 116.0m
        }
    }
};
var cfdiCreated = facturama.Cfdis.Create3(cfdi);

Complemento Pago 2.0

 Cfdi cfdi = new Cfdi
 {

            cfdi.NameId = "14"; // "Complemento de pago"
            cfdi.ExpeditionPlace = "78140";
            cfdi.Date = null; // Puedes especificar una fecha por ejemplo:  DateTime.Now
            cfdi.CfdiType = CfdiType.Pago; //"P" Pago
          

            Receiver receiver = new Receiver
            {
                Rfc = "URE180429TM6",
                Name = "UNIVERSIDAD ROBOTICA ESPAÑOLA",
                CfdiUse = "CP01",
                FiscalRegime = "601",
                TaxZipCode = "65000",
            };
            cfdi.Receiver = receiver;


            // Complemento de pago ---
            Complement complement = new Complement();
            // Pueden representarse más de un pago en un solo CFDI
            List<Facturama.Models.Complements.Payment> lstPagos = new List<Facturama.Models.Complements.Payment>();
            Facturama.Models.Complements.Payment pago = new Facturama.Models.Complements.Payment();

            // Fecha y hora en que se registró el pago en el formato: "yyyy-MM-ddTHH:mm:ss" 
            // (la fecha del pago debe ser menor que la fecha en que se emite el CFDI)
            // Para este ejemplo, se considera que  el pago se realizó hace una hora   
            pago.Date = DateTime.Now.AddHours(-6).ToString("yyyy-MM-dd HH:mm:ss");


            // Forma de pago (Efectivo, Tarjeta, etc)
            Facturama.Models.Response.Catalogs.CatalogViewModel paymentForm = facturama.Catalogs.PaymentForms.Where(p => p.Name.Equals("Efectivo")).First();
            pago.PaymentForm = paymentForm.Value;

            // Selección de la moneda del catálogo
            // La Moneda, puede ser diferente a la del documento inicial
            // (En el caso de que sea diferente, se debe colocar el tipo de cambio)
            List<CurrencyCatalog> lstCurrencies = facturama.Catalogs.Currencies.ToList();
            CurrencyCatalog currency = lstCurrencies.Where(p => p.Value.Equals("MXN")).First();
            pago.Currency = currency.Value;

            // Monto del pago
            // Este monto se puede distribuir entre los documentos relacionados al pago            
            pago.Amount = 116.00m;

            // Documentos relacionados con el pago
            // En este ejemplo, los datos se obtiene el cfdiInicial, pero puedes colocar solo los datos
            // aun sin tener el "Objeto" del cfdi Inicial, ya que los valores son del tipo "String"
            List<Facturama.Models.Complements.RelatedDocument> lstRelatedDocuments = new List<Facturama.Models.Complements.RelatedDocument>();
            List<Facturama.Models.Complements.Tax> lsttax = new List<Facturama.Models.Complements.Tax>();
            Facturama.Models.Complements.RelatedDocument relatedDocument = new Facturama.Models.Complements.RelatedDocument
            {
                Uuid = cfdiInicial.Complement.TaxStamp.Uuid, // "27568D31-E579-442F-BA77-798CBF30BD7D"
                Serie = "A",//cfdiInicial.Serie, // "EA"
                Folio = cfdiInicial.Folio, // 
                Currency = currency.Value,
                PaymentMethod = "PUE", // En el complemento de pago tiene que ser PUE
                PartialityNumber = 1,
                PreviousBalanceAmount = 116.00m,
                AmountPaid = 116.00m,
                TaxObject = "02",
            };
            
            Facturama.Models.Complements.Tax tax = new Facturama.Models.Complements.Tax
            {
                Total = 16.00m,
                Name  = "IVA",
                Base = 100.00m,
                Rate= 0.16m,
                IsRetention= false
            };

            lsttax.Add(tax);
            relatedDocument.Taxes = lsttax;

            lstRelatedDocuments.Add(relatedDocument);

            pago.RelatedDocuments = lstRelatedDocuments;

            lstPagos.Add(pago);
           
            complement.Payments = lstPagos;

            cfdi.Complement = complement;
        };

        var cfdiCreated = facturama.Cfdis.Create(cfdi);
        Console.WriteLine($"Se creo complemento de pago 2.0 con ID: {cfdiCreated.Id} y folío fiscal: {cfdiCreated.Complement.TaxStamp.Uuid}");

Cancelar CFDI

facturama.Cfdis.Remove(cfdiCreated.Id);

Cancelar retenciones

Descargar Factura

Descarga en el formato deseado xml, html ó pdf

facturama.Cfdis.SavePdf($"factura.pdf", cfdiCreated.Id);
facturama.Cfdis.SaveXml($"factura.xml", cfdiCreated.Id);

Obtener CFDI con keywork

Consulta tus facturas en cualquier momento mediante una palabra clave ó algun atributo en específico

facturama.Cfdis.List("Expresion en Software");
facturama.Cfdis.List(rfc: "ESO1202108R2");

Enviar CFDI por Email

Envia tu CFDI por Email

facturama.Cfdis.SendByMail(cfdiCreated.Id, "soporte-api@facturama.com.mx")