From 7218718b1c3feb05c9bbda281266199c38d3141a Mon Sep 17 00:00:00 2001 From: abdallahbeshi Date: Wed, 4 Oct 2023 14:27:23 +0200 Subject: [PATCH] Fixed invoice error handling in the IT fiscalization --- .../UniwixClientTests.cs | 9 ++++++ .../Mews.Fiscalizations.Italy.csproj | 2 +- .../Uniwix/Communication/UniwixClient.cs | 28 +++++++++++++++---- .../Uniwix/Errors/ErrorType.cs | 5 +++- .../Mews.Fiscalizations.All.csproj | 2 +- 5 files changed, 37 insertions(+), 9 deletions(-) diff --git a/src/Italy/Mews.Fiscalizations.Italy.Tests/UniwixClientTests.cs b/src/Italy/Mews.Fiscalizations.Italy.Tests/UniwixClientTests.cs index af1ed22f..051305c3 100644 --- a/src/Italy/Mews.Fiscalizations.Italy.Tests/UniwixClientTests.cs +++ b/src/Italy/Mews.Fiscalizations.Italy.Tests/UniwixClientTests.cs @@ -51,6 +51,7 @@ public async Task SendInvoiceSucceeds() } [Test] + [Retry(3)] public async Task VerifyCredentialsSucceeds() { var client = GetUniwixClient(); @@ -61,6 +62,14 @@ public async Task VerifyCredentialsSucceeds() ); } + [Test] + public async Task GetInvoiceStateWithInvalidFileIdReturnsCorrectErrorType() + { + var client = GetUniwixClient(); + var result = await client.GetInvoiceStateAsync("InvoiceThatDoesntExist"); + Assert.AreEqual(result.Error.Get().Type, ErrorType.InvoiceNotFound); + } + private ElectronicInvoiceHeader GetInvoiceHeader(string invoiceNumber) { return new ElectronicInvoiceHeader diff --git a/src/Italy/Mews.Fiscalizations.Italy/Mews.Fiscalizations.Italy.csproj b/src/Italy/Mews.Fiscalizations.Italy/Mews.Fiscalizations.Italy.csproj index efa7db14..42901bb5 100644 --- a/src/Italy/Mews.Fiscalizations.Italy/Mews.Fiscalizations.Italy.csproj +++ b/src/Italy/Mews.Fiscalizations.Italy/Mews.Fiscalizations.Italy.csproj @@ -10,7 +10,7 @@ https://github.com/MewsSystems/fiscalizations https://raw.githubusercontent.com/msigut/eet/master/receipt.png true - 12.0.0 + 12.0.1 10 true diff --git a/src/Italy/Mews.Fiscalizations.Italy/Uniwix/Communication/UniwixClient.cs b/src/Italy/Mews.Fiscalizations.Italy/Uniwix/Communication/UniwixClient.cs index 1d21d725..f926d192 100644 --- a/src/Italy/Mews.Fiscalizations.Italy/Uniwix/Communication/UniwixClient.cs +++ b/src/Italy/Mews.Fiscalizations.Italy/Uniwix/Communication/UniwixClient.cs @@ -108,15 +108,31 @@ private Task> ExecuteRequestAsync(string url, } var errorResponse = JsonConvert.DeserializeObject>(json); - if (errorResponse.Code == -12) - { - return Try.Error(ErrorResult.Create($"{errorResponse.Code}: {errorResponse.Result}", ErrorType.FileExistsInQueue)); - } - - return Try.Error(ErrorResult.Create($"{errorResponse.Code}: {errorResponse.Result}", ErrorType.Unknown)); + return Try.Error(ErrorResult.Create($"{errorResponse.Code}: {errorResponse.Result}", MapErrorType(errorResponse.Code))); }); } + private ErrorType MapErrorType(int errorCode) + { + return errorCode.Match( + -1, _ => ErrorType.Validation, + -2, _ => ErrorType.Validation, + -3, _ => ErrorType.Validation, + -4, _ => ErrorType.InsufficientCredit, + -5, _ => ErrorType.Connection, + -6, _ => ErrorType.InvoiceNotFound, + -7, _ => ErrorType.InvoiceStatusNotFound, + -8, _ => ErrorType.Validation, + -9, _ => ErrorType.Connection, + -10, _ => ErrorType.FileNotAvailable, + -11, _ => ErrorType.Validation, + -12, _ => ErrorType.FileExistsInQueue, + -13, _ => ErrorType.Unauthorized, + -15, _ => ErrorType.FileExistsInQueue, + _ => ErrorType.Unknown + ); + } + private async Task> ExecuteRequestAsync( string url, HttpMethod httpMethod, diff --git a/src/Italy/Mews.Fiscalizations.Italy/Uniwix/Errors/ErrorType.cs b/src/Italy/Mews.Fiscalizations.Italy/Uniwix/Errors/ErrorType.cs index 2f912473..b0e85ddc 100644 --- a/src/Italy/Mews.Fiscalizations.Italy/Uniwix/Errors/ErrorType.cs +++ b/src/Italy/Mews.Fiscalizations.Italy/Uniwix/Errors/ErrorType.cs @@ -7,5 +7,8 @@ public enum ErrorType Validation, Unknown, InvoiceNotFound, - FileExistsInQueue + FileExistsInQueue, + InsufficientCredit, + InvoiceStatusNotFound, + FileNotAvailable } \ No newline at end of file diff --git a/src/Mews.Fiscalizations.All/Mews.Fiscalizations.All.csproj b/src/Mews.Fiscalizations.All/Mews.Fiscalizations.All.csproj index c99c064a..125d5780 100644 --- a/src/Mews.Fiscalizations.All/Mews.Fiscalizations.All.csproj +++ b/src/Mews.Fiscalizations.All/Mews.Fiscalizations.All.csproj @@ -10,7 +10,7 @@ https://github.com/MewsSystems/fiscalizations https://raw.githubusercontent.com/msigut/eet/master/receipt.png true - 25.0.5 + 25.0.6 10 true $(TargetsForTfmSpecificBuildOutput);CopyProjectReferencesToPackage