The following walks through how to create instances of a device.
CoreAPI.createDevice() --> IDevice
CoreAPI.setDeviceType()
CoreAPI.startScanningForPeripherals --> onDeviceList()
These examples demonstrate methods for creating an IDevice to be used in the MagTek Universal SDK. This also shows how to establish a device specific API, which is not used with the MagTek Universal SDK.
Here, a single IDevice is established.
// Access MMS with Universal SDK using createDevice()
var mtmms: IDevice = CoreAPI.createDevice(
MTU_DeviceType_MMS,
connection: MTU_ConnectionType_ WEBSOCKET,
address: "ws://b123456.magtek.com",
model: "DynaFlex",
name: webSocketAddress,
serial: "B123456",
cert: Certificate)BLE device
iAP2 Lightning device.
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. This example demonstrates how to parse for the 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.
ConnectionInfo --> getAddress()
ConnectionInfo --> getConnectionType()
ConnectionInfo --> getDeviceType() Example
The following walks through how to make use of IDeviceCapability.
IDeviceCapability Γ BatteryBackedClock() to check if date/time should be set.
IDeviceCapability Γ PaymentMethods() to check card types supported.
IDeviceCapability Γ other functions.
The following walks through how to make use of IDeviceConfiguration.
IDevice Γ getDeviceConfiguration().
IDeviceConfiguration Γ updateFirmware().
IDeviceConfiguration Γ getConfiguration().
IDeviceConfiguration Γ setConfiguration().
IDeviceConfiguration Γ other functions.
Example
Application Main window may extent the IConfigurationCallback Delegates. This example demonstrates how to parse for the various events.
Example
// Access BLE device with Universal SDK
private let mtusdkShared = CoreAPI.shared()
mtusdkShared.setDeviceType(MTU_DeviceType_MMS, andConnectionType: MTU_ConnectionType_BLUETOOTH_LE_EMV)
mtusdkShared.mtuSDKDelegate = self
mtusdkShared.startScanningForPeripherals()// Acess onDeviceList()
func onDeviceList(_ instance: Any, withConnectionType:
MTU_ConnectionType, deviceList: [Any])
{
if let devices = deviceList as? [IDevice] {
deviceAddressList = []
}
}// Acess iAP2 device with Universal SDK
private let mtusdkShared = CoreAPI.shared()
mtusdkShared.setDeviceType(MTU_DeviceType_MMS, andConnectionType: MTU_ConnectionType_EXTERNAL_ACCESSORY)
mtusdkShared.setupEADeviceProtocolString(MTUConstant.dynaFlex2GoProtoc
olString)
mtusdkShared.mtuSDKDelegate = self
mtusdkShared.turnEAAccessoryConnectionNotificationsOn() mtusdkShared.showConnectedEAAccessoryIfAny()// Acess onDeviceList()
func onDeviceList(_ instance: Any, withConnectionType:
MTU_ConnectionType, deviceList: [Any])
{
if let devices = deviceList as? [IDevice] {
deviceAddressList = []
}
}// Extend the main window to receive events. @interface MTUSCK_DynaFlex : <IEventSubscriber, IConfigurationCallback>
// Establish a device from CoreAPI.
var device: IDevice = CoreAPI.createDevice(
MTU_DeviceType_MMS,
connection:MTU_ConnectionType_ WEBSOCKET,
address:"ws://b123456.magtek.com",
"",
"DynaFlex",
"",
cert:Certificate)
/* 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. */ var result: Bool = device.subscribeAll(self)
// Assign parameters for the transaction.
var transaction: ITransaction = ITransaction( Amount:β1.00β,
CashBack:β0.00β, TransactionType:0, Timeout:30,
For:MTU_PaymentMethod_MSR | MTU_PaymentMethod_Contact | MTU_PaymentMethod_Contactless,
QuickChip:true
)
// Start transaction.
result = device.startTransaction(transaction)
@interface MTUSCK_DynaFlex : <IEventSubscriber, IConfigurationCallback>
func onEvent(_ eventType: MTU_EventType, data: IData!)
{
switch eventType
{@interface MTUSCK_DynaFlex : <IEventSubscriber,
IConfigurationCallback>
func onEvent(_ eventType: MTU_EventType, data: IData!)
{
switch eventType
{case MTU_EventType_ConnectionState:
// Parse for the ConnectionState
var value: MTU_ConnectionState = ConnectionStateBuilder.GetValue(data)
break;case MTU_EventType_DeviceResponse:
break;case MTU_EventType_DeviceExtendedResponse:
break;case MTU_EventType_DeviceNotification:
break;case MTU_EventType_CardData:
break;case MTU_EventType_DisplayMessage:
// Get the message.
var message: NSString = data.StringValue
break;case MTU_EventType_InputRequest:
break;case MTU_EventType_AuthorizationRequest:
// Forward ARQC to processor.
/* data[0..1] β ARQC length
data[2..n] β remainder contains the ARQC TLV object
*/
var ARQC: IData = IData.dataWithData(data.ByteArray)
// App function to send the request to the processor.
var ARPC: NSString =
sendARQCToProcessorForApproval(ARQC.data.ByteArray);
// Send authorization to device when not in QuickChip mode.
var ARPCTLV: IData = IData.alloc(init);
ARPCTLV.StringValue = "FF7413DFDF250742363243413546FA067004β + ARPC;
if transaction.QuickChip == false
{
device.sendAuthorization(ARPCTLV)
}
break;case MTU_EventType_TransactionResult:
/* data[0] β Signature Required
data[1..2] β Batch Data length
data[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[0].
break;case EventType.PINData:
break; case MTU_EventType_Signature:
break; case MTU_EventType_TransactionStatus:
/*
Transaction status enumeration is build from the TransactionStatusBuilder.
*/
var status: MTU_TransactionStatus = TransactionStatusBuilder.
GetStatusCode(data.StringValue);
if status == MTU_TransactionStatus_CardSwiped
{
//
}
if status == MTU_TransactionStatus_CardInserted
{
//
}
if status == MTU_TransactionStatus_TransactionApproved
{
//
}
break;// Establish a deviceControl from device.
var deviceControl: IDeviceControl = device.getDeviceControl
// Open the device, then use the IDeviceControl functions. var result: BOOL = deviceControl.open()
. . .
// Close the device.
result = deviceControl.close()// Establish a ConnectionInfo from device.
var connectionInfo: ConnectionInfo = device.getConnectionInfo()
// Retrieve address, connectionType, and deviceType.
var address: NSString = connectionInfo.getAddress()
var connectionType: MTU_ConnectionType = connectionInfo
.getConnectionType()
var deviceType: MTU_DeviceType = connectionInfo.getDeviceType()// Establish a IDeviceCapabilities from device. DeviceCapabilities* capabilities = device.getDeviceCapability
// Retrieve device capabilities.
BOOL batteryBackedClock = capabilities.BatteryBackedClock() if (batteryBackedClock)
{
// Call IDeviceControl setDateTime
}
// Retrieve supported card payment methods.
MTU_PaymentMethod paymentMethods = capabilities.PaymentMethodsIDeviceConfiguration* devConfig = device.getDeviceConfiguration
IDeviceControl* devControl = device.getDeviceControl result = devControl.open()
// Update firmware.
var error: IData*
var fileData: NSData = NSData.dataWithContentsOfFile(
"/Users/UserName/DynaFlex/fw.bin",
options: NSDataReadingUncached,
error: &error);
var return: Int = devConfig.updateFirmware(1, data: fileData,
callback: self)
/* 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.
*/
var configType: Byte = 1;
var str: NSString = "E208E106E104E102C100"
var data: NSData= HexUtil.getBytesFromHexString(str)
var response: NSData = devConfig.getConfigInfo(configType, data)
/* 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.
*/
configType = 1
str = "E209E107E105E103C10101"
data NSData = HexUtil.getBytesFromHexString(str)
return = devConfig.setConfigInfo(configType, data, callback:self)func onProgress(_ progressValue: Int32)
{
}func onResult(_ status: MTU_StatusCode, data: Data)
{
/* Handle result.
A configuration process is complete when status = MTU_StatusCode_Success */
} func OnCalculateMAC (_ macType: UInt8, data: Data) -> IResult
{
//Calculate MAC.
}