Project Setup
We are continuing on the Getting Started tutorial.
Create a project and register the Checkbox(es) in the 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 nuget packages to the project and also add this package. This is only needed for the examples in these tutorials, you should not use them in your final product!
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
Base structure Pos
Lets create a base structure for our console application, we will then use it in the next examples.
In the first place we create a new class/file 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)
{
}
}
Initialise the Checkboxes
In the init part of this example FpsPos the settings for the Checkboxes you want to use need to be provided. The example uses 2 Checkboxes, these numbers need to be your checkboxes. Take 2 checkbox units en connect them in a way the internet is available on the unit. From this moment on the Checkbox middleware will know all the needed settings for the Checkbox.
Important: To complete this example and run it, you actually need 2 physical Checkboxes!
Put this code in the Init part
//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,
// This configures their destination network addresses automatically
await checkboxService.InitializeCheckboxesAsync(
_myFpsPos.CheckboxIdentifiers,
CheckboxLoadbalancingMode.Manual,
cancellationToken);
M110 Sales example
In the Run() function of the example we can put the effective code to execute the actions. We will start with the first Usecase
In de Dining Room a direct sale for following products get registered
- 2 Dry Martini (unit price 12 Eur, Vat code A)
- 1 Burger of the Chef (unit price 28 Eur, Vat code B)
The payment is cash. For a total amount of 52 Eur
//Create the correct action according to the example
var newSalesAction = new PosSalesAction(
FpsFinancesModels.Company,
_myFpsPos,
FpsFinancesModels.TerminalTer2Din,
FpsFinancesModels.EmployeeElisa)
{
TicketMedium = TicketMedium.PAPER,
SalesActionNumber = 1000,
BookingDate = DateTime.Now,
BookingPeriodId = Guid.Parse("dffcd829-a0e5-41ca-a0ae-9eb887f95637"),
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, null, cancellationToken);
//Handle the result accordingly
Console.WriteLine($"Result with Signature {result.SignResult?.DigitalSignature}");