Table of Contents

Class OmieServiceCatalogProvider

Namespace
NuvTools.Payment.Omie.ApiClient.Services
Assembly
NuvTools.Payment.Omie.ApiClient.dll

Omie service catalog, read whole (ListarCadastroServico, paginated) and indexed by the business code (cCodigo) — the code applications store in their own configuration. This is how the nCodServico, the description and the unit price of a service are discovered: Omie exposes no search by cCodigo, so the catalog is listed and searched in memory.

The result is cached for NuvTools.Payment.Omie.ApiClient.Services.OmieServiceCatalogProvider.CacheDuration because Omie refuses repeated ListarCadastroServico calls in a short window ("Consumo redundante detectado") — without the cache, opening a screen and generating a service order right after would drop the second call.

public class OmieServiceCatalogProvider
Inheritance
OmieServiceCatalogProvider
Inherited Members

Constructors

OmieServiceCatalogProvider(IOmieApiClient, IMemoryCache, TimeProvider)

Omie service catalog, read whole (ListarCadastroServico, paginated) and indexed by the business code (cCodigo) — the code applications store in their own configuration. This is how the nCodServico, the description and the unit price of a service are discovered: Omie exposes no search by cCodigo, so the catalog is listed and searched in memory.

The result is cached for NuvTools.Payment.Omie.ApiClient.Services.OmieServiceCatalogProvider.CacheDuration because Omie refuses repeated ListarCadastroServico calls in a short window ("Consumo redundante detectado") — without the cache, opening a screen and generating a service order right after would drop the second call.

public OmieServiceCatalogProvider(IOmieApiClient omie, IMemoryCache cache, TimeProvider timeProvider)

Parameters

omie IOmieApiClient
cache IMemoryCache
timeProvider TimeProvider

Methods

GetByCodeAsync(bool, CancellationToken)

Catalog indexed by cCodigo. With forceRefresh the cache is ignored and rewritten with whatever Omie returns.

public Task<IResult<IReadOnlyDictionary<string, OmieServiceInfo>>> GetByCodeAsync(bool forceRefresh, CancellationToken cancellationToken)

Parameters

forceRefresh bool
cancellationToken CancellationToken

Returns

Task<IResult<IReadOnlyDictionary<string, OmieServiceInfo>>>

GetByServiceCodeAsync(CancellationToken)

The same catalog indexed by the internal identifier (nCodServico) — the way back, used when reading a service order from Omie, where items carry only the nCodServico and the caller needs the service name.

public Task<IResult<IReadOnlyDictionary<long, OmieServiceInfo>>> GetByServiceCodeAsync(CancellationToken cancellationToken)

Parameters

cancellationToken CancellationToken

Returns

Task<IResult<IReadOnlyDictionary<long, OmieServiceInfo>>>

GetServiceDetailAsync(long, CancellationToken)

Full registration of a service (ConsultarCadastroServico) — it carries what the listing does not and the service order inclusion requires: LC 116, municipal code and tax classification. Cached per service for NuvTools.Payment.Omie.ApiClient.Services.OmieServiceCatalogProvider.CacheDuration, because the same two or three services repeat across every client.

public Task<IResult<OmieServiceDetail>> GetServiceDetailAsync(long serviceCode, CancellationToken cancellationToken)

Parameters

serviceCode long
cancellationToken CancellationToken

Returns

Task<IResult<OmieServiceDetail>>

GetServiceDetailAsync(long, TimeSpan, CancellationToken)

Full registration of a service, re-read from Omie when the cached copy is older than maxAge. This is the overload for whoever sends the registration back to Omie — a service order item carries the tax classification it was given, so a copy read before the user edited the service would issue the invoice with the old taxation. A short maxAge still lets a batch of orders for the same service share one read, which is what keeps Omie from refusing the repeated call as redundant consumption.

The cache is per process: on a host with several replicas each one keeps its own copy, which is why the freshness is decided by age and not by an explicit "clear cache" action — a reload on one replica would not reach the replica that issues the order.

When the re-read is refused (redundant consumption, Omie unavailable) the stale copy is not returned: serving it is exactly the outdated data the caller asked to avoid. The failure carries Omie's message, so a throttled call can be told apart and retried after the wait Omie reports.

public Task<IResult<OmieServiceDetail>> GetServiceDetailAsync(long serviceCode, TimeSpan maxAge, CancellationToken cancellationToken)

Parameters

serviceCode long
maxAge TimeSpan
cancellationToken CancellationToken

Returns

Task<IResult<OmieServiceDetail>>