Got questions? Connect with our experts on Vantiv ONE.
XCode iOS application capturing encrypted credit card swipe from MagTek peripheral and processing transactions to our web services platform.
Built with Xcode Version 6.1.1
Latest MagTek libMTSCRA.a added which provides for arm64 for both sdk and simulator (12/19/2014)
Add MTSCRA.h and libMTSCRA.a to your project
Add key "Supported external accessory protocols" Under above key add new item value of "com.magtek.idynamo"
self.magTek = [[MTSCRA alloc] init];
[self.magTek listenForEvents:(TRANS_EVENT_OK|TRANS_EVENT_START|TRANS_EVENT_ERROR)];
[self.magTek setDeviceProtocolString:(@"com.magtek.idynamo")];
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
[nc addObserver:self selector:@selector(trackDataReady:) name:@"trackDataReadyNotification" object:nil];
[nc addObserver:self selector:@selector(devConnStatusChange) name:@"devConnectionNotification" object:nil];
- (void)trackDataReady:(NSNotification *)notification
{
NSNumber *status = [[notification userInfo] valueForKey:@"status"];
[self performSelectorOnMainThread:@selector(onDataEvent:)
withObject:status
waitUntilDone:NO];
}
- (void)onDataEvent:(id)status
{
switch ([status intValue]) {
case TRANS_STATUS_OK:
NSLog(@"TRANS_STATUS_OK");
self.encryptedSwipeData = [[EncryptedSwipeData alloc] init];
self.encryptedSwipeData.track1Masked = self.magTek.getTrack1Masked;
self.encryptedSwipeData.track2Masked = self.magTek.getTrack2Masked;
self.encryptedSwipeData.track1Encrypted = self.magTek.getTrack1;
self.encryptedSwipeData.track2Encrypted = self.magTek.getTrack2;
self.encryptedSwipeData.ksn = self.magTek.getKSN;
AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
appDelegate.encryptedSwipeData = self.encryptedSwipeData;
break;
case TRANS_STATUS_ERROR:
NSLog(@"TRANS_STATUS_ERROR");
break;
default:
break;
}
}
Create a NSMutableDictionary and add all the Key Value Pairs.
AppDelegate *ad = (AppDelegate*)[[UIApplication sharedApplication] delegate];
NSMutableDictionary *dictionaryReq = [NSMutableDictionary new];
[dictionaryReq setObject:@"118725340908147" forKey:@"MerchantID"];
[dictionaryReq setObject:@"018847445761734" forKey:@"MerchantID"];
[dictionaryReq setObject:@"Credit" forKey:@"TranType"];
[dictionaryReq setObject:@"Sale" forKey:@"TranCode"];
[dictionaryReq setObject:@"12345" forKey:@"InvoiceNo"];
[dictionaryReq setObject:@"12345" forKey:@"RefNo"];
[dictionaryReq setObject:@"MercuryHelper 1.0.1" forKey:@"Memo"];
[dictionaryReq setObject:@"Allow" forKey:@"PartialAuth"];
[dictionaryReq setObject:@"MagneSafe" forKey:@"EncryptedFormat"];
[dictionaryReq setObject:@"Swiped" forKey:@"AccountSource"];
[dictionaryReq setObject:ad.encryptedSwipeData.track2Encrypted forKey:@"EncryptedBlock"];
[dictionaryReq setObject:ad.encryptedSwipeData.ksn forKey:@"EncryptedKey"];
[dictionaryReq setObject:@"OneTime" forKey:@"Frequency"];
[dictionaryReq setObject:@"RecordNumberRequested" forKey:@"RecordNo"];
[dictionaryReq setObject:@"1.01" forKey:@"Purchase"];
[dictionaryReq setObject:@"test" forKey:@"Name"];
[dictionaryReq setObject:@"MPS Terminal" forKey:@"TerminalName"];
[dictionaryReq setObject:@"MPS Shift" forKey:@"ShiftID"];
[dictionaryReq setObject:@"test" forKey:@"OperatorID"];
[dictionaryReq setObject:@"4 Corporate SQ" forKey:@"Address"];
[dictionaryReq setObject:@"30329" forKey:@"Zip"];
[dictionaryReq setObject:@"123" forKey:@"CVV"];
Create MercuryHelper object and call the transctionFromDictionary method with the NSMutalbeDictionary and merchant's password.
MercuryHelper *mgh = [MercuryHelper new];
mgh.delegate = self;
[mgh transctionFromDictionary:dictionaryReq andPassword:@"xyz"];
Parse the Response using in the transactionDidFinish delegate.
Approved transactions will have a CmdStatus equal to "Approved".
-(void) transactionDidFinish:(NSDictionary *)result {
if ([result objectForKey:@"CmdStatus"]
&& [[result objectForKey:@"CmdStatus"] isEqualToString:@"Approved"]) {
// Approved logic here
} else {
// Declined logic here
}
}