Skip to content

Commit feeed9b

Browse files
committed
Version 5.0.15 Descarga de retenciones e informacion de pagos
1 parent c056043 commit feeed9b

File tree

6 files changed

+91
-10
lines changed

6 files changed

+91
-10
lines changed

IXmlDownloaderService.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,16 +70,25 @@ public interface IXmlDownloaderService
7070
/// <returns>AuthResponse</returns>
7171
Task<AuthResponse> AuthenticateAsync(string base64Cer, string base64Key, string password,
7272
ServiceEndpoints? endpoints = null, CancellationToken cancellationToken = default);
73+
/// <summary>
74+
/// Authenticates the user with SAT and retrieves an authentication token given the Fiel credential.
75+
/// </summary>
76+
/// <param name="credential"></param>
77+
/// <param name="endpoints">Service endpoints to use for authentication. Defaults to CFDI endpoints if null.</param>
78+
/// <param name="cancellationToken"></param>
79+
/// <returns>AuthResponse</returns>
80+
Task<AuthResponse> AuthenticateAsync(ICredential credential, ServiceEndpoints? endpoints = null, CancellationToken cancellationToken = default);
7381

7482

7583
/// <summary>
76-
/// Authenticates the user with SAT and retrieves an authentication token given the Fiel credential.
84+
/// Authenticates the user to CFDI endpoints with SAT and retrieves an authentication token given the Fiel credential.
7785
/// </summary>
7886
/// <param name="credential"></param>
7987
/// <param name="cancellationToken"></param>
8088
/// <returns>AuthResponse</returns>
8189
Task<AuthResponse> AuthenticateAsync(ICredential credential, CancellationToken cancellationToken = default);
8290

91+
8392
/// <summary>
8493
/// Creates a 'download request' to the SAT with the specified query parameters.
8594
/// </summary>

Query/Models/QueryParameters.cs

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
* ============================================================================
1515
*/
1616

17+
using Fiscalapi.XmlDownloader.Common.Enums;
18+
using Fiscalapi.XmlDownloader.Common.Http;
19+
1720
namespace Fiscalapi.XmlDownloader.Query.Models;
1821

1922
public class QueryParameters
@@ -50,4 +53,68 @@ public class QueryParameters
5053

5154
// 'RfcACuentaTerceros' attribute
5255
public string? ThirdPartyTin { get; set; }
56+
57+
58+
public void Validate(ServiceEndpoints endpoints)
59+
{
60+
// Check: No se permite la descarga de retenciones en el servicio de CFDI | Metadatos.
61+
if (RequestType == QueryType.Retenciones && endpoints.ServiceType != ServiceType.Retenciones)
62+
{
63+
throw new InvalidOperationException(
64+
$"No se permite la descarga de retenciones en el servicio de CFDI | Metadatos.");
65+
}
66+
67+
// Check: No se permite la descarga de CFDI | Metadatos en el servicio de retenciones.
68+
if (RequestType is QueryType.CFDI or QueryType.Metadata && endpoints.ServiceType != ServiceType.Cfdi)
69+
{
70+
throw new InvalidOperationException(
71+
$"No se permite la descarga de CFDI | Metadatos en el servicio de retenciones.");
72+
}
73+
74+
// Check: No se permite la descarga de retenciones canceladas
75+
if (RequestType == QueryType.Retenciones && InvoiceStatus == InvoiceStatus.Cancelado)
76+
{
77+
throw new InvalidOperationException($"No se permite la descarga de retenciones cancelados.");
78+
}
79+
80+
// Check: No se permite la descarga de CFDI recibidos cancelados.
81+
if (RequestType == QueryType.CFDI && RecipientTin is not null && InvoiceStatus == InvoiceStatus.Cancelado)
82+
{
83+
throw new InvalidOperationException($"No se permite la descarga de CFDI recibidos cancelados.");
84+
}
85+
}
86+
87+
// Method to know what ServiceType is using this QueryParameters
88+
public ServiceEndpoints GetServiceEndpoints()
89+
{
90+
return RequestType switch
91+
{
92+
QueryType.CFDI => ServiceEndpoints.Cfdi(),
93+
QueryType.Metadata => ServiceEndpoints.Cfdi(),
94+
QueryType.Retenciones => ServiceEndpoints.Retenciones(),
95+
_ => throw new InvalidOperationException("Tipo de solicitud no válido.")
96+
};
97+
}
98+
99+
public bool IsCfdiServiceType()
100+
{
101+
return RequestType switch
102+
{
103+
QueryType.CFDI => true,
104+
QueryType.Metadata => true,
105+
QueryType.Retenciones => false,
106+
_ => throw new InvalidOperationException("Tipo de solicitud no válido.")
107+
};
108+
}
109+
110+
public bool IsRetencionesServiceType()
111+
{
112+
return RequestType switch
113+
{
114+
QueryType.CFDI => false,
115+
QueryType.Metadata => false,
116+
QueryType.Retenciones => true,
117+
_ => throw new InvalidOperationException("Tipo de solicitud no válido.")
118+
};
119+
}
53120
}

Query/QueryService.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ public QueryService(ILogger<QueryService> logger)
6161
public async Task<QueryResponse> CreateAsync(ICredential credential, Token authToken,
6262
QueryParameters parameters, ServiceEndpoints endpoints, ILogger logger, CancellationToken cancellationToken = default)
6363
{
64+
parameters.Validate(endpoints);
65+
6466
var operationType = DetermineOperationType(parameters);
6567
var toDigest = CreateDigest(parameters, operationType);
6668
var signature = CreateSignature(credential, toDigest);

XmlDownloader.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<TargetFramework>net8.0</TargetFramework>
55
<ImplicitUsings>enable</ImplicitUsings>
66
<Nullable>enable</Nullable>
7-
<Version>5.0.13</Version>
7+
<Version>5.0.15</Version>
88
<AssemblyVersion>$(Version)</AssemblyVersion>
99
<FileVersion>$(Version)</FileVersion>
1010
<PackageVersion>$(Version)</PackageVersion>

XmlDownloader.sln

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio Version 18
4-
VisualStudioVersion = 18.0.11217.181 d18.0
4+
VisualStudioVersion = 18.0.11217.181
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "XmlDownloader", "XmlDownloader.csproj", "{DB606B95-4DFD-41A1-85E8-1B7E6102129B}"
77
EndProject
8-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "XmlDownloaderClient", "..\XmlDownloaderClient\XmlDownloaderClient.csproj", "{9B823821-C180-48C4-99BE-F1B3F66FE9D1}"
9-
EndProject
108
Global
119
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1210
Debug|Any CPU = Debug|Any CPU
@@ -17,10 +15,6 @@ Global
1715
{DB606B95-4DFD-41A1-85E8-1B7E6102129B}.Debug|Any CPU.Build.0 = Debug|Any CPU
1816
{DB606B95-4DFD-41A1-85E8-1B7E6102129B}.Release|Any CPU.ActiveCfg = Release|Any CPU
1917
{DB606B95-4DFD-41A1-85E8-1B7E6102129B}.Release|Any CPU.Build.0 = Release|Any CPU
20-
{9B823821-C180-48C4-99BE-F1B3F66FE9D1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21-
{9B823821-C180-48C4-99BE-F1B3F66FE9D1}.Debug|Any CPU.Build.0 = Debug|Any CPU
22-
{9B823821-C180-48C4-99BE-F1B3F66FE9D1}.Release|Any CPU.ActiveCfg = Release|Any CPU
23-
{9B823821-C180-48C4-99BE-F1B3F66FE9D1}.Release|Any CPU.Build.0 = Release|Any CPU
2418
EndGlobalSection
2519
GlobalSection(SolutionProperties) = preSolution
2620
HideSolutionNode = FALSE

XmlDownloaderService.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,15 @@ public async Task<AuthResponse> AuthenticateAsync(string base64Cer, string base6
223223
return await AuthenticateAsync(credential, cancellationToken);
224224
}
225225

226+
public Task<AuthResponse> AuthenticateAsync(ICredential credential, ServiceEndpoints? endpoints = null,
227+
CancellationToken cancellationToken = default)
228+
{
229+
// Set service endpoints before authenticating (default to CFDI if not specified)
230+
_serviceEndpoints = endpoints ?? ServiceEndpoints.Cfdi();
231+
Credential = credential;
232+
return AuthenticateAsync(credential, cancellationToken);
233+
}
234+
226235
/// <summary>
227236
/// Authenticate with a FiscalAPI credential.
228237
/// See https://github.com/FiscalAPI/fiscalapi-credentials-net for more information.
@@ -286,7 +295,7 @@ public async Task<QueryResponse> CreateRequestAsync(QueryParameters parameters,
286295
Token == null,
287296
Credential == null);
288297
}
289-
298+
290299
EnsureAuthToken();
291300

292301
_logger.LogInformation("Creating download request for RFC: {Rfc}, ServiceType: {ServiceType}",

0 commit comments

Comments
 (0)