In this article you will learn how to implement the FiscalClient using nuget.
Requirements
- Knowledge of .net development
- Knowledge in the use of nuget packages
-
Download the packages
RetailForce.Fiscalisation - Environment platform that supports .net Standard 2.0
Implementation
Configuration-Provider
To save the configuration, you need a FileConfigurationProvider with the path to the configuration file and a logger:
FileConfigurationProvider fileConfigurationProvider = new FileConfigurationProvider(System.IO.Path.Combine(this.FilesDir.ToString(), "fiscalclient.config.json"), _logger);(Android).
Fiscal module management
To create clients or load the configuration from the cloud, you need the FiscalModuleManagement class:
IClientStatusReporter clientStatusReporter = new EmptyClientStatusReporter();
FiscalModuleManagement moduleManagement = new FiscalModuleManagement(_logger, fileConfigurationProvider, clientStatusReporter);The logger is derived from Microsoft.Extensions.Logging.ILogger.
The client status reporter (IClientStatusReporter) is required. If you do not process the status reports yourself, use EmptyClientStatusReporter.
Load client from the cloud
To load the client from the cloud, you can use the command CreateClientByCloud:
uniqueClientId = moduleManagement.CreateClientByCloud(new CompanyIdentification() { Identification = "ATU1234567", Type = CompanyIdentification.IdentificationType.VatNumber }, "T001", "T001", cloudApiKey, cloudApiSecret);Create client manually
The client can also be created manually (FiscalClient). Once this class has been created, the client can be created with CreateClient.
Create a fiscal module
A fiscal module can be created with the FiscalModuleCreator class:
CloudService cloudService = new CloudService(_logger, storageBasePath, uniqueClientId.Value, cloudApiKey, cloudApiSecret);
FiscalModulCreator creator = new FiscalModulCreator(fileConfigurationProvider, _logger, cloudService, null, clientStatusReporter);This creates the fiscal module. The CloudService is a class that should be kept in the software for the entire runtime. It takes care of the background transfer to the cloud.
The fourth parameter (IotService) is optional and can be set to null. The FiscalModulCreator also accepts null for the CloudService, but the LocalMonitoringClient used below requires a CloudService.
Creating the fiscal module
After the Fiscal Module Creator class has been initialised, the fiscal module can be created.
The fiscal module stores its data through two storage providers: a FiscalDataStorageProvider for the fiscal data and an AuditLogStorageProvider for the audit log. For local storage use LocalFiscalDataStorageProvider and LocalAuditLogStorageProvider. storageBasePath is the base directory without the client id (Android: this.GetExternalFilesDir(Android.OS.Environment.DirectoryDocuments).AbsolutePath); the path for the audit log must contain the client id.
IMonitoringClient monitoringClient = new LocalMonitoringClient(cloudService);
FiscalDataStorageProvider storageProvider = new LocalFiscalDataStorageProvider(_logger, uniqueClientId.Value, monitoringClient, storageBasePath);
AuditLogStorageProvider auditLogStorageProvider = new LocalAuditLogStorageProvider(uniqueClientId.Value, _logger, System.IO.Path.Combine(storageBasePath, uniqueClientId.Value.ToString()));
TrustedFiscalModule fiscalModule = creator.CreateFiscalModuleForClient(uniqueClientId.Value, storageProvider, auditLogStorageProvider, cloudApiKey: cloudApiKey, cloudApiSecret: cloudApiSecret);Here too, if cloud support is not required, the cloud securables (cloudApiKey, cloudApiSecret) can be omitted.
IMPORTANT: The client configuration must have been created beforehand. Either by downloading from the cloud or via CreateClient (see above).
Comments
0 comments
Please sign in to leave a comment.