Skip to main content
Multi-session payment allows multiple transactions to be processed independently, ensuring a seamless user experience in self-service environments. This page will guide you through implementing a multi-session payment in C SDK in more detail. To better explain this process, the code implementation is divided into the following steps:
  1. Include Libraries
  2. Set Up Macro and Global Variables
  3. Set Up Private Functions
  4. Add Initialization Functions
  5. Implement the Main Function
See the section below for more details on each step.

Step 1: Include Libraries

Start by including the necessary libraries for the SDK. See the code block below:
C

Step 2: Setup Macro and Global Variables

The code below defines a macro for the module name used in logging/debugging and sets up the global variables that store configuration and session-related data.
C
Where:
  • config: Stores vending machine configuration.
  • session_products: Array representing two products, one per session.
    • The first is for session 0.
    • The second is for session 1.
  • sessions: Array representing two active sessions.
  • current_session: Keeps track of the active session.
  • menu: Stores menu-related settings.
  • com_id: Represents a communication ID.

Step 3: Setup Private Functions

Implement helper functions for debugging, event handling, and transaction processing. The following sections provide more details.

Debug Output Function

This function determines the output stream for debug information.
C
Where:
  • str: String that contains the debug information.

CPU Timer Tick

This function is called periodically (every 5-10ms) by the platform timer.
C
Where:
  • p: Pointer to optional parameter (unused in this function).
This function handles link events and logs relevant information.
C
Where:
  • event_id: Type of link event.
  • data: Pointer to optional parameter (varies based on event type).
The function will always return the boolean value __false as no success/failure is determined.

Multi-Session Vend Request Handler

This function manages the session and its included items, then sends a vending request to the Nayax Device. See the code block below:
C
It initializes session_products 0 and 1, each with a different product code and price. Each of those would be a separate session (transaction). This is, of course, a demo app, meaning you can (and should) manage your own products and prices to match your peripherals.

Multi-Session Vending Events Handler

This function handles vend events for multi-session and logs relevant information.
C
Where:
  • event_id: Type of vend event.
  • data: Pointer to optional parameter. Varies based on event type.
This function will return a Boolean value:
  • __false in most cases.
  • __true for vmc_vend_event_on_vend_approved to indicate a successful vend approval.

Step 4: Setup Initialization Functions

After adding the helper functions, you need to implement the functions to initialize the VMC configuration and the Menu Handler. See the sections below for more details.

Initialize VMC

This function initializes the VMC configuration and registers the event handlers. See the code below:
C
Since this is a multi-session payment config.multi_session_support is set to__true.

Initialize Menu

Before initializing the menu, add the necessary handler functions. See the code below:
C
Now, you can initialize the menu linking the handlers created before. See the code below.
C

Step 5: Implement the Main Function

Once all other parts are implemented, you can add the program’s main entry point, which initializes the link to the peripheral and the menu, then starts an infinite loop that runs the menu. See the code below:
C