The fiskaly SDK includes 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 (Kassensicherungsverordnung).
The .NET SDK is available for download on NuGet.
PM> Install-Package fiskaly-dotnet-sdk -Version 1.2.200
$ dotnet add package fiskaly-dotnet-sdk --version 1.2.200
Additionaly to the SDK, you'll also need the fiskaly client. Follow these steps to integrate it into your project:
When using the dotnet
CLI, use the following command to build the project:
[Fiskaly/SDK]$ dotnet build SDK.standard.csproj
If you are using and older version than the earliest supported version, there is also a legacy build configuration that supports .NET Framework versions as early as .NET Framework 2.0.
[Fiskaly/SDK]$ dotnet build SDK.legacy.csproj
using System;
using System.Text;
using Fiskaly;
using Fiskaly.Client;
using Fiskaly.Client.Models;
namespace Demo
{
static class Demo
{
// create your own API key and secret at https://dashboard.fiskaly.com
public static String FiskalyApiKey = Environment.GetEnvironmentVariable("API_KEY");
public static String FiskalyApiSecret = Environment.GetEnvironmentVariable("API_SECRET");
public static string TSS_ID = Guid.NewGuid().ToString();
public static string CLIENT_ID = Guid.NewGuid().ToString();
public static FiskalyHttpClient client =
new FiskalyHttpClient(FiskalyApiKey, FiskalyApiSecret, "https://kassensichv.io/api/v1");
public static void Main(string[] args)
{
InitializeTss();
var startTxResponse = StartTransaction();
}
public static void CreateClient()
{
var clientSerial = "fiskaly-dotnet-sdk-test-client";
var createTssPayload = "{ \"serial_number\": \"" + clientSerial + "\" }";
var bodyBytes = Encoding.UTF8.GetBytes(createTssPayload);
var response = client
.Request("PUT", "/tss/" + TSS_ID + "/client/" + CLIENT_ID, bodyBytes, null, null);
var decodedBody = Encoding.UTF8.GetString(response.Body);
var body = JsonConvert
.DeserializeObject<Dictionary<string, object>>(decodedBody);
}
public static void CreateTss()
{
var descriptionContent = "TSS created by .NET SDK CreateClient at "
+ DateTime.Now.ToString();
var createClientPayload = "{ \"description\": \""
+ descriptionContent + "\", \"state\": \"UNINITIALIZED\" }";
var bodyBytes = Encoding.UTF8.GetBytes(createClientPayload);
var response = client
.Request("PUT", "/tss/" + TSS_ID, bodyBytes, null, null);
var decodedBody = Encoding.UTF8.GetString(response.Body);
var body = JsonConvert
.DeserializeObject<Dictionary<string, object>>(decodedBody);
var initializeTssPayload = "{ \"state\": \"INITIALIZED\" }";
bodyBytes = Encoding.UTF8.GetBytes(initializeTssPayload);
var initializeResponse = client
.Request("PUT", "/tss/" + TSS_ID, bodyBytes, null, null);
}
public static void InitializeTss()
{
CreateTss();
CreateClient();
}
public static FiskalyHttpResponse StartTransaction()
{
var txId = Guid.NewGuid().ToString();
var payload = "{ \"state\": \"ACTIVE\", \"client_id\": \"" + CLIENT_ID + "\" }";
var bodyBytes = Encoding.UTF8.GetBytes(payload);
var response = client
.Request("PUT", "/tss/" + TSS_ID + "/tx/" + txId, bodyBytes, null, null);
return response;
}
}
}
The SDK is built on the fiskaly Client which can be configured through the SDK.
A reason why you would do this, is to enable the debug mode.
The following code snippet demonstrates how to enable the debug mode in the client.
public static void Main(string[] args)
{
var client = new FiskalyHttpClient(
FiskalyApiKey,
FiskalyApiSecret,
"https://kassensichv.io/api/v1"
);
var configuration = new ClientConfiguration
{
DebugLevel = DebugLevel.EVERYTHING
};
client.ConfigureClient(configuration);
}