Table of Contents

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

db IAppDbContext
provider ITaxProvider
taxCodes TaxCodeResolver
guard EntityGuard
fx ExchangeRateService
events IEventPublisher
clock BusinessClock
audit AdminAuditLog
options IOptions<TaxOptions>
logger ILogger<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

id Guid
ct CancellationToken

Returns

Task<TaxDocumentDto>

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

request CreateTaxDocumentRequest
ct CancellationToken

Returns

Task<(TaxDocumentDto Document, TaxDocumentOutcome Outcome)>

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

originalId Guid
request CreateCreditRequest
ct CancellationToken

Returns

Task<(TaxDocumentDto Document, TaxDocumentOutcome Outcome)>

DuePendingAsync(int, CancellationToken)

Ids of PendingTax documents due for another attempt.

public Task<IReadOnlyList<Guid>> DuePendingAsync(int take, CancellationToken ct)

Parameters

take int
ct CancellationToken

Returns

Task<IReadOnlyList<Guid>>

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

request TaxEstimateRequest
ct CancellationToken

Returns

Task<TaxEstimateDto>

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

entityId string
sourceSystem string
sourceDocumentId string
ct CancellationToken

Returns

Task<IReadOnlyList<TaxDocumentDto>>

GetAsync(Guid, CancellationToken)

A document by id.

public Task<TaxDocumentDto> GetAsync(Guid id, CancellationToken ct)

Parameters

id Guid
ct CancellationToken

Returns

Task<TaxDocumentDto>

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

id Guid
ct CancellationToken

Returns

Task<TaxDocumentDto>

VoidAsync(Guid, string, CancellationToken)

Voids the document here and at the provider.

public Task<TaxDocumentDto> VoidAsync(Guid id, string reason, CancellationToken ct)

Parameters

id Guid
reason string
ct CancellationToken

Returns

Task<TaxDocumentDto>