Crear CFDIs mediante API Multiemisor

Ruby
PHP
Javascript
.Net >= 4.5
Java
Phyton

Al usar la API Multiemisor, se tiene la ventaja de poder crear CFDIs desde diferentes Emisores,
siempre y cuando se tengan los sellos digitales (CSD) de cada uno de los RFCs con los que se desea emitir CFDIs

La creación de un CFDI en la modalidad multiemisor es muy similar (casi identica) que el API Web ver en la guía
Solo se diferencían en:

  • Aquí se agrega el Nodo Issuer, que contiene la información del Emisor
  • Aquí se agrega el campo de Folio para especificar el folio
Puedes ver en la documentación de la API referente a este tipo de CFDI

Datos generales

Se puede especificar el folio según se desee. (El único campo que se diferencía respecto ala API Web)

Datos generales

    "NameId": "1",          
    "CfdiType": Facturama::CfdiType::INGRESO,
    "ExpeditionPlace": "78116",
    "PaymentForm": "03",    
    "PaymentMethod": "PUE",        
    "Currency": "MXN",    
    "Folio": "100",
        

Datos generales

    'NameId' => '1',
    'CfdiType' => 'I',
    'ExpeditionPlace' => '78116',
    'PaymentForm' => '03',
    'PaymentMethod' => 'PUE',
    'Currency' => 'MXN',    
    'Folio' => '100',

Datos generales

    "NameId": "1",
    "CfdiType": "I",      
    "ExpeditionPlace": "78116",
    "PaymentForm": "03",
    "PaymentMethod": "PUE",    
    "Currency": "MXN",    
    "Folio": "100",
        

Datos generales

        
    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());    
    cfdi.setFolio("100");

Datos generales

    NameId = "1",
    CfdiType = CfdiType.Ingreso,
    ExpeditionPlace = "78116",
    PaymentForm = "03",
    PaymentMethod = "PUE",
    Currency = "MXN",
    Folio = "100",

Datos generales

    
    "NameId": "1",
    "CfdiType": "I",
    "ExpeditionPlace": "78116",
    "PaymentForm": "03",
    "PaymentMethod": "PUE",    
    "Currency": "MXN",
    "Folio": "100",

Emisor

Es quien expide el CFDI. En la estructura es representado por un nodo que se coloca en el atributo Issuer
puedes ver en la documentación de la API

Regimenes Fiscales ver en la guía
Nombre del Emisor
Clave del Registro Federal de Contribuyentes del Emisor (recuerda que debes tener los CSD del RFC cargados) ver en la guía

Datos del receptor

    "Issuer": {
        "FiscalRegime": "601",
        "Rfc": "AAA010101AAA",
        "Name": "EXPRESION EN SOFTWARE"
    },
        

Datos del receptor

    
    'Issuer' => [
        'FiscalRegime' => '601',
        'Rfc' => 'AAA010101AAA',
        'Name' => 'EXPRESION EN SOFTWARE'        
    ],          
        

Datos del receptor

    "Issuer": {
        "FiscalRegime": "601",
        "Rfc": "AAA010101AAA",
        "Name": "EXPRESION EN SOFTWARE"
    },    
        

Datos del receptor

        
    Issuer  issuer = new Issuer();

    issuer.setName("EXPRESION EN SOFTWARE");
    issuer.setFiscalRegime("601");
    issuer.setRfc("AAA010101AAA");    

    cfdi.setIssuer(issuer);

Datos del receptor

    Issuer = new Issuer
    {
        Name = "EXPRESION EN SOFTWARE",
        FiscalRegime = "601",
        Rfc = "AAA010101AAA",        
    },

Datos del receptor

    
    "Issuer": {
            "FiscalRegime": "601",
            "Name": "EXPRESION EN SOFTWARE",
            "Rfc": "AAA010101AAA"
        },

La forma completa del ejemplo es

CFDI Factura

    cfdi = {
        "NameId": "1",          
        "PaymentForm": "03",
        "PaymentMethod": "PUE",
        "CfdiType": Facturama::CfdiType::INGRESO,        
        "Currency": "MXN",
        "Decimals": "2",
        "ExpeditionPlace": "78116",
        "Issuer": {
                "FiscalRegime": "601",
                "Rfc": "AAA010101AAA",
                "Name": "EXPRESION EN SOFTWARE"
        },
        "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 Factura

    var $params = {
        "Issuer" => {
            "FiscalRegime" => "601",
            "Rfc" => "AAA010101AAA",
            "Name" => "EXPRESION EN SOFTWARE"
        }, 
        "Receiver" => {
            "Name" => "CABIFY MEXICO S DE RL DE CV",
            "CfdiUse" => "P01",
            "Rfc" => "CME1208017C4"        
        },
        "CfdiType" => "I",
        "NameId" => "1",
        "ExpeditionPlace" => "78216",
        "PaymentForm" => "03",
        "PaymentMethod" => "PUE",    
        "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

CFDI Factura

    var newCfdi = {
        "Issuer": {
            "FiscalRegime": "601",
            "Rfc": "AAA010101AAA",
            "Name": "EXPRESION EN SOFTWARE"
        }, 
        "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

CFDI Factura

    
    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));

    Issuer  issuer = new Issuer();
    issuer.setName("EXPRESION EN SOFTWARE");
    issuer.setFiscalRegime("601");
    issuer.setRfc("AAA010101AAA");    
    cfdi.setIssuer(issuer);

    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

CFDI Factura

    var cfdi = new Cfdi
    {
        Issuer = new Issuer
        {
            Name = "EXPRESION EN SOFTWARE",
            FiscalRegime = "601",
            Rfc = "AAA010101AAA",        
        },
        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
            }
        }
    };

CFDI Factura

    newCfdi = {
        "Issuer": {
            "FiscalRegime": "601",
            "Name": "EXPRESION EN SOFTWARE",
            "Rfc": "AAA010101AAA"
        },
        "Receiver": {
            "Name": "CABIFY MEXICO S DE RL DE CV",
            "CfdiUse": "P01",
            "Rfc": "CME1208017C4",            
            "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