All pages
Powered by GitBook
1 of 1

Loading...

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.

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

#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);

IDevice Walk Through

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

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

Various events are separately shown below.

The following walks through how to make use of IDeviceControl.

  • IDevice --> IDeviceControl.

  • IDeviceControl --> open().

  • IDeviceControl --> other functions.

  • IDeviceControl --> close().

Example

The following walks through how to make use of ConnectionInfo.

  • IDevice --> ConnectionInfo.

  • ConnectionInfo --> getAddress()

  • ConnectionInfo --> getConnectionType()

  • ConnectionInfo --> getDeviceType() Example

Example

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.

The following walks through how to make use of IDeviceConfiguration.

  • IDevice --> getConfiguration().

  • IDeviceConfiguration --> updateFirmware().

  • IDeviceConfiguration --> getConfiguration().

  • IDeviceConfiguration --> setConfiguration().

  • IDeviceConfiguration --> other functions.

Example

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

Handling Events

IDeviceControl Walk Through

ConnectionInfo Walk Through

DeviceCapability Walk Through

IDeviceConfiguration Walk Through

Handling Events

#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);
// A class to handle events.
class MainWindow : public IEventSubscriber
{
virtual void OnEvent(EventType eventType, IData data)
{
switch (eventType)
{
case EVENT_TYPE_ConnectionState:
// Parse for the ConnectionState ConnectionState value =
ConnectionStateBuilder::GetValue(data.StringValue);

break;
case EVENT_TYPE_DeviceResponse:

break;
case EVENT_TYPE_DeviceExtendedResponse:

break;
case EVENT_TYPE_DeviceNotification:

break;
case EVENT_TYPE_CardData:

break;
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;
case EVENT_TYPE_DisplayMessage:

string message;

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

break;
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;
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;
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;
// 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();
// 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();
// 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();

. . .
// Establish a device from CoreAPI. 
vector<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<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, &MainWindow);
 
/* Get configuration.
        Device-Driven Fallback OID = 1.2.1.1.1.1
                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<unsigned char> data2 =
{0xE2,0x08,0xE1,0x06,0xE1,0x04,0xE1,0x02,0xC1,0x00 };
vector<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<unsigned char> data3 =
{0xE2,0x09,0xE1,0x07,0xE1,0x05,0xE1,0x03,0xC1,0x01,0x00};
return = devConfig->setConfigInfo(configType, data3, &MainWindow);
// 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 */
}
virtual void OnResult(int status, vector<unsigned char> data)
{
        /* Handle result.
                A configuration process is complete when 
                status = StatusCode.Success */
}
    IResult OnCalculateMAC(unsigned char MACType, vector<unsigned char> 
data)
{

        /* Handle MAC */ 
        return result;
    }
}