<dict> <key>Title</key> <string>payment-group</string> <key>Type</key> <string>PSGroupSpecifier</string> </dict> <dict> <key>AutocapitalizationType</key> <string>None</string> <key>AutocorrectionType</key> <string>No</string> <key>DefaultValue</key> <string></string> <key>IsSecure</key> <false/> <key>Key</key> <string>payworks-merchantIdentifier</string> <key>KeyboardType</key> <string>Alphabet</string> <key>Title</key> <string>payworks-user</string> <key>Type</key> <string>PSTextFieldSpecifier</string> </dict> <dict> <key>AutocapitalizationType</key> <string>None</string> <key>AutocorrectionType</key> <string>No</string> <key>DefaultValue</key> <string></string> <key>IsSecure</key> <true/> <key>Key</key> <string>payworks-merchantSecretKey</string> <key>KeyboardType</key> <string>Alphabet</string> <key>Title</key> <string>payworks-password</string> <key>Type</key> <string>PSTextFieldSpecifier</string> </dict>
"payment-group" = "Payment"; "payworks-user" = "payworks User"; "payworks-password" = "payworks Password";
NSString* merchantIdentifier = [[NSUserDefaults standardUserDefaults] stringForKey:@"payworks-merchantIdentifier"]; NSString* merchantSecretKey = [[NSUserDefaults standardUserDefaults] stringForKey:@"payworks-merchantSecretKey"]; if(merchantIdentifier == nil || [merchantIdentifier isEqualToString:@""] || merchantSecretKey == nil || [merchantSecretKey isEqualToString:@""]) { // credentials are not set! Instruct user how to get credentials UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Missing credentials" message:@"Your username and/or password for using payment functionality is not set. Go to the settings and enter your username and password." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; [alert show]; return; }
yourapp://payworks/configuration?payworks-username=<merchantIdentifier>&payworks-password=<merchantSecretKey>
<key>CFBundleURLTypes</key> <array> <dict> <key>CFBundleURLName</key> <string>io.payworks.config</string> <key>CFBundleURLSchemes</key> <array> <string>yourapp</string> </array> </dict> </array>
- (NSDictionary *)parseQueryString:(NSString *)query { NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithCapacity:6]; NSArray *pairs = [query componentsSeparatedByString:@"&"]; for (NSString *pair in pairs) { NSArray *elements = [pair componentsSeparatedByString:@"="]; NSString *key = [[elements objectAtIndex:0] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; NSString *val = [[elements objectAtIndex:1] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; [dict setObject:val forKey:key]; } return dict; } - (void) showError { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Could not configure payment" message:@"The link you clicked seems to be broken." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; [alert show]; } - (void) showSuccess { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Payment has been configured" message:@"You can do transactions now!" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; [alert show]; } - (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url { // handler code here if([[url host] isEqualToString:@"payworks"] && [[url path] isEqualToString:@"/configuration"]) { NSDictionary *dict = [self parseQueryString:[url query]]; if([dict objectForKey:@"payworks-username"] && [dict objectForKey:@"payworks-password"]) { NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults]; [defaults setObject:[dict objectForKey:@"payworks-username"] forKey:@"payworks-merchantIdentifier"]; [defaults setObject:[dict objectForKey:@"payworks-password"] forKey:@"payworks-merchantSecretKey"]; [self showSuccess]; } else { [self showError]; } } else { [self showError]; } return YES; }