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.
}This section demonstrates transaction flow.
The following breaks out the EMV flow chart into code. When enabling QuickChip mode, host does not send the ARPC to the device to complete the transaction. Events are shown separately and in the order received.
// Assign parameters.
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.
var result: BOOL = device.startTransaction(transaction)func onEvent(_ eventType: MTU_EventType, data: IData!)
{
var message: NSString = “”
switch eventType
{
case MTU_EventType_DisplayMessage:
// Get the message.
message = data.StringValue
}
} func onEvent(_ eventType: MTU_EventType, data: IData!)
{
var message: NSString = “”
switch eventType
{
case MTU_EventType_InputRequest:
// Get the message.
message = data.StringValue
// display/retrieve user selection.
// set status and selection result.
var statusSelection: NSString* = "0001"
var selectionData: IData = IData.dataWithHex(statusSelection);
device.sendSelection(selectionData)
}
}func onEvent(_ eventType: MTU_EventType, data: IData!)
{
var ARQC[]: Byte = nil; switch eventType
{
case MTU_EventType_AuthorizationRequest:
// Forward ARQC to processor.
/* data[0..1] – ARQC length
data[2..n] – remainder contains the ARQC TLV object */
}
}func onEvent(_ eventType: MTU_EventType, data: IData!)
{
var message: NSString = “”
switch eventType
{
case MTU_EventType_DisplayMessage:
// Display approval message.
message = data.StringValue
// A data size of 0 is an instruction to clear the display.
if (data.StringValue.count == 0)
{
// Clear the UI display.
}
}
}func onEvent(_ eventType: MTU_EventType, data: IData!)
{
switch eventType
(
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 data[0].
}
}
The following breaks out the EMV flow chart into code. Events are shown separately and in the order received.
// Assign parameters.
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.
var result: BOOL = device.startTransaction(transaction)func onEvent(_ eventType: MTU_EventType, data: IData!)
{
var message: NSString = ""
switch eventType
{
case MTU_EventType_DisplayMessage:
// Get the message.
message = data.StringValue
}
}func onEvent(_ eventType: MTU_EventType, data: IData!)
{
var message: NSString = ""
switch eventType
{
case MTU_EventType_InputRequest:
// Get the message.
message = data.StringValue
// display/retrieve user selection.
// set status and selection result.
var statusSelection: NSString* = "0001"
IData* selectionData = IData dataWithHex(statusSelection);
device.sendSelection(selectionData);
}
} func onEvent(_ eventType: MTU_EventType, data: IData!)
{
var ARQC[]: Byte = nil; switch eventType
{
case MTU_EventType_AuthorizationRequest:
// Forward ARQC to processor.
/* data[0..1] – ARQC length
data[2..n] – remainder contains the ARQC TLV object */
}
}func onEvent(_ eventType: MTU_EventType, data: IData!)
{
var message: NSString = ""
switch eventType
{
case MTU_EventType_DisplayMessage:
// Display approval message.
message = data.StringValue;
// A data size of 0 is an instruction to clear the display.
if (data.StringValue.count == 0)
{
// Clear the UI display.
}
}
}func onEvent(_ eventType: MTU_EventType, data: IData!)
{
switch eventType
{
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 data[0].
}
}func onEvent(_ eventType: MTU_EventType, data: IData!)
{
var signature: NSString = “”;
switch eventType
{
case MTU_EventType_Signature:
signature = data.StringValue;
}
}The following breaks out the EMV flow chart into code. When disabling QuickChip mode, host must send the ARPC to the device to complete the transaction. Events are shown separately and in the order received.
// Assign parameters.
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:false
);
// Start transaction.
var result: BOOL = device.startTransaction(transaction)func onEvent(_ eventType: MTU_EventType, data: IData!)
{
var message: NSString = ""
switch eventType
{
case MTU_EventType_DisplayMessage:
// Get the message.
message = data.StringValue
}
}func onEvent(_ eventType: MTU_EventType, data: IData!)
{
var message: NSString = "";
switch eventType
{
case MTU_EventType_InputRequest:
// Get the message.
message = data.StringValue
// display/retrieve user selection.
// set status and selection result.
var statusSelection: NSString = "0001"
var selectionData: IData* = IData
dataWithHex(statusSelection);
device.sendSelection(selectionData)
}
}func onEvent(_ eventType: MTU_EventType, data: IData!)
{
var ARQC: IData = data;
switch eventType
{
case MTU_EventType_AuthorizationRequest:
// Forward ARQC to processor.
/* data[0..1] – ARQC length
data[2..n] – remainder contains the ARQC TLV object */
ARPC = sendARQCToProcessorForApproval(ARQC.ByteArray)
}
}After the ARPC is returned from the processor, it is constructed into a TLV container and then sent to the device. The ARPC for approved (00) is set in ASCII 3030.
The optional tags 91, 71, and 72 (Issuer Authentication Data, Issuer Script Template 1, and Issuer Script Template 2) are not included in this example.
See the construction of the ARPCTLV in the table below.
var ARPC: NSString = “8A3030”;
var ARPCTLV: IData = IData();
ARPCTLV.StringValue = "FF7413DFDF250742363243413546FA067004” + ARPC
device.sendAuthorization(ARPCTLV)The use case for an MSR fallback is when communication with the chip results in a terminated transaction and the TransactionStatus is reported as MSRFallback.
The host application will re-attempt the transaction. To invoke this use case, here are the following pre-requisites.
Pre-requisites:
Device already configured for Device-Driven Fallback = Disabled.
A card to cause the fallback. Example but not limited to a card with no applications programmed or a card with an application not configured on the device.
Scheme:
-->Host begins an initial transaction with PaymentMethod set to MSR+Chip+Contactless.
<--Device responds with fail and with status of MSRFallback.
-->Host displays a message to use magnetic stripe.
-->Host starts a transaction with PaymentMethod set to MSR.
-->Host displays a message each time the transaction fails until successful or until Host decides to end the transaction.
<--Device sends the transaction result.
Tag
Len
Value / Description
Typ
Req
Default
FF74
var
Container for non-MAC ARPC
T
R
/DFDF25
var
Device Serial Number (IFD Serial Number)
B
R
Tag
Len
Value / Description
Typ
Req
Default
///71
var
Issuer Script Template 1
As defined in EMV Integrated Circuit Card Specifications for Payment Systems 4.3. The host may include as many instances of this parameter as needed, up to a maximum length of 128 bytes including Tags and Lengths.
B
O
///72
var
Issuer Script Template 2
As defined in EMV Integrated Circuit Card Specifications for Payment Systems 4.3. The host may include as many instances of this parameter as needed, up to a maximum length of 128 bytes including Tags and Lengths.
B
func onEvent(_ eventType: MTU_EventType, data: IData!)
{
var message: NSString = ""
switch eventType
{
case MTU_EventType_DisplayMessage:
// Display approval message.
message = data.StringValue
// A data size of 0 is an instruction to clear the display.
if (data.StringValue.count == 0)
{
// Clear the UI display.
}
}
}func onEvent(_ eventType: MTU_EventType, data: IData!)
{
switch eventType
{
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 data[0].
}
}func onEvent(_ eventType: MTU_EventType, data: IData!)
{
var signature: NSString* = ""
switch eventType
{
case MTU_EventType_Signature:
signature = data.StringValue
}
}


/FA
var
Container for generic data
T
R
//70
var
Container for ARPC
T
R
///8A
02
Authorization Response Code
· 0x3030 = Approved
· 0x3031 = Issuer Referral
· 0x3035 = Declined
· 0x3132 = Switch Interface
· 0x3133 = Request Online PIN
AN
R
///91
var
Issuer Authentication Data
As defined in EMV Integrated Circuit Card Specifications for Payment Systems 4.3
B
O
O
Worked examples for the MagTek Universal SDK for iOS: a walk-through of the main interfaces with sample code, from creating a device through handling delegate events, and the EMV transaction sequence showing where your app’s code fits in a chip-card payment.
Reference Section
Information Available
Sample code showing the call sequence for each major interface: device discovery and creation through CoreAPI, transactions through IDevice, commands through IDeviceControl, and configuration reads and writes through IDeviceConfiguration.
The sequence of calls and events in an EMV chip transaction, from startTransaction through the ARQC authorization request, sendAuthorization with the processor’s ARPC, and the transaction result.