Class ImportServiceClient
Concrete class that implement HTTP calls on Import Microservice.
Inheritance
Implements
Namespace: StoneCo.TransRep.Import.Host.Client
Assembly: cs.temp.dll.dll
Syntax
public class ImportServiceClient : ImportServiceClientBase, IImportServiceClient
Constructors
ImportServiceClient(IOptionsSnapshot<ImportServiceClientOptions>, IHttpRestServiceClient, IConfiguration)
Default constructor to set options and HttpRestServiceClient.
Declaration
public ImportServiceClient(IOptionsSnapshot<ImportServiceClientOptions> options, IHttpRestServiceClient httpRestServiceClient, IConfiguration configuration)
Parameters
Type | Name | Description |
---|---|---|
IOptionsSnapshot<ImportServiceClientOptions> | options | The options design pattern used in ImportServiceClient. |
IHttpRestServiceClient | httpRestServiceClient | Interface with the default methods and properties to be used for all HTTP Rest calls. |
IConfiguration | configuration | Represents a set of key/value application configuration properties. |
Examples
Create a options configuration on class with name AppSettingsOptionsConfigurations on folder Configurations.
public static class AppSettingsOptionsConfigurations
{
private static string AppSettingsImportServiceClient => "Clients:ImportServiceClient";
public static void ConfigureAppSettingsOptions(this IServiceCollection services, IConfiguration configuration)
{
services.AddOptions();
services.Configure<ImportServiceClientOptions>(options =>
configuration.GetSection(AppSettingsImportServiceClient).Bind(options));
}
}
Representation on appsettings.json file.
{
"Clients": {
"ImportServiceClient": {
"Name": "ImportServiceClient",
"AuthorizationToken": "a07f5aa4d2654c0e91412ee7025de133",
"BaseAddress": "https://domain-of-api.com/"
}
}
}
Dependency injection on application.
public class DIFactory
{
public static void ConfigureDI(IServiceCollection services, IConfiguration configuration)
{
services.AddScoped<IImportServiceClient, ImportServiceClient>(configuration.GetValue<string>("Clients:ImportServiceClient:Name"), configuration.GetValue<string>("Clients:ImportServiceClient:BaseAddress"));
}
}
Finally, follow the example of how to use the client.
public class Bar
{
private IImportServiceClient ImportServiceClient { get; }
public Bar(IImportServiceClient importServiceClient) => ImportServiceClient = importServiceClient;
public async Task NewImport(string cardAcceptorCode, string cardAcceptorTerminalCode, ...)
{
var traceKey = Guid.NewGuid().ToString("N");
var request = new NewImportRequestMessage();
request.ImportMessage = new ImportMessage
{
CardAcceptorCode = cardAcceptorCode,
CardAcceptorTerminalCode = cardAcceptorTerminalCode,
...
};
request.AddHeader(Headers.TraceKey, traceKey);
var result = await ImportServiceClient.NewAsync(request);
}
public void NewImportBackground(string cardAcceptorCode, string cardAcceptorTerminalCode, ...)
{
var traceKey = Guid.NewGuid().ToString("N");
var request = new NewImportRequestMessage();
request.ImportMessage = new ImportMessage
{
CardAcceptorCode = cardAcceptorCode,
CardAcceptorTerminalCode = cardAcceptorTerminalCode,
...
};
request.AddHeader(Headers.TraceKey, traceKey);
var result = ImportServiceClient.NewBackground(request);
}
public async Task NewImportBatch(string cardAcceptorCode, string cardAcceptorTerminalCode, ...)
{
var traceKey = Guid.NewGuid().ToString("N");
var request = new NewImportRequestMessage();
var importMessages = new ListImportMessage()
{
new ImportMessage
{
CardAcceptorCode = cardAcceptorCode,
CardAcceptorTerminalCode = cardAcceptorTerminalCode,
...
};
}
request.ImportMessages = importMessages;
request.AddHeader(Headers.TraceKey, traceKey);
var result = await ImportServiceClient.NewBatchAsync(request);
}
public void NewImportBatchBackground(string cardAcceptorCode, string cardAcceptorTerminalCode, ...)
{
var traceKey = Guid.NewGuid().ToString("N");
var request = new NewImportRequestMessage();
var importMessages = new ListImportMessage()
{
new ImportMessage
{
CardAcceptorCode = cardAcceptorCode,
CardAcceptorTerminalCode = cardAcceptorTerminalCode,
...
};
}
request.ImportMessages = importMessages;
request.AddHeader(Headers.TraceKey, traceKey);
var result = ImportServiceClient.NewBatchBackground(request);
}
}
Methods
DeleteAsync(DeleteTransactionsRequestMessage)
Asynchronous call to delete transactions if is necessary.
Declaration
public Task<ResultResponseMessage<ResponseMessage>> DeleteAsync(DeleteTransactionsRequestMessage request)
Parameters
Type | Name | Description |
---|---|---|
DeleteTransactionsRequestMessage | request | Request with values to delete. |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<ResultResponseMessage<ResponseMessage>> | Result of operations with total rolling back transactions on header. |
ImportAsync(ImportTransactionsRequestMessage)
Asynchronous call to import transactions to transaction repository database.
Declaration
public Task<ResultResponseMessage<ResponseMessage>> ImportAsync(ImportTransactionsRequestMessage request)
Parameters
Type | Name | Description |
---|---|---|
ImportTransactionsRequestMessage | request | Default request. |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<ResultResponseMessage<ResponseMessage>> | Result of operations with total imported items on header. |