Skip to main content

Setup

Setup the provided NodeJS and C++ SDK’s according to the SDK Setup sections in the docs. The NodeJS package is provided as an npm library that can be included in your package.json. For C++ we have provided a C++ header file and a Dynamic Library (dll), which should be placed in the same directory as your exe. If you would prefer a .lib (statically linkable) library we can provide this too (just reach out to support).

Initialisation

When your POS Software starts it should initialise the library with relevant configuration. This function call is offline only and will always succede, unless passed malformed parameters. ie. If the initialise call fails, this should be treated as a bug, and you should shutdown the application.
Note we provide both NodeJS and C++ examples in all snippets (check the tabs)
import * as sdk from "k42-sdk"

const initResult = sdk.initialize({
  platform_endpoint: "https://mesh.transit.dev",
  auth_token: "atu_abc123",
  pos_id: "pos-1",
  location_id: "loc-1"
});

if (!initResult.success) {
  process.exit(1)
}

// the rest of your code

Checkout Sessions

When a new pos session (first screen) is initiated for a customer arriving at the till, you create a Session. This session stores context about the POS session such as items that get scanned into the basket, basket totals etc and is used to help the API process transactions that involve discounts on basket items.
All session functions are completely offline (in memory) and therefore safe to call as part of a regular interaction (no need to worry about network outages etc).
You should create a Session as early as possible in the checkout flow (before beginning to scan customer basket items). When creating a session you pass a ref, which is YOUR unique identifier for the customer interaction. This is used to help reconcile transactions in your system with ours when performing settlement and reconsiliation functions with treasury.
const session = sdk.createSession("unique-session-ref");
Once a Session is created, it is set as the “active” session and future function calls will operate against this session. At the end of a customer checkout flow, you should remember to close the session, as described in the reference. As items are scanned (or at the end of the item scanning process), you should set any basket items and the basket total. This will be set against the currently active session.
const items = [
  {
    sku: "xxx243",
    price: 10
  },
  {
    sku: "xxx643",
    price: 100
  }
]

sdk.setSessionBasketItems(items);
sdk.setSessionBasketTotal(1000);

Token Scanning or Manual Encoding

The SDK exposes a Token Scan function that provides easy access to the scanner and a Token Encode function that allows you to manually encode a token. These tokens can then be used when creating transactions. When scanning or encoding, you provide a provider key which represents the type of code, for instance sodexo, gifted or sharetreats (see the API for a full list).
let scanResult = await sdk.tokenScan(30000, 3, "sodexo");

if (!scanResult.success) {
  // get manual code and provide to token encode if it fails
  scanResult = await sdk.tokenEncode("manual token", "sodexo")
}

// then use token for a transaction

Transactions

To transact a token you call the Create Transaction function. By doing this you can check the details of the transaction before it finalises. You can then either finalise or cancel the transaction. The Create Transaction function accepts a ref which is YOUR unique identifier for the transaction. This is purely informational and helps to reconcile the transaction later.

const txResult = await sdk.createTransaction("tx-ref", scanResult.token);
if (!txResult.success) {
  console.log(`Failed to create transaction: ${txResult.message}`);
} else {
    // If you're happy with the transaction, finalise it to get the auth code.
    // Otherwise cancel it.

    const finalizeResult = await sdk.finalizeTransaction(txResult.id);

    if (!finalizeResult.success) {
        console.log(`Failed to finalize transaction: ${txResult.message}`);
        return;
    }

    console.log('Transaction successful');
    console.log(`id: ${finalizeResult.id}`);
    console.log(`auth_code: ${finalizeResult.auth_code}`);
    console.log(`credit amount: ${finalizeResult.effects[0].amount}`);
    console.log(`coupon id: ${finalizeResult.coupon.id}`);
}