Class TaxService
- Namespace
- Integrations.Application.Tax
- Assembly
- Integrations.Application.dll
AR/AP tax documents: estimate, create/replace, commit, void, credit and recalculate.
Documents are persisted before the provider is called, so the provider document code is durable and a crash or retry can never create a second provider document. Provider outages leave the document PendingTax (the caller falls back to the manual process and the recalculation job finishes the work); the service never invents a tax amount.
public sealed class TaxService
- Inheritance
-
TaxService
- Inherited Members
Constructors
TaxService(IAppDbContext, ITaxProvider, TaxCodeResolver, EntityGuard, ExchangeRateService, IEventPublisher, BusinessClock, AdminAuditLog, IOptions<TaxOptions>, ILogger<TaxService>)
AR/AP tax documents: estimate, create/replace, commit, void, credit and recalculate.
Documents are persisted before the provider is called, so the provider document code is durable and a crash or retry can never create a second provider document. Provider outages leave the document PendingTax (the caller falls back to the manual process and the recalculation job finishes the work); the service never invents a tax amount.
public TaxService(IAppDbContext db, ITaxProvider provider, TaxCodeResolver taxCodes, EntityGuard guard, ExchangeRateService fx, IEventPublisher events, BusinessClock clock, AdminAuditLog audit, IOptions<TaxOptions> options, ILogger<TaxService> logger)
Parameters
dbIAppDbContextproviderITaxProvidertaxCodesTaxCodeResolverguardEntityGuardfxExchangeRateServiceeventsIEventPublisherclockBusinessClockauditAdminAuditLogoptionsIOptions<TaxOptions>loggerILogger<TaxService>
Methods
CommitAsync(Guid, CancellationToken)
Commits a saved document; a PendingTax one is committed once it calculates.
public Task<TaxDocumentDto> CommitAsync(Guid id, CancellationToken ct)
Parameters
idGuidctCancellationToken
Returns
CreateAsync(CreateTaxDocumentRequest, CancellationToken)
Creates or replaces a document. Saved first, then calculated; PendingTax when the provider is down.
public Task<(TaxDocumentDto Document, TaxDocumentOutcome Outcome)> CreateAsync(CreateTaxDocumentRequest request, CancellationToken ct)
Parameters
requestCreateTaxDocumentRequestctCancellationToken
Returns
CreditAsync(Guid, CreateCreditRequest, CancellationToken)
Credits a committed document at its original tax date and rate.
public Task<(TaxDocumentDto Document, TaxDocumentOutcome Outcome)> CreditAsync(Guid originalId, CreateCreditRequest request, CancellationToken ct)
Parameters
originalIdGuidrequestCreateCreditRequestctCancellationToken
Returns
DuePendingAsync(int, CancellationToken)
Ids of PendingTax documents due for another attempt.
public Task<IReadOnlyList<Guid>> DuePendingAsync(int take, CancellationToken ct)
Parameters
takeintctCancellationToken
Returns
EstimateAsync(TaxEstimateRequest, CancellationToken)
Real-time estimate; nothing is recorded. Throws ProviderUnavailableException when the provider is down.
public Task<TaxEstimateDto> EstimateAsync(TaxEstimateRequest request, CancellationToken ct)
Parameters
requestTaxEstimateRequestctCancellationToken
Returns
FindBySourceAsync(string, string, string, CancellationToken)
Documents for a caller's source document (both directions).
public Task<IReadOnlyList<TaxDocumentDto>> FindBySourceAsync(string entityId, string sourceSystem, string sourceDocumentId, CancellationToken ct)
Parameters
entityIdstringsourceSystemstringsourceDocumentIdstringctCancellationToken
Returns
GetAsync(Guid, CancellationToken)
A document by id.
public Task<TaxDocumentDto> GetAsync(Guid id, CancellationToken ct)
Parameters
idGuidctCancellationToken
Returns
RecalculateAsync(Guid, CancellationToken)
Retries a PendingTax or Failed document with its stored content. Used by the job and the API.
public Task<TaxDocumentDto> RecalculateAsync(Guid id, CancellationToken ct)
Parameters
idGuidctCancellationToken
Returns
VoidAsync(Guid, string, CancellationToken)
Voids the document here and at the provider.
public Task<TaxDocumentDto> VoidAsync(Guid id, string reason, CancellationToken ct)
Parameters
idGuidreasonstringctCancellationToken