ARSoftware.Cfdi.DescargaMasiva 4.0.0-beta1

This is a prerelease version of ARSoftware.Cfdi.DescargaMasiva.
dotnet add package ARSoftware.Cfdi.DescargaMasiva --version 4.0.0-beta1
                    
NuGet\Install-Package ARSoftware.Cfdi.DescargaMasiva -Version 4.0.0-beta1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ARSoftware.Cfdi.DescargaMasiva" Version="4.0.0-beta1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ARSoftware.Cfdi.DescargaMasiva" Version="4.0.0-beta1" />
                    
Directory.Packages.props
<PackageReference Include="ARSoftware.Cfdi.DescargaMasiva" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add ARSoftware.Cfdi.DescargaMasiva --version 4.0.0-beta1
                    
#r "nuget: ARSoftware.Cfdi.DescargaMasiva, 4.0.0-beta1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package ARSoftware.Cfdi.DescargaMasiva@4.0.0-beta1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=ARSoftware.Cfdi.DescargaMasiva&version=4.0.0-beta1&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=ARSoftware.Cfdi.DescargaMasiva&version=4.0.0-beta1&prerelease
                    
Install as a Cake Tool

ARSoftware.Cfdi.DescargaMasiva

Nuget GitHub Discussions

Este proyecto es una libreria que expone clases y servicios para descargar los CFDI de forma masiva utilizando el web service del SAT.

Este proyecto te permite realizar las siguiente peticiones al web service:

  1. Peticion de Autenticacion
  2. Peticion de Solicitud
  3. Peticion de Verificacion
  4. Peticion de Descarga

Instalacion

Puedes instalarlo utilizando NuGet

dotnet add package ARSoftware.Cfdi.DescargaMasiva

Ejemplo

Agregar servicios

IHost host = Host.CreateDefaultBuilder(args)
    .ConfigureServices(services =>
    {
        // Agregar servicios de descarga masiva con el proveedor de servicios
        services.AddCfdiDescargaMasivaServices();
    })
    .Build();

Crear X509Certificate2 del certificado PFX

var rutaCertificadoPfx = @"C:\AR Software\CFDI Descarga Masiva\certificado.pfx";
var certificadoPassword = "12345678a";
byte[] certificadoPfx = await File.ReadAllBytesAsync(rutaCertificadoPfx, cancellationToken);

logger.LogInformation("Creando el certificado SAT con el certificado PFX y contrasena.");
X509Certificate2 certificadoSat = X509Certificate2Helper.GetCertificate(certificadoPfx, certificadoPassword);

Peticion De Autenticacion

logger.LogInformation("Buscando el servicio de autenticacion en el contenedor de servicios (Dependency Injection).");
var autenticacionService = host.Services.GetRequiredService<IAutenticacionService>();

logger.LogInformation("Creando solicitud de autenticacion.");
var autenticacionRequest = AutenticacionRequest.CreateInstance();

logger.LogInformation("Enviando solicitud de autenticacion.");
AutenticacionResult autenticacionResult =
    await autenticacionService.SendSoapRequestAsync(autenticacionRequest, certificadoSat, cancellationToken);

if (!autenticacionResult.AccessToken.IsValid)
{
    logger.LogError("La solicitud de autenticacion no fue exitosa. FaultCode:{0} FaultString:{1}",
        autenticacionResult.FaultCode,
        autenticacionResult.FaultString);
    throw new Exception();
}

logger.LogInformation("La solicitud de autenticacion fue exitosa. AccessToken:{0}", autenticacionResult.AccessToken.DecodedValue);

Peticion De Solicitud

// Paremetros para buscar CFDIs recibidos por rango de fecha
DateTime fechaInicio = DateTime.Today;
DateTime fechaFin = DateTime.Today;
TipoSolicitud tipoSolicitud = TipoSolicitud.Cfdi;
var rfcEmisor = "";
var rfcReceptores = new List<string> { "AAA010101AAA" };
var rfcSolicitante = "AAA010101AAA";

logger.LogInformation("Buscando el servicio de solicitud de descarga en el contenedor de servicios (Dependency Injection).");
var solicitudService = host.Services.GetRequiredService<ISolicitudService>();

logger.LogInformation("Creando solicitud de solicitud de descarga.");
var solicitudPorRangoFecha = SolicitudRequest.CreateInstance(fechaInicio,
    fechaFin,
    tipoSolicitud,
    rfcEmisor,
    rfcReceptores,
    rfcSolicitante,
    autenticacionResult.AccessToken);

logger.LogInformation("Enviando solicitud de solicitud de descarga.");
SolicitudResult solicitudResult = await solicitudService.SendSoapRequestAsync(solicitudPorRangoFecha, certificadoSat, cancellationToken);

if (string.IsNullOrEmpty(solicitudResult.RequestId))
{
    logger.LogError("La solicitud de solicitud de descarga no fue exitosa. RequestStatusCode:{0} RequestStatusMessage:{1}",
        solicitudResult.RequestStatusCode,
        solicitudResult.RequestStatusMessage);
    throw new Exception();
}

logger.LogInformation("La solicitud de solicitud de descarga fue exitosa. RequestId:{0}", solicitudResult.RequestId);

Peticion De Verificacion

logger.LogInformation("Buscando el servicio de verificacion en el contenedor de servicios (Dependency Injection).");
var verificaSolicitudService = host.Services.GetRequiredService<IVerificacionService>();

logger.LogInformation("Creando solicitud de verificacion.");
var verificacionRequest = VerificacionRequest.CreateInstance(solicitudResult.RequestId, rfcSolicitante, autenticacionResult.AccessToken);

logger.LogInformation("Enviando solicitud de verificacion.");
VerificacionResult verificacionResult = await verificaSolicitudService.SendSoapRequestAsync(verificacionRequest,
    certificadoSat,
    cancellationToken);

if (verificacionResult.DownloadRequestStatusNumber != EstadoSolicitud.Terminada.Value.ToString())
{
    logger.LogError(
        "La solicitud de verificacion no fue exitosa. DownloadRequestStatusNumber:{0} RequestStatusCode:{1} RequestStatusMessage:{2}",
        verificacionResult.DownloadRequestStatusNumber,
        verificacionResult.RequestStatusCode,
        verificacionResult.RequestStatusMessage);

    if (verificacionResult.DownloadRequestStatusNumber == EstadoSolicitud.Aceptada.Value.ToString())
        logger.LogInformation(
            "Es estado de la solicitud es Aceptada. Mandar otra solicitud de verificaion mas tarde para que el servicio web pueda procesar la solicitud.");
    else if (verificacionResult.DownloadRequestStatusNumber == EstadoSolicitud.EnProceso.Value.ToString())
        logger.LogInformation(
            "Es estado de la solicitud es En Proceso. Mandar otra solicitud de verificaion mas tarde para que el servicio web pueda procesar la solicitud.");

    throw new Exception();
}

logger.LogInformation("La solicitud de verificacion fue exitosa.");
foreach (string idsPaquete in verificacionResult.PackageIds)
    logger.LogInformation("PackageId:{0}", idsPaquete);

Peticion De Descarga

logger.LogInformation("Buscando el servicio de verificacion en el contenedor de servicios (Dependency Injection).");
var descargarSolicitudService = host.Services.GetRequiredService<IDescargaService>();

foreach (string? idsPaquete in verificacionResult.PackageIds)
{
    logger.LogInformation("Creando solicitud de descarga.");
    var descargaRequest = DescargaRequest.CreateInstace(idsPaquete, rfcSolicitante, autenticacionResult.AccessToken);

    logger.LogInformation("Enviando solicitud de descarga.");
    DescargaResult descargaResult = await descargarSolicitudService.SendSoapRequestAsync(descargaRequest,
        certificadoSat,
        cancellationToken);
    
    var rutaDescarga = @"C:\AR Software\CFDI Descarga Masiva\CFDIs";

    string fileName = Path.Combine(rutaDescarga, $"{idsPaquete}.zip");
    byte[] paqueteContenido = Convert.FromBase64String(descargaResult.Package);

    logger.LogInformation("Guardando paquete descargado en un archivo .zip en la ruta de descarga.");
    using FileStream fileStream = File.Create(fileName, paqueteContenido.Length);
    await fileStream.WriteAsync(paqueteContenido, 0, paqueteContenido.Length, cancellationToken);
}

Aplicacion De Descarga Masiva

Si buscas una aplicacion ya lista para hacer la descarga masiva de CFDIs te recomiendo mi aplicacion Manejador Documentos CFDI.

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
4.0.0-beta1 146 6/23/2025
3.0.0 2,131 4/6/2023
3.0.0-beta1 191 3/21/2023
2.1.0-beta1 184 3/16/2023
2.0.0 559 8/29/2022
2.0.0-beta.7 160 8/28/2022
2.0.0-beta.6 169 8/27/2022
2.0.0-beta.5 162 8/27/2022
2.0.0-beta.4 154 8/26/2022
2.0.0-beta.3 163 8/26/2022
2.0.0-beta.2 171 8/25/2022
2.0.0-beta 204 8/24/2022
2.0.0-alpha 203 8/20/2022
1.0.2-alpha 278 4/27/2022
1.0.1 1,005 3/10/2020 1.0.1 is deprecated because it has critical bugs.
1.0.0 881 3/7/2020 1.0.0 is deprecated because it has critical bugs.