diff --git a/src/Axepta.SDK/Entities/Response/TransactionResponse.cs b/src/Axepta.SDK/Entities/Response/TransactionResponse.cs new file mode 100644 index 0000000..6def704 --- /dev/null +++ b/src/Axepta.SDK/Entities/Response/TransactionResponse.cs @@ -0,0 +1,7 @@ +namespace Axepta.SDK; + +public sealed record TransactionResponse +{ + [JsonPropertyName("data")] + public required Data Data { get; init; } +} \ No newline at end of file diff --git a/src/Axepta.SDK/Extensions.cs b/src/Axepta.SDK/Extensions.cs index 93fdde7..90176d9 100644 --- a/src/Axepta.SDK/Extensions.cs +++ b/src/Axepta.SDK/Extensions.cs @@ -58,6 +58,39 @@ IConfiguration cfg return services; } + internal static async Task GetAsync( + this HttpClient http, + string url, + CancellationToken ct = default + ) + { + HttpResponseMessage? httpRes = null; + + var httpResContentAsJson = async () => httpRes is null ? + string.Empty : + await httpRes.Content.ReadAsStringAsync(ct); + + try + { + httpRes = await http.GetAsync( + url, + ct + ); + + httpRes.EnsureSuccessStatusCode(); + + return (T)JsonSerializer.Deserialize( + await httpResContentAsJson().ConfigureAwait(false), + typeof(T), + _sourceGenOptions + )!; + } + catch (HttpRequestException) + { + throw new AxeptaException(await httpResContentAsJson().ConfigureAwait(false)); + } + } + internal static async Task PostAsync( this HttpClient http, string url, diff --git a/src/Axepta.SDK/Services/Abstractions/IAxepta.cs b/src/Axepta.SDK/Services/Abstractions/IAxepta.cs index 7f51cb9..02f5126 100644 --- a/src/Axepta.SDK/Services/Abstractions/IAxepta.cs +++ b/src/Axepta.SDK/Services/Abstractions/IAxepta.cs @@ -29,4 +29,17 @@ Task CreateRefundAsync( Refund refund, CancellationToken ct = default ); + + /// + /// Retrieves the details of a specific transaction asynchronously. + /// + /// The unique identifier of the transaction to retrieve. + /// An optional cancellation token to cancel the request. + /// + /// A task that represents the asynchronous operation. The task result contains the object with the details of the requested transaction. + /// + Task GetTransactionAsync( + Guid transactionId, + CancellationToken ct = default + ); } diff --git a/src/Axepta.SDK/Services/Axepta.cs b/src/Axepta.SDK/Services/Axepta.cs index b560467..5ec2285 100644 --- a/src/Axepta.SDK/Services/Axepta.cs +++ b/src/Axepta.SDK/Services/Axepta.cs @@ -22,4 +22,13 @@ public Task CreateRefundAsync( refund, ct ); + + public async Task GetTransactionAsync( + Guid transationId, + CancellationToken ct = default + ) + => (await http.GetAsync( + $"transaction/{transationId}", + ct + )).Data.Transaction!; } \ No newline at end of file