Skip to content

Commit 9369caa

Browse files
authored
Merge pull request #324 from OpenAC-Net/correção-ipm
correção-ipm
2 parents 2e7b896 + f4593e3 commit 9369caa

18 files changed

Lines changed: 16524 additions & 16225 deletions

File tree

.github/workflows/publish.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ jobs:
3434
- name: Setup .NET
3535
uses: actions/setup-dotnet@v4
3636
with:
37-
dotnet-version: '8.x'
37+
dotnet-version: |
38+
8.x
39+
9.x
3840
- run: dotnet msbuild OpenAC.Net.NFSe.sln -property:Configuration=Release -property:platform="Any CPU"
3941
working-directory: src
4042
- run: dotnet pack --configuration Release --output ${{ env.NuGetDirectory }}

src/OpenAC.Net.NFSe.DANFSe.FastReport.OpenSource/OpenAC.Net.NFSe.DANFSe.FastReport.OpenSource.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@
4343
</ItemGroup>
4444

4545
<ItemGroup>
46-
<PackageReference Include="FastReport.OpenSource" Version="2025.1.0" />
47-
<PackageReference Include="FastReport.OpenSource.Export.PdfSimple" Version="2025.1.0" />
46+
<PackageReference Include="FastReport.OpenSource" Version="2025.2.0" />
47+
<PackageReference Include="FastReport.OpenSource.Export.PdfSimple" Version="2025.2.0" />
4848
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0">
4949
<PrivateAssets>all</PrivateAssets>
5050
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
@@ -79,11 +79,11 @@
7979
</ItemGroup>
8080

8181
<ItemGroup Condition="'$(TargetFramework)' == 'net6.0-windows'">
82-
<PackageReference Include="System.Drawing.Common" Version="9.0.3" />
82+
<PackageReference Include="System.Drawing.Common" Version="9.0.6" />
8383
</ItemGroup>
8484

8585
<ItemGroup Condition="'$(TargetFramework)' == 'net8.0-windows'">
86-
<PackageReference Include="System.Drawing.Common" Version="9.0.3" />
86+
<PackageReference Include="System.Drawing.Common" Version="9.0.6" />
8787
</ItemGroup>
8888

8989
</Project>

src/OpenAC.Net.NFSe.DANFSe.QuestPdf/OpenAC.Net.NFSe.DANFSe.QuestPdf.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
</ItemGroup>
5656

5757
<ItemGroup>
58-
<PackageReference Include="QuestPDF" Version="2025.1.7" />
58+
<PackageReference Include="QuestPDF" Version="2025.5.1" />
5959
</ItemGroup>
6060

6161
<ItemGroup>

src/OpenAC.Net.NFSe.Demo/OpenAC.Net.NFSe.Demo.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
</PropertyGroup>
1212

1313
<ItemGroup>
14-
<PackageReference Include="NLog" Version="5.4.0" />
15-
<PackageReference Include="NLog.Windows.Forms" Version="5.2.3" />
14+
<PackageReference Include="NLog" Version="5.5.0" />
15+
<PackageReference Include="NLog.Windows.Forms" Version="5.2.4" />
1616
<PackageReference Include="OpenAC.Net.Core" Version="1.6.0" />
1717
<PackageReference Include="OpenAC.Net.DFe.Core" Version="1.6.0.2" />
18-
<PackageReference Include="System.Text.Encoding.CodePages" Version="9.0.3" />
18+
<PackageReference Include="System.Text.Encoding.CodePages" Version="9.0.6" />
1919
</ItemGroup>
2020

2121
<ItemGroup>

src/OpenAC.Net.NFSe.Test/OpenAC.Net.NFSe.Test.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<ItemGroup>
1313
<PackageReference Include="OpenAC.Net.DFe.Core" Version="1.6.0.2" />
1414
<PackageReference Include="xunit" Version="2.9.3" />
15-
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.2">
15+
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.1">
1616
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1717
<PrivateAssets>all</PrivateAssets>
1818
</PackageReference>

src/OpenAC.Net.NFSe/Commom/Client/NFSeHttpServiceClient.cs

Lines changed: 102 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -47,29 +47,55 @@
4747

4848
namespace OpenAC.Net.NFSe.Commom.Client;
4949

50+
/// <summary>
51+
/// Classe base abstrata para clientes de serviço HTTP utilizados na comunicação com provedores de NFSe.
52+
/// Responsável por gerenciar requisições HTTP, autenticação, manipulação de certificados digitais,
53+
/// gravação de arquivos de envio e retorno, além de permitir customizações para validação de certificados
54+
/// e autenticação.
55+
/// </summary>
56+
/// <remarks>
57+
/// Deve ser herdada por classes concretas que implementam a comunicação HTTP específica de cada provedor de NFSe,
58+
/// podendo sobrescrever métodos para autenticação e validação de certificados conforme necessário.
59+
/// </remarks>
5060
public abstract class NFSeHttpServiceClient : IDisposable
5161
{
5262
#region Inner Types
5363

64+
/// <summary>
65+
/// Esquemas de autenticação suportados para requisições HTTP.
66+
/// </summary>
5467
public enum AuthScheme
5568
{
56-
[DFeEnum("Basic")]
69+
/// <summary>
70+
/// Sem autenticação.
71+
/// </summary>
72+
[DFeEnum("None")]
73+
None,
74+
75+
/// <summary>
76+
/// Autenticação Basic.
77+
/// </summary>
78+
[DFeEnum("Basic")]
5779
Basic,
58-
59-
[DFeEnum("Bearer")]
80+
81+
/// <summary>
82+
/// Autenticação Bearer (Token).
83+
/// </summary>
84+
[DFeEnum("Bearer")]
6085
Bearer,
6186
}
6287

6388
#endregion Inner Types
64-
89+
6590
#region Constructors
6691

6792
/// <summary>
6893
///
6994
/// </summary>
7095
/// <param name="provider"></param>
7196
/// <param name="tipoUrl"></param>
72-
protected NFSeHttpServiceClient(ProviderBase provider, TipoUrl tipoUrl) : this(provider, tipoUrl, provider.Certificado)
97+
protected NFSeHttpServiceClient(ProviderBase provider, TipoUrl tipoUrl) : this(provider, tipoUrl,
98+
provider.Certificado)
7399
{
74100
}
75101

@@ -141,7 +167,7 @@ protected NFSeHttpServiceClient(ProviderBase provider, TipoUrl tipoUrl, X509Cert
141167
PrefixoEnvio = "aut-nfse";
142168
PrefixoResposta = "aut-nfse";
143169
break;
144-
170+
145171
default:
146172
throw new ArgumentOutOfRangeException(nameof(tipoUrl), tipoUrl, null);
147173
}
@@ -153,47 +179,93 @@ protected NFSeHttpServiceClient(ProviderBase provider, TipoUrl tipoUrl, X509Cert
153179

154180
#region Properties
155181

182+
/// <summary>
183+
/// Prefixo utilizado para gerar o nome do arquivo de envio.
184+
/// </summary>
156185
public string PrefixoEnvio { get; }
157186

187+
/// <summary>
188+
/// Prefixo utilizado para gerar o nome do arquivo de resposta.
189+
/// </summary>
158190
public string PrefixoResposta { get; }
159191

192+
/// <summary>
193+
/// Envelope XML que será enviado na requisição HTTP.
194+
/// </summary>
160195
public string EnvelopeEnvio { get; protected set; } = "";
161196

197+
/// <summary>
198+
/// Envelope XML que será recebido na resposta da requisição HTTP.
199+
/// </summary>
162200
public string EnvelopeRetorno { get; protected set; } = "";
163201

202+
/// <summary>
203+
/// Instância do provedor de NFSe associado a este cliente HTTP.
204+
/// </summary>
164205
public ProviderBase Provider { get; set; }
165206

207+
/// <summary>
208+
/// Indica se o ambiente configurado para o provedor é de homologação.
209+
/// </summary>
166210
public bool EhHomologacao => Provider.Configuracoes.WebServices.Ambiente == DFeTipoAmbiente.Homologacao;
167211

212+
/// <summary>
213+
/// URL do serviço HTTP utilizado para comunicação com o provedor de NFSe.
214+
/// </summary>
168215
protected string Url { get; set; }
169216

217+
/// <summary>
218+
/// Certificado digital utilizado para autenticação do cliente HTTP, se necessário.
219+
/// </summary>
170220
protected X509Certificate2? Certificado { get; set; }
171221

222+
/// <summary>
223+
/// Indica se o objeto já foi descartado (disposed).
224+
/// </summary>
172225
protected bool IsDisposed { get; private set; }
173226

174-
protected AuthScheme AuthenticationScheme { get; set; } = AuthScheme.Basic;
227+
/// <summary>
228+
/// Esquema de autenticação utilizado nas requisições HTTP.
229+
/// </summary>
230+
protected AuthScheme AuthenticationScheme { get; set; } = AuthScheme.None;
175231

232+
/// <summary>
233+
/// Define o encoding (conjunto de caracteres) utilizado nas requisições HTTP.
234+
/// O padrão é UTF-8, mas pode ser alterado conforme a necessidade do provedor ou integração.
235+
/// </summary>
176236
protected Encoding Charset { get; set; } = Encoding.UTF8;
177237

178238
#endregion Properties
179239

180240
#region Methods
181241

242+
/// <summary>
243+
/// Executa uma requisição HTTP GET utilizando as configurações do cliente.
244+
/// </summary>
182245
protected void ExecuteGet()
183246
{
184247
Execute(null, HttpMethod.Get);
185248
}
186-
249+
250+
/// <summary>
251+
/// Executa uma requisição HTTP POST utilizando as configurações do cliente.
252+
/// </summary>
253+
/// <param name="content">Conteúdo HTTP a ser enviado na requisição POST.</param>
187254
protected void ExecutePost(HttpContent content)
188255
{
189256
Execute(content, HttpMethod.Post);
190257
}
191258

259+
/// <summary>
260+
/// Executa uma requisição HTTP utilizando o método e conteúdo especificados.
261+
/// </summary>
262+
/// <param name="content">Conteúdo HTTP a ser enviado na requisição (pode ser nulo para métodos que não enviam corpo).</param>
263+
/// <param name="method">Método HTTP a ser utilizado (GET, POST, etc).</param>
192264
protected void Execute(HttpContent? content, HttpMethod method)
193265
{
194266
try
195267
{
196-
if(content == null && method == HttpMethod.Post) throw new ArgumentNullException(nameof(content));
268+
if (content == null && method == HttpMethod.Post) throw new ArgumentNullException(nameof(content));
197269

198270
if (!EnvelopeEnvio.IsEmpty())
199271
GravarEnvio(EnvelopeEnvio, $"{DateTime.Now:yyyyMMddssfff}_{PrefixoEnvio}_envio.xml");
@@ -228,9 +300,12 @@ protected void Execute(HttpContent? content, HttpMethod method)
228300
request.Headers.UserAgent.Add(productValue);
229301
request.Headers.UserAgent.Add(commentValue);
230302

231-
var auth = Authentication();
232-
if (!auth.IsEmpty())
233-
request.Headers.Authorization = new AuthenticationHeaderValue(AuthenticationScheme.GetDFeValue(), auth);
303+
request.Headers.Authorization = AuthenticationScheme switch
304+
{
305+
AuthScheme.Basic or AuthScheme.Bearer => new AuthenticationHeaderValue(
306+
AuthenticationScheme.GetDFeValue(), Authentication()),
307+
_ => request.Headers.Authorization
308+
};
234309

235310
if (content != null)
236311
request.Content = content;
@@ -247,8 +322,20 @@ protected void Execute(HttpContent? content, HttpMethod method)
247322
}
248323
}
249324

325+
/// <summary>
326+
/// Retorna a string de autenticação para ser utilizada no cabeçalho da requisição HTTP.
327+
/// Pode ser sobrescrito em classes derivadas para fornecer o token ou credencial apropriada,
328+
/// dependendo do esquema de autenticação configurado.
329+
/// </summary>
330+
/// <returns>String de autenticação ou vazia se não houver autenticação.</returns>
250331
protected virtual string Authentication() => "";
251332

333+
/// <summary>
334+
/// Valida o certificado do servidor durante a comunicação HTTP.
335+
/// Pode ser sobrescrito para implementar validação personalizada do certificado.
336+
/// Retorna <c>true</c> para validar normalmente, ou <c>false</c> para ignorar a validação.
337+
/// </summary>
338+
/// <returns><c>true</c> se a validação do certificado do servidor deve ser realizada; caso contrário, <c>false</c>.</returns>
252339
protected virtual bool ValidarCertificadoServidor() => true;
253340

254341
/// <summary>
@@ -261,7 +348,8 @@ protected virtual void GravarEnvio(string conteudoArquivo, string nomeArquivo)
261348
{
262349
if (Provider.Configuracoes.WebServices.Salvar == false) return;
263350

264-
var path = Provider.Configuracoes.Arquivos.GetPathSoap(DateTime.Now, Provider.Configuracoes.PrestadorPadrao.CpfCnpj);
351+
var path = Provider.Configuracoes.Arquivos.GetPathSoap(DateTime.Now,
352+
Provider.Configuracoes.PrestadorPadrao.CpfCnpj);
265353
nomeArquivo = Path.Combine(path, nomeArquivo);
266354
File.WriteAllText(nomeArquivo, conteudoArquivo, Encoding.UTF8);
267355
}
@@ -314,4 +402,4 @@ private void Dispose(bool disposing)
314402
}
315403

316404
#endregion Methods
317-
}
405+
}

0 commit comments

Comments
 (0)