Getting Started

Prerequisites

A basic knowledge of C# is required for following examples.

The .Net SDK is also required to complete these examples.

The SDK can be downloaded here .

Create your first project

In this example you will create a simple cash register, setup a basic connection to a Checkbox and then send your first transaction to the Checkbox. The box will sign the transaction and return the result to the application.

Create a folder on your computer where you want to have this project located. The next step is opening a terminal and navigate to this folder.

C#
        
mkdir SimpleCashRegister
cd SimpleCashRegister
dotnet new sln -n SimpleCashRegister
        
    

This will create the solution directory SimpleCashRegister, this will hold all the projects inside the solution.

From this directory, you can use these commands to start a console project and add it to your solution.

Bash
        
mkdir src
cd src
dotnet new console -n CheckboxSign
        
    

This will create a new folder src/CheckboxSign where the project will reside.

  • CheckboxSign.csproj - project file
  • program.cs - main starting point of the application

Now we need to add the project to our soluition.

Bash
        
cd ..
cd ..
dotnet sln add ./src/CheckboxSign

code ./
        
    

Open the project with your preferred editor. In this example we will use Visual Studio Code.

Running the project

To run the project we go inside the folder of the project and execute it with this command.

Bash
        
cd src/CheckboxSign
dotnet run
        
    

Add the Checkbox SDK to the project

Via nuget we then add the SDK to the project. Since we want to use Dependency Injection we also need to add a Microsoft package to the application

  • Checkbox.Fdm.Sdk - This SDK will handle the communication between the Checkbox and will handle all the transactions.
  • Microsoft.Extensions.Hosting - This extension is handling the Dependency Injection.
Bash
        
dotnet add package Checkbox.Fdm.Sdk
dotnet add package Microsoft.Extensions.Hosting
        
    

Configure the Checkbox Sdk

Adapt the file program.cs in a way to configure dependency injection (DI), we will also add our SDK to this pool.

C#
        
//Add on top of the program.cs file
using Checkbox.Fdm.Sdk;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

//Create the Dependency Injector host
var host = CreateHostBuilder(args).Build();


//Configure DI for this console app, place this at the bottom of the program.cs file
static IHostBuilder CreateHostBuilder(string[] args) =>
    Host.CreateDefaultBuilder(args)
        .ConfigureServices(services =>
        {
            services.AddCheckbox("Your Client Key");
        });
        
    

Inject the Checkbox service

Now we have configured the service to be used in our program, We can now fetch it trough GetRequiredService, If you don't want to use Dependency injection, it can just be manually inserted in the constructor.

This will handle the communication between our program and the checkbox. The next step is initialising the service.

var myCheckboxService = host.Services.GetRequiredService<ICheckboxService>();

Initialise the Checkbox with the service

If you use a real Checkbox, this can fetch its configuration automatically with the SDK, the configuration will be very simple that way. If you don't want to use the automatic service, it can also be configured manually. The SDK also allows multiple checkboxes to be configured for a POS system to communicate with.

C#
        
var allCheckboxesInitialized = await myCheckboxService.InitializeCheckboxesAsync(
    ["Checkbox Id 1", "Checkbox Id 2"], 
    CheckboxLoadbalancingMode.Manual);
        
    

The Checkbox Service is now ready to be used troughout your program

From this moment on, it is possible to use the checkbox to process the actions from a POS system.

For this example we will define an imagniary Pos system with emloyees, terminals etc.

C#
        
// Define your company
Company myRestaurant = new()
{
    VatNo = "BE0000000097",
    EstNo = "200000000"
};

// Define all your terminals
PosTerminal myPosTerminal = new()
{
    DeviceId = "1631678d-7a85-4ac3-b296-bb4565e873fe",
    TerminalName = "POS-TERMINAL"
};

//Define all your employees
Employee myEmployee = new()
{
    FullName = "Francis",
    Insz = "84022899837"
};

// Define all your Pos systems
PosSystem myPos = new()
{
    PosId = "CPOS0031234567",
    SoftwareVersion = "1.0.0"
};
        
    

Lets begin the day for Francis, so he can start his shift

We have everything in place to sign this action with the Checkbox, the Checkbox will return the result and the Pos system can now process the result.

C#
        
// Create a new action for an employee to start its work, this is done for myRestaurant, on myPos and on myPosTerminal
PosWorkAction workInAction = new PosWorkAction(myRestaurant, myPos, myPosTerminal, myEmployee)
{
    //The date where this action is booked on
    BookingDate = DateTime.Now,
    //A Pos system should handle the bookingperiods
    BookingPeriodId = Guid.NewGuid(),
    //The Pos system is handling the number of the action to sign, this should always increase for each action it wants to sign
    SalesActionNumber = 1,
    //The type of Work action
    Type = WorkType.WORK_IN
};

//Actual signing of this action
var result = await myCheckboxService.SignPosAction(workInAction);
        
    

The result coming from the Checkbox is now a task for the Pos system to handle.

Congratulations, you have created your first project and you have sent your first request to a Checkbox.

Full Program.cs

C#
        
using Checkbox.Fdm.Core.PosModels;
using Checkbox.Fdm.Core.PosModels.Actions;
using Checkbox.Fdm.Sdk;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

Console.WriteLine("Hello, Checkbox!");

var host = CreateHostBuilder(args).Build();

// Fetch the checkbox service that will handle all future signings
var myCheckboxService = host.Services.GetRequiredService<ICheckboxService>();

var allCheckboxesInitialized = await myCheckboxService.InitializeCheckboxesAsync(
    ["Checkbox Reference Id"],
    CheckboxLoadbalancingMode.Manual);

// Define your company
Company myRestaurant = new()
{
    VatNo = "BE0000000097",
    EstNo = "200000000"
};

// Define all your terminals
PosTerminal myPosTerminal = new()
{
    DeviceId = "1631678d-7a85-4ac3-b296-bb4565e873fe",
    TerminalName = "POS-TERMINAL"
};

//Define all your employees
Employee myEmployee = new()
{
    FullName = "Francis",
    Insz = "84022899837"
};

// Define all your Pos systems
PosSystem myPos = new()
{
    PosId = "CPOS0031234567",
    SoftwareVersion = "1.0.0"
};

// Create a new action for an employee to start its work
PosWorkAction workInAction = new PosWorkAction(myRestaurant, myPos, myPosTerminal, myEmployee)
{
    //The date where this action is booked on
    BookingDate = DateTime.Now,
    //A Pos system should handle the bookingperiods
    BookingPeriodId = Guid.NewGuid(),
    //The Pos system is handling the number of the action to sign, this should always increase for each action it wants to sign
    SalesActionNumber = 1,
    //The type of Work action
    Type = WorkType.WORK_IN
};

//Actual signing of this action
var result = await myCheckboxService.SignPosAction(workInAction);

//Handle The result

return;

//Configure DI for this console app
static IHostBuilder CreateHostBuilder(string[] args) =>
    Host.CreateDefaultBuilder(args)
        .ConfigureServices(services =>
        {
            services.AddCheckbox("Your Checkbox API Key");
        });

        
    

Next

Na deze tutorial kun je verder gaan met het opzetten van effectieve voorbeelden zoals een kassasysteem dit zal afhandelen.

Er zijn voorbeeldscenario's uitgewerkt door FOD. Deze worden hier met de Checkbox SDK volledig uitgewerkt.

  1. M110 Sales
  2. M111 Volledige terugname
  3. M112 Verkoop met terugname
  4. M121 Bestelling
  5. M122 Bestelling verplaatsen
  6. M123 Pre Bill afprinten
  7. M130 Geld in de lade
  8. M131 Lade open zonder actie
  9. M132 Betalingscorrectie
  10. M133 Declareren van geld in lade
  11. M140 Start werktijd
  12. M150 Stop werktijd
  13. M160 Kopie van verkoop afdrukken
  14. M161 Kopie van pre bill afdrukken
  15. M170 Training Start werktijd
  16. M171 Training Verkoop
  17. M172 Training Copy verkoop