Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [4.10.0] - 2025-09-04

### Added

- Add `Invoices.PreviewPdfAsync` method to preview invoice PDF before stamping.

## [4.9.1] - 2025-07-21

### Fixed
Expand Down
5 changes: 5 additions & 0 deletions Router/InvoiceRouter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,10 @@ public static string CopyInvoice(string id)
{
return $"invoices/{id}/copy";
}

public static string PreviewPdf(Dictionary<string, object> query = null)
{
return UriWithQuery("invoices/preview/pdf", query);
}
}
}
13 changes: 13 additions & 0 deletions Wrappers/InvoiceWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,5 +183,18 @@ public async Task<Invoice> CopyToDraftAsync(string id)
var invoice = JsonConvert.DeserializeObject<Invoice>(resultString, this.jsonSettings);
return invoice;
}

public async Task<Stream> PreviewPdfAsync(Dictionary<string, object> query = null)
{
var response = await client.GetAsync(Router.PreviewPdf(query));
if (!response.IsSuccessStatusCode)
{
var resultString = await response.Content.ReadAsStringAsync();
var error = JsonConvert.DeserializeObject<JObject>(resultString, this.jsonSettings);
throw new FacturapiException(error["message"].ToString());
Copy link

Copilot AI Sep 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Potential null reference exception if the response JSON doesn't contain a 'message' field. The code should check if error['message'] exists before calling ToString().

Copilot uses AI. Check for mistakes.
}
var stream = await response.Content.ReadAsStreamAsync();
return stream;
Comment on lines +189 to +197
Copy link

Copilot AI Sep 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method doesn't dispose of the HTTP response, which can lead to resource leaks. The response should be wrapped in a using statement or the stream should be copied to avoid keeping the HTTP connection open.

Suggested change
var response = await client.GetAsync(Router.PreviewPdf(query));
if (!response.IsSuccessStatusCode)
{
var resultString = await response.Content.ReadAsStringAsync();
var error = JsonConvert.DeserializeObject<JObject>(resultString, this.jsonSettings);
throw new FacturapiException(error["message"].ToString());
}
var stream = await response.Content.ReadAsStreamAsync();
return stream;
using (var response = await client.GetAsync(Router.PreviewPdf(query)))
{
if (!response.IsSuccessStatusCode)
{
var resultString = await response.Content.ReadAsStringAsync();
var error = JsonConvert.DeserializeObject<JObject>(resultString, this.jsonSettings);
throw new FacturapiException(error["message"].ToString());
}
var responseStream = await response.Content.ReadAsStreamAsync();
var memoryStream = new MemoryStream();
await responseStream.CopyToAsync(memoryStream);
memoryStream.Position = 0;
return memoryStream;
}

Copilot uses AI. Check for mistakes.
}
}
}
2 changes: 1 addition & 1 deletion facturapi-net.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
API Keys creando una cuenta gratuita en https://www.facturapi.io</Summary>
<PackageTags>factura factura-electronica cfdi facturapi mexico conekta</PackageTags>
<Title>Facturapi</Title>
<Version>4.9.1</Version>
<Version>4.10.0</Version>
<PackageVersion>$(Version)</PackageVersion>
<Owners>Facturapi</Owners>
<ApplicationIcon>facturapi.ico</ApplicationIcon>
Expand Down