Conversation
…d we don't use external API packages in other places of our project) Refactored code
src/Service/AvalaraRequest.cs
Outdated
| { | ||
| public static string SendRequest(string accountId, string licenseKey, string apiUrl, CommandConfiguration configuration) | ||
| { | ||
| using (var messageHandler = GetMessageHandler()) |
There was a problem hiding this comment.
It seems like these usings are for the whole method, we can avoid a lot of indentation here, making it more readable;
using var messageHandler = GetMessageHandler();
using var client = new HttpClient(messageHandler);
etc
| TransactionType.Adjust or TransactionType.Commit => DocumentType.SalesInvoice, | ||
| TransactionType.Calculate => DocumentType.SalesOrder, | ||
| TransactionType.ProductReturns => DocumentType.ReturnInvoice, | ||
| _ => throw new ArgumentOutOfRangeException(nameof(transactionType), $"Unknown or unsupported transaction type: {transactionType}") |
There was a problem hiding this comment.
Usually we throw a NotImplementedException as a default case if we're not just returning null.
| { | ||
| if (Provider.IsTaxableTypeInternal(orderLine) || orderLine.HasType(OrderLineType.PointProduct)) | ||
| { | ||
| if (orderLine.Product is not null) |
There was a problem hiding this comment.
In general it would be good to avoid indentation in places like this, and just say
if (orderLine.Product is null)
continue;
|
|
||
| private void SetCustomerExemptionData(CreateTransactionRequest request) | ||
| { | ||
| if (Order.CustomerAccessUserId > 0) |
There was a problem hiding this comment.
if (Order.CustomerAccessUserId <= 0)
return;
| nameof(CustomerCodeSource.AccessUserExternalId) => Order.CustomerAccessUserId > 0 | ||
| ? UserManagementServices.Users.GetUserById(Order.CustomerAccessUserId)?.ExternalID ?? "" | ||
| : string.Empty, | ||
| _ => throw new Exception($"Unsupported option is used: {Provider.GetCustomerCodeFrom}") |
There was a problem hiding this comment.
NotImplementedException
src/Service/AvalaraRequest.cs
Outdated
| ApiCommand.CreateTransaction => GetCommandLink("transactions/create"), | ||
| ApiCommand.ResolveAddress => GetCommandLink("addresses/resolve", queryParameters), | ||
| ApiCommand.VoidTransaction => GetCommandLink($"companies/{operatorId}/transactions/{operatorSecondId}/void"), | ||
| _ => throw new NotSupportedException($"The api command is not supported. Command: {command}") |
There was a problem hiding this comment.
NotImplementedException
src/Service/AvalaraRequest.cs
Outdated
| //POST | ||
| ApiCommand.CreateTransaction or | ||
| ApiCommand.VoidTransaction => client.PostAsync(apiCommand, GetContent()), | ||
| _ => throw new NotSupportedException($"Unknown operation was used. The operation code: {configuration.CommandType}.") |
There was a problem hiding this comment.
NotImplementedException
Refactored code.
Removed external Avalara package. We don't use external API helper packages in any other our projects.
Refactored code to use our common Client-Server communication layer which we use in other payment/shipping providers.
Added logging of each data we send to server and the data which we get from server.
Some other related changes also were done, but they are mainly related with parameters processing...
Added logo.
Used Net 8.0 Framework.
Removed "Tax Service Url" - we don't need this anymore...
Removed "BoundaryLevel" - it wasn't used in previous code.
Added "Test Mode" checkbox to use sandbox environment for test. Uncheck for production.
The settings of provider now looks like this:
Original task: User Story 23797. Avalara Avatax Tax Method