> For the complete documentation index, see [llms.txt](https://developer.magtek.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developer.magtek.com/sdks-and-tools/universal-sdk-documentation/linux/appendices/appendix-a-api-walk-through.md).

# Appendix A - API Walk Through

## CoreAPI Walk Trough

The following walks through how to create instances of a device.

* CoreAPI.getDeviceList à IDevice

These examples demonstrate methods for creating an IDevice to be used in the MagTek Universal SDK.&#x20;

Here, a list of IDevice is established. The first device is accessed at index 0.

{% code overflow="wrap" %}

```
#include "MTUSDK.h" 
using namespace MTUSDK;

// Acess MMS with Universal SDK using getDeviceList()

vector<IDevice*> devices = 
CoreAPI::getDeviceList(MTU_DEVICE_TYPE::MMS);

IDevice* mtmms = devices.at(0); 
mtmms->requestSignature(0xff);
```

{% endcode %}

## IDevice Walk Through <a href="#a.2_idevice_walk_through" id="a.2_idevice_walk_through"></a>

The following walks through how to make use of IDevice.

* Implement device events within the class to receive events.
* CoreAPI --> IDevice.
* IDevice --> subscribeAll().
* IDevice --> other functions.
* IDevice --> startTransaction().

**Example**

{% code overflow="wrap" %}

```
#include "MTUSDK.h" using namespace MTUSDK;
 
 
// Extend the main window to receive events.
class MainWindow : public IEventSubscriber, IConfigurationCallback
{
 
// Establish a device from CoreAPI.
vector<IDevice*> deviceList = CoreAPI::getDeviceList(); IDevice* device = deviceList.at(0);
 
/* Suscribe to events sent from the device.
These would be but not limited to: card inserted, card removed, connection state...
 
Set MainWindow to receive the events. */ bool return = device_subscribeAll(&MainWindow);
 
 
// Assign parameters for the transaction. ITransaction transaction; transaction.Amount = “1.00”;
transaction.CashBack = “0.00”;
transaction.EMVOnly = true;
int PaymentMethodes = = PAYMENT_METHOD_MSR | PAYMENT_METHOD_CONTACT | PAYMENT_METHOD_CONTACTLESS;
transaction.PaymentMethods = PaymentMethods; transaction.QuickChip = true;

// Start transaction.
return = device->startTransaction(transaction);
```

{% endcode %}

## **Handling Events**

Application Main window may extent the IEventSubscriber, or events can be interfaced by a separate class. This example shows how to parse for various event types.

**Example**

{% code overflow="wrap" %}

```
// A class to handle events.
class MainWindow : public IEventSubscriber
{
virtual void OnEvent(EventType eventType, IData data)
{
switch (eventType)
{

```

{% endcode %}

Various events are separately shown below.

{% code overflow="wrap" %}

```
case EVENT_TYPE_ConnectionState:
// Parse for the ConnectionState ConnectionState value =
ConnectionStateBuilder::GetValue(data.StringValue);

break;
```

{% endcode %}

{% code overflow="wrap" %}

```
case EVENT_TYPE_DeviceResponse:

break;
```

{% endcode %}

{% code overflow="wrap" %}

```
case EVENT_TYPE_DeviceExtendedResponse:

break;
```

{% endcode %}

{% code overflow="wrap" %}

```
case EVENT_TYPE_DeviceNotification:

break;
```

{% endcode %}

{% code overflow="wrap" %}

```
case EVENT_TYPE_CardData:

break;
```

{% endcode %}

{% code overflow="wrap" %}

```
case EVENT_TYPE_TransactionStatus:
// Parse for the transaction status code and detail. TransactionStatus status = TransactionStatusBuilder::GetStatusCode(data.StringValue);

string statusDetail = TransactionStatusBuilder::GetString(data.StringValue);

break;
```

{% endcode %}

{% code overflow="wrap" %}

```
case EVENT_TYPE_DisplayMessage:

string message;

// Get the message.
message = data.StringValue;

break;
```

{% endcode %}

{% code overflow="wrap" %}

```
case EVENT_TYPE_AuthorizationRequest:

// Forward the ARQC to processor.
/* data.ByteArray[0..1] – ARQC length
data.ByteArray[2..n] – remainder contains the ARQC TLV object
*/
IData ARQC = data;

// App function to send the request to the processor.
string ARPC = sendARQCToProcessorForApproval(ARQC.ByteArray);

// Send authorization to device when not in QuickChip mode. IData ARPCTLV;
ARPCTLV.StringValue = "FF7413DFDF250742363243413546FA067004” + ARPC;

if (transaction.QuickChip == false)
{
device->sendAuthorization(ARPCTLV);
}

break;
```

{% endcode %}

{% code overflow="wrap" %}

```
case EventType.TransactionResult

/* data.ByteArray[0] – Signature Required
data.ByteArray[1..2] – Batch Data length
data.ByteArray[3..n] – remainder contains the Batch Data TLV object
*/
// Parse the TLV from data[].
// Abstract Approval status from TLV tag “DFDF1A”.
// Abstract Signature Required status from TLV tag at data.ByteArray
// [0].

break;
```

{% endcode %}

{% code overflow="wrap" %}

```
case EventType.TransactionStatus:
/*
Transaction status enumeration is build from the TransactionStatusBuilder.

*/
TransactionStatus status = TransactionStatusBuilder::GetStatusCode(data.StringValue);
if (status == TransactionStatusBuilder::MTUSDKTS_CARD_SWIPED)
{
//
}
if (status == TransactionStatusBuilder::MTUSDKTS_CARDINSERTED)
{
//
}

if (status == TransactionStatusBuilder:: MTUSDKTS_TRANSACTION_APPROVED)
{
//
}

break;
```

{% endcode %}

## IDeviceControl Walk Through <a href="#a.3_idevicecontrol_walk_through" id="a.3_idevicecontrol_walk_through"></a>

The following walks through how to make use of IDeviceControl.

* IDevice --> IDeviceControl.
* IDeviceControl --> open().
* IDeviceControl --> other functions.
* IDeviceControl --> close().

**Example**

{% code overflow="wrap" %}

```
// Establish a device from CoreAPI. 
vector<IDevice*> devices = 
CoreAPI::getDeviceList(MTU_DEVICE_TYPE::MMS); 
IDevice* device = devices.at(0);


// Establish a deviceControl from device.
IDeviceControl* deviceControl = device->getDeviceControl();

// Open the device, then use the IDeviceControl functions. 
deviceControl->open();

. . .

// Close the device. 
deviceControl->close();
```

{% endcode %}

## ConnectionInfo Walk Through <a href="#a.4_connectioninfo_walk_through" id="a.4_connectioninfo_walk_through"></a>

The following walks through how to make use of ConnectionInfo.

* IDevice --> ConnectionInfo.
* ConnectionInfo --> getAddress()
* ConnectionInfo --> getConnectionType()
* ConnectionInfo --> getDeviceType() Example

**Example**

{% code overflow="wrap" %}

```
// Establish a device from CoreAPI. 
vector<IDevice*> devices = 
CoreAPI::getDeviceList(MTU_DEVICE_TYPE::MMS); 
IDevice* device = devices.at(0);

// Establish a ConnectionInfo from device.
ConnectionInfo connectionInfo = device->getConnectionInfo();

// Retrieve address, connectionType, and deviceType. 
string address = connectionInfo.getAddress();

MTU_DEVICE_CONNECTION_TYPE connectionType = 
connectionInfo.getConnectionType();

MTU_DEVICE_TYPE deviceType = connectionInfo.getDeviceType();
```

{% endcode %}

## DeviceCapability Walk Through <a href="#a.5_devicecapability_walk_through" id="a.5_devicecapability_walk_through"></a>

The following walks through how to make use of DeviceCapability

* IDevice --> DeviceCapability.
* DeviceCapability --> BatteryBackedClock() to check if date/time should be set.
* DeviceCapability --> PaymentMethods() to check card types supported.
* DeviceCapability --> other functions.

{% code overflow="wrap" %}

```
// Establish a device from CoreAPI. 
vector<IDevice*> devices = 
CoreAPI::getDeviceList(MTU_DEVICE_TYPE::MMS); 
IDevice* device = devices.at(0);


// Establish a DeviceCapability from device. 
DeviceCapability capabilities = device->getCapabilities();

// Retrieve device capabilities.
bool batteryBackedClock = capabilities.BatteryBackedClock(); if (batteryBackedClock)
{
// Call IDeviceControl->setDateTime().
}

// Retrieve supported card payment methods.
PaymentMethods paymentMethods = capabilities.PaymentMethods();

. . .
```

{% endcode %}

## IDeviceConfiguration Walk Through <a href="#a.6_ideviceconfiguration_walk_through" id="a.6_ideviceconfiguration_walk_through"></a>

The following walks through how to make use of IDeviceConfiguration.

* IDevice --> getConfiguration().
* IDeviceConfiguration --> updateFirmware().
* IDeviceConfiguration --> getConfiguration().
* IDeviceConfiguration --> setConfiguration().
* IDeviceConfiguration --> other functions.

**Example**

<pre data-overflow="wrap"><code>// Establish a device from CoreAPI. 
vector&#x3C;IDevice*> devices = 
CoreAPI::getDeviceList(MTU_DEVICE_TYPE::MMS); 
IDevice* device = devices.at(0);
 
IDeviceConfiguration* devConfig = device->getConfiguration(); 
IDeviceControl* devControl = device.getDeviceControl(); 
devControl->open();
 
 
// Update firmware. 
vector&#x3C;unsigned char> data;
ifstream fw("firmware.bin", ifstream::binary); 
if (fw)
{
        while (!fw.eof())
        {
                int aByte = fw.get(); 
                data.push_back(aByte);
        }
}
 
int return = devConfig->updateFirmware(0x01, data, &#x26;MainWindow);
 
/* Get configuration.
<strong>        Device-Driven Fallback OID = 1.2.1.1.1.1
</strong>                contructed OID = E2 08 E1 06 E1 04 E1 02 C1 00
        Note: first digit of OID is ommited in the construction and instead 
is passed in the configType.
*/
unsigned char configType = 0x01; 
vector&#x3C;unsigned char> data2 =
{0xE2,0x08,0xE1,0x06,0xE1,0x04,0xE1,0x02,0xC1,0x00 };
vector&#x3C;unsigned char> response = devConfig->getConfigInfo(configType, 
data2);
 
/* Set configuation.
Device-Driven Fallback OID is 1.2.1.1.1.1
                Disabled contructed OID = E2 09 E1 07 E1 05 E1 03 C1 01 00
                Enabled contructed OID = E2 09 E1 07 E1 05 E1 03 C1 01 01
        Note: first digit of OID is ommited in the construction and instead is passed in the configType.

*/
vector&#x3C;unsigned char> data3 =
{0xE2,0x09,0xE1,0x07,0xE1,0x05,0xE1,0x03,0xC1,0x01,0x00};
return = devConfig->setConfigInfo(configType, data3, &#x26;MainWindow);
</code></pre>

## **Handling Events**

Application Main window may extent the IConfigurationCallback Delegates or can be extended by a separate class. This example uses a separate class and demonstrates how to parse for the various events.

**Example**

{% code overflow="wrap" %}

```
// A class to handle configuration callback events. class ConfigCallbacks : public IConfigurationCallback public:
{
        virtural void OnProgress(int progress)
        {
                /* Handle progress.
                Progress is complete when progress = 100 */
}
```

{% endcode %}

{% code overflow="wrap" %}

```
virtual void OnResult(int status, vector<unsigned char> data)
{
        /* Handle result.
                A configuration process is complete when 
                status = StatusCode.Success */
}
```

{% endcode %}

{% code overflow="wrap" %}

```
    IResult OnCalculateMAC(unsigned char MACType, vector<unsigned char> 
data)
{

        /* Handle MAC */ 
        return result;
    }
}
```

{% endcode %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://developer.magtek.com/sdks-and-tools/universal-sdk-documentation/linux/appendices/appendix-a-api-walk-through.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
