Project Setup
We are building on the knowledge we got from the Getting Started tutorial.
Create a project and register the Checkbox(es) in code.
mkdir Mt110_SignSale
cd Mt110_SignSale
dotnet new sln -n Mt110_SignSale
mkdir src
cd src
dotnet new console -n Mt110_SignSale
cd ..
dotnet sln add ./src/Mt110_SignSale
Add the required nuget packages to the project and also add this test package. This package is only needed as an example for these usecases. In a real-life project this package is not needed.
Checkbox.Fdm.UseCases
cd src/Mt110_SignSale
dotnet add package Checkbox.Fdm.Sdk
dotnet add package Checkbox.Fdm.UseCases
dotnet add package Microsoft.Extensions.Hosting
Basic structure Pos
Lets create a console application for these basic tests, we can then further use it for the next examples.
In the first example we will create a new Class FpsExample.cs in the root of the project.
The Project now has 2 c# files (Program.cs and FpsExample.cs)
FpsExample.cs starting point
using Checkbox.Fdm.Core.PosModels;
using Checkbox.Fdm.Sdk;
using Checkbox.Fdm.UseCases;
namespace Mt110_SignSale;
//Inject the Service into this example
internal class FpsExample(ICheckboxService checkboxService)
{
//Use the example pos from the example nuget package
private readonly PosSystem _myFpsPos = FpsFinancesModels.Pos567;
//Initialize the pos
public async Task Init(CancellationToken cancellationToken = default)
{
}
//Run the pos
public async Task Run(CancellationToken cancellationToken = default)
{
}
}
Program.cs starting point
using Checkbox.Fdm.Sdk;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Mt110_SignSale;
Console.WriteLine("Fps Finances Pos Examples");
try
{
var host = CreateHostBuilder(args).Build();
//Inject the Checkbox Service
var myFpsExample = host.Services.GetRequiredService<FpsExample>();
await myFpsExample.Init();
await myFpsExample.Run();
}
catch(Exception ex)
{
Console.WriteLine(ex.ToString());
}
return;
static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureServices(services =>
{
services.AddCheckboxService("YOUR CHECKBOX API KEY");
services.AddSingleton<FpsExample>();
});
Configure your Checkboxes
In the init part of the example FpsPos you have to configure the Checkboxes you wish to use.
The example is using 2 Checkboxes (in the example, the ID's are not real life id's) So you need to replace it with the actual checkboxes at your location. Take 2 Checkbox units and connect them. If you can see them to be online in the tools, you are ready to go.)
Important: To actually execute this example, you will need 2 actual Checkboxes.
Put this code in the init part of your FpsExample
//This is an optional step
//In the example there are 2 checkboxes connected, you can change this to your own checkbox Id's
_myFpsPos.CheckboxUnits[0].CheckboxId = "ACTUAL CHECKBOX ID";
_myFpsPos.CheckboxUnits[1].CheckboxId = "ACTUAL CHECKBOX ID";
// Try to Initializes the Checkbox devices,
foreach(var checkboxUnit in _myFpsPos.CheckboxUnits)
{
await myCheckboxService.ConfigureCheckboxAsync(checkboxUnit.CheckboxId);
}
M110 Sales example
In the Run() function of the example we can now put code to execute the actions, lets begin with the first Usecase.
In the Dining Room we will register a direct sale for these products
- 2 Dry Martini (unit price 12 Eur, Vat code A)
- 1 Burger of the Chef (unit price 28 Eur, Vat code B)
A cash payment is executed, the total is 52 EUR.
//Create the correct action according to the example
var newSalesAction = new PosSalesAction(
FpsFinancesModels.Company,
_myFpsPos,
FpsFinancesModels.TerminalTer2Din,
FpsFinancesModels.EmployeeElisa,
FpsFinancesModels.BookingPeriod20240730)
{
TicketMedium = TicketMedium.PAPER,
SalesActionNumber = 1000,
TransactionLines =
[
new SaleLine(TransactionLineType.SINGLE_PRODUCT, 2, FpsFinancesModels.ProdDryMartini),
new SaleLine(TransactionLineType.SINGLE_PRODUCT, 1, FpsFinancesModels.ProdBurgerOfTheChef)
],
Payments = [
new Payment
{
Id = "1",
Name = "CONTANT",
Type = PaymentType.CASH,
InputMethod = InputMethod.MANUAL,
Amount = 52,
AmountType = PaymentLineType.PAYMENT
}
]
};
//Sign the action
var result = await checkboxService.SignPosAction(newSalesAction, false, cancellationToken);
//Handle the result accordingly
Console.WriteLine($"Result with Signature {result.SignResult?.DigitalSignature}");