Skip to content

kaineder/fiskaly-kassensichv-client-dotnet

 
 

Repository files navigation

fiskaly KassenSichV client for .NET Core

The fiskaly KassenSichV client is an HTTP client that is needed1 for accessing the kassensichv.io API that implements a cloud-based, virtual CTSS (Certified Technical Security System) / TSE (Technische Sicherheitseinrichtung) as defined by the German KassenSichV (Kassen­sich­er­ungsver­ord­nung).

Conceptually this client is a thin (convenience) wrapper above the System.Net.Http.HttpClient for .NET Core. This means you will have to look up the API documentation of System.Net.Http.HttpClient to learn how this client is used. From a developer's point of view, the only difference is that you have to use the Fiskaly.Client.ClientFactory class for the instantiation of a new HttpClient.

Features

  • Automatic authentication handling (fetch/refresh JWT and re-authenticate upon 401 errors).
  • Automatic retries on failures (server errors or network timeouts/issues).
  • Automatic JSON parsing and serialization of request and response bodies.
  • Future: [1] compliance regarding BSI CC-PP-0105-2019 which mandates a locally executed SMA component for creating signed log messages.
  • Future: Automatic offline-handling (collection and documentation according to Anwendungserlass zu § 146a AO)

Install

First of all, you have to initialize the required git submodule(s) using:

$ git submodule update

Then you can build FiskalyClient using:

$ dotnet build

The test suite in FiskalyClientTest is run using:

$ dotnet test

Usage

using System;
using System.Net.Http;
using Fiskaly.Client;
using Serilog;
using System.Text;
using System.Threading.Tasks;

namespace Fiskaly.Client
{
    class Demo
    {
        static String ApiKey = Environment.GetEnvironmentVariable("API_KEY"); // create your own API key and secret at https://dashboard.fiskaly.com
        static String ApiSecret = Environment.GetEnvironmentVariable("API_SECRET");
        static HttpClient client;

        public static StringContent Content(string payload)
        {
            return new StringContent(payload, Encoding.UTF8, "application/json");
        }

        public static async Task<String> CreateTss()
        {
            Log.Information("creating tss...");
            var tssGuid = Guid.NewGuid().ToString();
            var url = $"tss/{tssGuid}";
            var payload = $"{{\"description\": \"{tssGuid}\", \"state\": \"INITIALIZED\"}}";

            HttpResponseMessage response = await client
              .PutAsync(url, Content(payload))
              .ConfigureAwait(false);

            String content = await response.Content
              .ReadAsStringAsync()
              .ConfigureAwait(false);

            return content;
        }

        public static async Task<String> ListTss()
        {
            Log.Information("listing tss...");
            
            HttpResponseMessage response = await client
              .GetAsync("tss")
              .ConfigureAwait(false);

            String content = await response.Content
              .ReadAsStringAsync()
              .ConfigureAwait(false);

            return content;
        }

        static async Task Main(string[] args)
        {
            Log.Logger = new LoggerConfiguration()
              .WriteTo.Console()
              .CreateLogger();

            client = await ClientFactory.Create(ApiKey, ApiSecret).ConfigureAwait(false);
            var createTssResponse = await CreateTss().ConfigureAwait(false);
            var listTssResponse = await ListTss().ConfigureAwait(false);
            Log.Information("createTssResponse: {Response}", createTssResponse);
            Log.Information("listTssResponse: {Response}", listTssResponse);
        }
    }
}

Related

About

fiskaly KassenSichV client for .NET Core

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 100.0%