En un Comprobante Fiscal Digital por Internet (CFDI), recuerda que:
los datos del emisor son los que fueron cargados en la sección de perfil fiscal ver en la guía
La factura es el CFDI más común, pero hay varios de ellos.
Y cuentan con una estructura base común y de acuerdo al tipo, algunos elementos que lo forman cambian, o se agregan
"NameId": "1", "CfdiType": Facturama::CfdiType::INGRESO, "ExpeditionPlace": "78116", "PaymentForm": "03", "PaymentMethod": "PUE", "Currency": "MXN", "Decimals": "2",
"NameId" => "1", "CfdiType" => "I", "ExpeditionPlace" => "78116", "PaymentForm" => "03", "PaymentMethod" => "PUE", "Currency" => "MXN",
"NameId": "1", "CfdiType": "I", "ExpeditionPlace": "78116", "PaymentForm": "03", "PaymentMethod": "PUE", "Currency": "MXN", "Decimals": "2",
cfdi.setNameId(facturama.Catalogs().NameIds().get(1).getValue()); cfdi.setCfdiType( CfdiType.Ingreso.getValue() ); cfdi.setExpeditionPlace("78216"); cfdi.setPaymentForm(facturama.Catalogs().PaymentForms().get(3).getValue()); cfdi.setPaymentMethod("PUE"); cfdi.setCurrency(currency.getValue());
NameId = "1", CfdiType = CfdiType.Ingreso, ExpeditionPlace = "78116", PaymentForm = "03", PaymentMethod = "PUE", Currency = "MXN",
"NameId": "1", "CfdiType": "I", "ExpeditionPlace": "78116", "PaymentForm": "03", "PaymentMethod": "PUE", "Currency": "MXN",
Es a quien va dirigido el CFDI. En la estructura es representado por un nodo que se coloca en el atributo Receiver
puedes ver en la documentación de la API
"Receiver": { "CfdiUse": "P01", "Name": "CABIFY MEXICO S DE RL DE CV", "Rfc": "XAXX010101000" },
"Receiver" => { "Name" => "CABIFY MEXICO S DE RL DE CV", "CfdiUse" => "P01", "Rfc" => "CME1208017C4" },
"Receiver": { "Name": "CABIFY MEXICO S DE RL DE CV", "CfdiUse": "P01", "Rfc": "CME1208017C4" },
Receiver receiver = new Receiver(); receiver.setName("CABIFY MEXICO S DE RL DE CV"); receiver.setCfdiUse("P01"); receiver.setRfc("CME1208017C4"); cfdi.setReceiver(receiver);
Receiver = new Receiver { Name = "CABIFY MEXICO S DE RL DE CV", CfdiUse = "P01", Rfc = "CME1208017C4" },
"Receiver": { "CfdiUse": "P01", "Name": "CABIFY MEXICO S DE RL DE CV", "Rfc": "XAXX010101000" },
Son el conjunto de productos y servicio que cubre el comprobante, especificando la cantidad, montos e impuestos en cada uno de los conceptos.
En la estructura es representado por un nodo que se coloca en el atributo Items
puedes ver en la documentación de la API
"Items": [ { "Description": " API folios adicionales", "Discount": "10", "IdentificationNumber": "23", "ProductCode": "84111506", "Quantity": "100", "Subtotal": "50.00", "Total": "46.40", "Unit": "Unidad de servicio", "UnitCode": "E48", "UnitPrice": "0.50" "Taxes": [ { "Base": "40", "IsRetention": "false", "Name": "IVA", "Rate": "0.16", "Total": "6.4" } ], "Total": "46.40", "Unit": "Unidad de servicio", "UnitCode": "E48", "UnitPrice": "0.50" }, ... ]
"Items" => [ { "Quantity" => "100", "ProductCode" => "84111506", "UnitCode" => "E48", "Unit" => "Unidad de servicio", "Description" => " API folios adicionales", "IdentificationNumber" => "23", "UnitPrice" => "0.50", "Subtotal" => "50.00", "Discount" => "10", "Taxes" => [ { "Name" => "IVA", "Rate" => "0.16", "Total" => "6.4", "Base" => "40", "IsRetention" => "false" }], "Total" => "46.40" }]
"Items": [ { "Quantity": "100", "ProductCode": "84111506", "UnitCode": "E48", "Unit": "Unidad de servicio", "Description": " API folios adicionales", "IdentificationNumber": "23", "UnitPrice": "0.50", "Subtotal": "50.00", "Discount": "10", "Taxes": [ { "Name": "IVA", "Rate": "0.16", "Total": "6.4", "Base": "40", "IsRetention": "false" }], "Total": "46.40" }]
List<Item> lstItems = new ArrayList<>(); Item item = new Item(); item.setProductCode("84111506"); item.setUnitCode("E48"); item.setUnit("Unidad de servicio"); item.setDescription(" API folios adicionales"); item.setIdentificationNumber("23"); item.setQuantity(100.00); item.setDiscount(10.00 ); item.setUnitPrice(0.50); item.setSubtotal(50.00); List<Tax> lstTaxes = new ArrayList<>(); Tax tax = new Tax(); tax.setName("IVA"); tax.setIsQuota(false); tax.setIsRetention(false); tax.setRate( 0.160000d ); tax.setBase( 40 ); tax.setTotal(6.4); lstTaxes.add(tax); item.setTaxes(lstTaxes); item.setTotal(46.40); lstItems.add(item); cfdi.setItems(lstItems);
Items = new List<Item> { new Item { Quantity = 100, ProductCode = "84111506", UnitCode = "E48", Unit = "Unidad de servicio", Description = " API folios adicionales", IdentificationNumber = "23", UnitPrice = 0.50m, Subtotal = 50.00m, Discount = 10.00m, Taxes = new List<Tax> { new Tax { Name = "IVA", Rate = 0.16m, Total = 6.4m, Base = 40.00m, IsRetention = false } }, Total = 46.40m } }
"Items": [ { "Quantity": "100", "ProductCode": "84111506", "UnitCode": "E48", "Unit": "Unidad de servicio", "Description": " API folios adicionales", "IdentificationNumber": "23", "UnitPrice": "0.50", "Subtotal": "50.00", "Discount": "10", "Taxes": [ { "Name": "IVA", "Rate": "0.16", "Total": "6.4", "Base": "40", "IsRetention": "false" }], "Total": "46.40" }, { "Quantity": "1", "ProductCode": "84111506", "UnitCode": "E48", "Unit": "Unidad de servicio", "Description": " API Implementación ", "IdentificationNumber": "21", "UnitPrice": "6000.00", "Subtotal": "6000.00", "Taxes": [ { "Name": "IVA", "Rate": "0.16", "Total": "960", "Base": "6000", "IsRetention": "false" }], "Total": "6960.00" }]
Los hay de 2 tipos, Impuestos federales e Impuestos locales pero en general tienen la misma estructura. En la estructura es representado por un nodo que se coloca en el atributo Taxes de un Item puedes ver en la documentación de la API
"Taxes": [ { "Base": "40", "IsRetention": "false", "Name": "IVA", "Rate": "0.16", "Total": "6.4" }, ... ],
"Taxes" => [ { "Base" => "40", "IsRetention" => "false", "Name" => "IVA", "Rate" => "0.16", "Total" => "6.4" }, ... ],
"Taxes": [ { "Base": "40", "IsRetention": "false", "Name": "IVA", "Rate": "0.16", "Total": "6.4" }, ... ],
ListlstTaxes = new ArrayList<>(); Tax tax = new Tax(); tax.setName("IVA"); tax.setIsQuota(false); tax.setIsRetention(false); tax.setRate( 0.160000d ); tax.setBase( 40 ); tax.setTotal(6.4); lstTaxes.add(tax);
Taxes = new List{ new Tax { Name = "IVA", Rate = 0.16m, Total = 6.4m, Base = 40.00m, IsRetention = false }, ... },
"Taxes": [ { "Name": "IVA", "Rate": "0.16", "Total": "6.4", "Base": "40", "IsRetention": "false" }, ... ]
cfdi = { "NameId": "1", "PaymentForm": "03", "PaymentMethod": "PUE", "CfdiType": Facturama::CfdiType::INGRESO, "Currency": "MXN", "Decimals": "2", "ExpeditionPlace": "78116", "Receiver": { "CfdiUse": "P01", "Name": "CABIFY MEXICO S DE RL DE CV", "Rfc": "XAXX010101000" }, "Items": [ { "Description": " API folios adicionales", "Discount": "10", "IdentificationNumber": "23", "ProductCode": "84111506", "Quantity": "100", "Subtotal": "50.00", "Taxes": [ { "Base": "40", "IsRetention": "false", "Name": "IVA", "Rate": "0.16", "Total": "6.4" } ], "Total": "46.40", "Unit": "Unidad de servicio", "UnitCode": "E48", "UnitPrice": "0.50" }, { "Description": " API Implementación ", "IdentificationNumber": "21", "ProductCode": "84111506", "Quantity": "1", "Subtotal": "6000.00", "Taxes": [ { "Base": "6000", "IsRetention": "false", "Name": "IVA", "Rate": "0.16", "Total": "960" } ], "Total": "6960.00", "Unit": "Unidad de servicio", "UnitCode": "E48", "UnitPrice": "6000.00" } ] } # Creación del CFDI mediante la API cfdi = facturama.cfdis.create(cfdi)
$cfdi = { "Receiver" => { "Name" => "CABIFY MEXICO S DE RL DE CV", "CfdiUse" => "P01", "Rfc" => "CME1208017C4" }, "CfdiType" => "I", "NameId" => "1", "ExpeditionPlace" => "78216", "PaymentForm" => "03", "PaymentMethod" => "PUE", "Decimals" => "2", "Currency" => "MXN", "Date" => "2018-04-16T09:51:39", "Items" => [ { "Quantity" => "100", "ProductCode" => "84111506", "UnitCode" => "E48", "Unit" => "Unidad de servicio", "Description" => " API folios adicionales", "IdentificationNumber" => "23", "UnitPrice" => "0.50", "Subtotal" => "50.00", "Discount" => "10", "DiscountVal" => "10", "Taxes" => [ { "Name" => "IVA", "Rate" => "0.16", "Total" => "6.4", "Base" => "40", "IsRetention" => "false" }], "Total" => "46.40" }, { "Quantity" => "1", "ProductCode" => "84111506", "UnitCode" => "E48", "Unit" => "Unidad de servicio", "Description" => " API Implementación ", "IdentificationNumber" => "21", "UnitPrice" => "6000.00", "Subtotal" => "6000.00", "Taxes" => [ { "Name" => "IVA", "Rate" => "0.16", "Total" => "960", "Base" => "6000", "IsRetention" => "false" }], "Total" => "6960.00" } ] }; $result = $facturama->post('2/cfdis', $params);
En este ejemplo se considera que Facturama es una instancia de Facturama API ver en la guía
var newCfdi = { "Receiver": { "Name": "CABIFY MEXICO S DE RL DE CV", "CfdiUse": "P01", "Rfc": "CME1208017C4" }, "CfdiType": "I", "NameId": "1", "ExpeditionPlace": "78216", "PaymentForm": "03", "PaymentMethod": "PUE", "Decimals": "2", "Currency": "MXN", "Date": "2018-04-16T09:51:39", "Items": [ { "Quantity": "100", "ProductCode": "84111506", "UnitCode": "E48", "Unit": "Unidad de servicio", "Description": " API folios adicionales", "IdentificationNumber": "23", "UnitPrice": "0.50", "Subtotal": "50.00", "Discount": "10", "DiscountVal": "10", "Taxes": [ { "Name": "IVA", "Rate": "0.16", "Total": "6.4", "Base": "40", "IsRetention": "false" }], "Total": "46.40" }, { "Quantity": "1", "ProductCode": "84111506", "UnitCode": "E48", "Unit": "Unidad de servicio", "Description": " API Implementación ", "IdentificationNumber": "21", "UnitPrice": "6000.00", "Subtotal": "6000.00", "Taxes": [ { "Name": "IVA", "Rate": "0.16", "Total": "960", "Base": "6000", "IsRetention": "false" }], "Total": "6960.00" }] }; //llamada para la creacion Facturama.Cfdi.Create(newCfdi, function (result) { var cfdi = result; console.log("creacion de una factura", result); }, function (error) { if (error && error.responseJSON) { console.log("errores", error.responseJSON); } });
En este ejemplo se considera que facturama es una instancia de Facturama API ver en la guía
List<Currency> lstCurrencies = facturama.Catalogs().Currencies(); Currency currency = lstCurrencies.stream().filter(p -> p.getValue().equals("MXN")).findFirst().get(); // Modelo de CFDI (datos de envío) com.Facturama.sdk_java.Models.Request.Cfdi cfdi = new com.Facturama.sdk_java.Models.Request.Cfdi(); cfdi.setCfdiType( CfdiType.Ingreso.getValue() ); cfdi.setNameId(facturama.Catalogs().NameIds().get(1).getValue()); cfdi.setCfdiType( CfdiType.Ingreso.getValue() ); cfdi.setNameId(facturama.Catalogs().NameIds().get(1).getValue()); cfdi.setExpeditionPlace("78216"); cfdi.setPaymentForm(facturama.Catalogs().PaymentForms().get(3).getValue()); cfdi.setPaymentMethod("PUE"); cfdi.setCurrency(currency.getValue()); DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Date date = new Date(); cfdi.setDate(dateFormat.format(date)); Receiver receiver = new Receiver(); receiver.setName("CABIFY MEXICO S DE RL DE CV"); receiver.setCfdiUse("P01"); receiver.setRfc("CME1208017C4"); cfdi.setReceiver(receiver); List<Item> lstItems = new ArrayList<>(); Item item = new Item(); item.setProductCode("84111506"); item.setUnitCode("E48"); item.setUnit("Unidad de servicio"); item.setDescription(" API folios adicionales"); item.setIdentificationNumber("23"); item.setQuantity(100.00); item.setDiscount(10.00 ); item.setUnitPrice(0.50); item.setSubtotal(50.00); List<Tax> lstTaxes = new ArrayList<>(); Tax tax = new Tax(); tax.setName("IVA"); tax.setIsQuota(false); tax.setIsRetention(false); tax.setRate( 0.160000d ); tax.setBase( 40 ); tax.setTotal(6.4); lstTaxes.add(tax); item.setTaxes(lstTaxes); item.setTotal(46.40); lstItems.add(item); Item item2 = new Item(); item2.setProductCode("84111506"); item2.setUnitCode("E48"); item2.setUnit("Unidad de servicio"); item2.setDescription(" API Implementación"); item2.setIdentificationNumber("21"); item2.setQuantity(1); item2.setUnitPrice(6000.00); item2.setSubtotal(6000.00); List<Tax> lstTaxes2 = new ArrayList<>(); Tax tax2 = new Tax(); tax2.setName("IVA"); tax2.setIsQuota(false); tax2.setIsRetention(false); tax2.setRate( 0.160000d ); tax2.setBase( 6000 ); tax2.setTotal(960); lstTaxes2.add(tax2); item2.setTaxes(lstTaxes2); item2.setTotal(6960); lstItems.add(item2); cfdi.setItems(lstItems); // Creación del CFDI mediante la API (Modelo con datos de respuesta) com.Facturama.sdk_java.Models.Response.Cfdi cfdiCreated = facturama.Cfdis().Create(cfdi);
En este ejemplo se considera que facturama es una instancia de Facturama API ver en la guía
var cfdi = new Cfdi { Receiver = new Receiver { Name = "CABIFY MEXICO S DE RL DE CV", CfdiUse = "P01", Rfc = "CME1208017C4" }, CfdiType = CfdiType.Ingreso, NameId = "1", ExpeditionPlace = "78216", PaymentForm = "03", PaymentMethod = "PUE", Currency = "MXN", Items = new List<Item> { new Item { Quantity = 100, ProductCode = "84111506", UnitCode = "E48", Unit = "Unidad de servicio", Description = " API folios adicionales", IdentificationNumber = "23", UnitPrice = 0.50m, Subtotal = 50.00m, Discount = 10.00m, Taxes = new List<Tax> { new Tax { Name = "IVA", Rate = 0.16m, Total = 6.4m, Base = 40.00m, IsRetention = false } }, Total = 46.40m }, new Item { Quantity = 1, ProductCode = "84111506", UnitCode = "E48", Unit = "Unidad de servicio", Description = " API Implementación ", IdentificationNumber = "21", UnitPrice = 6000.00m, Subtotal = 6000.00m, Taxes = new List<Tax> { new Tax { Name = "IVA", Rate = 0.16m, Total = 960.00m, Base = 6000.00m, IsRetention = false } }, Total = 6960.00m } } };
newCfdi = { "Receiver": { "Name": "CABIFY MEXICO S DE RL DE CV", "CfdiUse": "P01", "Rfc": "CME1208017C4", "TaxRegistrationNumber": "undefined", "TaxResidence": "undefined", "Id": "JJdtYbC2m2mB8sc3rT8S-w2" }, "CfdiType": "I", "NameId": "1", "ExpeditionPlace": "78216", "PaymentForm": "03", "PaymentMethod": "PUE", "Decimals": "2", "Currency": "MXN", "Date": "2018-04-16T09:51:39", "Items": [ { "Quantity": "100", "ProductCode": "84111506", "UnitCode": "E48", "Unit": "Unidad de servicio", "Description": " API folios adicionales", "IdentificationNumber": "23", "UnitPrice": "0.50", "Subtotal": "50.00", "Discount": "10", "Taxes": [ { "Name": "IVA", "Rate": "0.16", "Total": "6.4", "Base": "40", "IsRetention": "false" }], "Total": "46.40" }, { "Quantity": "1", "ProductCode": "84111506", "UnitCode": "E48", "Unit": "Unidad de servicio", "Description": " API Implementación ", "IdentificationNumber": "21", "UnitPrice": "6000.00", "Subtotal": "6000.00", "Taxes": [ { "Name": "IVA", "Rate": "0.16", "Total": "960", "Base": "6000", "IsRetention": "false" }], "Total": "6960.00" }] } #llamada para la creacion try: cfdi = client.Cfdi.create(newCfdi.copy()) print "se creo factura", cfdi except Exception, ex: print "Error al crear factura", ex