How to Integrate payment using Authorize.Net for iOS - ios

I have integrated authorize.net into my iOS application. I did steps in this tutorial
https://developer.authorize.net/integration/fifteenminutes/ios/
- (void) loginToGateway {
MobileDeviceLoginRequest *mobileDeviceLoginRequest =
[MobileDeviceLoginRequest mobileDeviceLoginRequest];
mobileDeviceLoginRequest.anetApiRequest.merchantAuthentication.name = <USERNAME>;
mobileDeviceLoginRequest.anetApiRequest.merchantAuthentication.password = <PASSWORD>;
mobileDeviceLoginRequest.anetApiRequest.merchantAuthentication.mobileDeviceId =
[[[UIDevice currentDevice] uniqueIdentifier]
stringByReplacingOccurrencesOfString:#"-" withString:#"_"];
AuthNet *an = [AuthNet getInstance];
[an setDelegate:self];
[an mobileDeviceLoginRequest: mobileDeviceLoginRequest];
}
But request responsive:
- (void) requestFailed:(AuthNetResponse *)response{
NSLog(#"ViewController : requestFailed - %#",response);
[_activityIndicator stopAnimating];
UIAlertView *infoAlertView = [[UIAlertView alloc] initWithTitle:#"Login Error" message:INFORMATION_MESSAGE delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
[infoAlertView show];
}
What's to fill in here?
mobileDeviceLoginRequest.anetApiRequest.merchantAuthentication.name = <USERNAME>;
mobileDeviceLoginRequest.anetApiRequest.merchantAuthentication.password = <PASSWORD>;

The Name and Password are the Login ID and Password for a user created in the Merchant Interface. If you specified the test environment and are connecting to the sandbox, this would be the username and password you use to login to https://sandbox.authorize.net
You may wish to review the integrating mobile payments training video available on http://developer.authorize.net/api/mobile for an overview.

Related

Error in sending app invitation in ios to facebook friends

I am trying to send app invitation to facebook friends but getting the following error
app invite error:Error Domain=com.facebook.sdk.core Code=9 "The operation couldn’t be completed. (com.facebook.sdk.core error 9.)"
below is my code
-(IBAction)buttonTapped:(id)sender {
FBSDKAppInviteContent *content = [[FBSDKAppInviteContent alloc] init];
content.appLinkURL = [NSURL URLWithString:#"https://fb.me/115385318808986"];
[FBSDKAppInviteDialog showWithContent:content
delegate:self];
}
#pragma mark - FBSDKAppInviteDialogDelegate
- (void)appInviteDialog:(FBSDKAppInviteDialog *)appInviteDialog didCompleteWithResults:(NSDictionary *)results
{
// Intentionally no-op.
}
- (void)appInviteDialog:(FBSDKAppInviteDialog *)appInviteDialog didFailWithError:(NSError *)error
{
NSLog(#"app invite error:%#", error);
NSString *message = error.userInfo[FBSDKErrorLocalizedDescriptionKey] ?:
#"There was a problem sending the invite, please try again later.";
NSString *title = error.userInfo[FBSDKErrorLocalizedTitleKey] ?: #"Oops!";
[[[UIAlertView alloc] initWithTitle:title message:message delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil] show];
}
and when I am trying to print the error.userInfo it shows a blank dictionary. Please guide.
For facebook sdk 4.0 and later
at first create an applink.
FBSDKAppInviteContent *content =[[FBSDKAppInviteContent alloc] init];
content.appLinkURL = [NSURL URLWithString:#"https://www.google.com/myapplink"];
//optionally set previewImageURL
content.appInvitePreviewImageURL = [NSURL URLWithString:#"https://www.google.com/my_invite_image.jpg"];
// present the dialog. Assumes self implements protocol `FBSDKAppInviteDialogDelegate`
[FBSDKAppInviteDialog showWithContent:content
delegate:self];
see this link https://developers.facebook.com/docs/app-invites/ios
EDIT:
when you create an app link and you have to provide an url scheme,this url scheme added in your project info plist.after that you add a face book canvas platform in face book developer setting page,and provide a canvas url and save it.
If you've been looking everywhere like me to figure out why it's not working, turns out Facebook is deprecating App Invites and will completely stop working as of 2/6/2018:
https://developers.facebook.com/blog/post/2017/11/07/changes-developer-offerings/
I had this error as well. What fixed it was adding
[FBSDKAppEvents activateApp];
in applicationDidBecomeActive:(UIApplication *)application
within the appDelegate. See also https://developers.facebook.com/docs/app-events/ios#appActivation

Unable to connect XMPPFramework to Openfire server in iOS

I am working on an iOS chat app where user login to app. I've downloaded XMPPFramework from GitHub XMPPFramework. I am trying to connect XMPP framework with Openfire server by following this tutorial. Here is my code to connect XMPP to openfire.
- (BOOL)connect {
[self setupStream];
[xmppStream setHostName:#"192.168.1.5"];
[xmppStream setHostPort:5222];
NSString *jabberID = [[NSUserDefaults standardUserDefaults] stringForKey:#"userID"];
NSString *myPassword = [[NSUserDefaults standardUserDefaults] stringForKey:#"userPassword"];
if (![xmppStream isDisconnected])
return YES;
if (jabberID == nil || myPassword == nil)
return NO;
[xmppStream setMyJID:[XMPPJID jidWithString:jabberID]];
password = myPassword;
NSError *error = nil;
if (![xmppStream isConnected])
{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"Error"
message:[NSString stringWithFormat:#"Can't connect to server %#", [error localizedDescription]]
delegate:nil
cancelButtonTitle:#"Ok"
otherButtonTitles:nil];
[alertView show];
return NO;
}
return YES;
}
The problem is when I run the app, it shows the alert can't connect to server. I have checked many questions on StackOverflow and tried googling but couldn't find any relevant solution. How to connect it to the Openfire serve? If I am doing anything wrong in my code please suggest me with a snippet of code or a tutorial to make this happen.
A host of possibilities.
Try adding break points at xmppStreamDidConnect and xmppStreamDidAuthenticate.
If xmppStreamDidConnect isn't reached, the connection is not established; you've to rectify your hostName.
If xmppStreamDidAuthenticate isn't reached, the user is not authenticated; you've to rectify your credentials i.e. username and/or password.
One common mistake is omitting of #domainname at the back of username i.e. username#domainname e.g. keithoys#openfireserver where domain name is openfireserver.
Hope this still relevant, if not, hopefully it will help others.
There are some issues with your code:
I don't see the call to connect, you should add something like this:
NSError *error = nil;
if (![_xmppStream connectWithTimeout:XMPPStreamTimeoutNone error:&error]) {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"Error connecting"
message:#"Msg"
delegate:nil
cancelButtonTitle:#"Ok"
otherButtonTitles:nil];
[alertView show];
}
Most of the XMPP API is asynchronous.
You have to set the stream delegate in order to receive events.
Check out XMPPStreamDelegate and XMPPStream#addDelegate
If you don't want to go through the code yourself XMPPStream.h
, you can implement all methods of XMPPStreamDelegate and log the events. This will help you understand how the framework works.
Hope this helps, Yaron

Quicklox token required

I am using quickblox in my app. I did my user signup, user login and chat. Everything works fine when i log in for the first time. if I press home and enter the app again, I come to my viewController page. The user is logged out automatically. And when I try to log in it says, token is required.
I have put the session authentication in appdelegate
[QBAuth createSessionWithDelegate:self]
-(void)viewDidAppear:(BOOL)animated
{
if([LocalStorageService shared].currentUser == nil)// check if user is logged in
{
NSCharacterSet *nonalphanumericSet = [[ NSCharacterSet alphanumericCharacterSet] invertedSet];
[QBUsers logInWithUserLogin:[[[PFUser currentUser].username componentsSeparatedByCharactersInSet:nonalphanumericSet ] componentsJoinedByString:#"1"] password:#"password" delegate:self];
}
}
- (void)completedWithResult:(Result *)result
{
if(result.success && [result isKindOfClass:QBUUserLogInResult.class])
{
// Success, do something
QBUUserLogInResult *userResult = (QBUUserLogInResult *)result;
NSLog(#"Logged In user=%#", userResult.user);
userResult.user.password =#"password";
// Save current user
//
[[LocalStorageService shared] setCurrentUser: userResult.user];
// Login to QuickBlox Chat
//
[[ChatService instance] loginWithUser:[LocalStorageService shared].currentUser completionBlock:^{
NSLog(#"chat logged successfully");
}];
// Errors
}
else
{
NSString *errorMessage = [[result.errors description] stringByReplacingOccurrencesOfString:#"(" withString:#""];
errorMessage = [errorMessage stringByReplacingOccurrencesOfString:#")" withString:#""];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Errors"
message:errorMessage
delegate:nil
cancelButtonTitle:#"Ok"
otherButtonTitles: nil];
[alert show];
}
}
token is required means that you are trying to perform request, but you didn't create a session still
You can reproduce this issue just perform 2 requests one by one:
[QBAuth createSessionWithDelegate:self];
[QBUsers logInWithUserLogin:... delegate:self];
After this sequence you will got 'token is required'
To get rid of this you should wait when create session requests will be finished and perform next request:
[QBAuth createSessionWithDelegate:self];
...
- (void)completedWithResult:(Result *)result{
if(result.success && [result isKindOfClass:QBAAuthSessionCreationResult.class]){
// you got token here - perform any other requests after this
[QBUsers logInWithUserLogin:... delegate:self];
}
}
It's not a solution for your issue, but it's an explanation hy it happenes and how to resolve it
It seems socket get closed. Try to log out from QBChat instance when app goes to background, and log in to QBChat when app will enter foreground. And if you don't send presence messages to QBChat, socket will be closed in 90 seconds

When should I renew an ACAccount? Or, how to check if the credential is expired. (Facebook)

Recently I was assigned to survey how to use iOS framework ACAccount and Social to implement facebook post function. It is quite simple to gain access of the account configured in setting.
if(!_accountStore)
_accountStore = [[ACAccountStore alloc] init];
ACAccountType *facebookTypeAccount = [_accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
// Check if there is any faceboook account
NSArray *accounts = [_accountStore accountsWithAccountType:facebookTypeAccount];
if (![accounts count]) {
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:#"alert" message:#"No facebook account configured in setting." delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
return;
}
[_accountStore requestAccessToAccountsWithType:facebookTypeAccount
options:#{ACFacebookAppIdKey: #"FACEBOOK-APP-ID", ACFacebookPermissionsKey: #[#"email"]}
completion:^(BOOL granted, NSError *error) {
if(granted){
NSArray *accounts = [_accountStore accountsWithAccountType:facebookTypeAccount];
_facebookAccount = [accounts lastObject];
NSLog(#"Success");
}else{
// ouch
NSLog(#"Failed, Error: %#", error);
dispatch_async(dispatch_get_main_queue(), ^{
NSString *message = [NSString stringWithFormat:#"App access denied, please grant access in Setting->Facebook. Error message::%#", error];
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:#"Alert" message:message delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
});
}
}];
Once the app gain access to facebook, it can post message by using SLComposeViewController:
- (IBAction)postButtonPressed:(id)sender {
if (!_facebookAccount) {
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:#"alert" message:#"login first" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
return;
}
SLComposeViewController *fbController = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
SLComposeViewControllerCompletionHandler __block completionHandler=^(SLComposeViewControllerResult result){
[fbController dismissViewControllerAnimated:YES completion:nil];
switch(result){
case SLComposeViewControllerResultCancelled:
default:
{
NSLog(#"Cancelled.....");
}
break;
case SLComposeViewControllerResultDone:
{
NSLog(#"Posted....");
}
break;
}};
[fbController setInitialText:#"Test message"];
[fbController setCompletionHandler:completionHandler];
[self presentViewController:fbController animated:YES completion:nil];
} else {
NSLog(#"no facebook setup");
}
Here comes my question. I found that there is a method in ACAccountStore which is used to renew expired credential of an ACAccount:
- (void)renewCredentialsForAccount:(ACAccount *)account completion:(ACAccountStoreCredentialRenewalHandler)completionHandler;
But I don't even know how to check whether the credential is expired so that I can renew it. Anyone got an idea about this?
Oh, by the way, we just want to use the native Social framework to do simple work such as post some message or picture. So, if not needed, we are not going to use the facebook SDK.
If you know anything about how to check the credential is valid or not, please leave a comment or submit an answer, thank you:)
Updates 2013.11.20 11:10 AM
I learn something from my experiments to this issue..
One is not able to get certain type of accounts from account store before he gains access to them, so I should not check account count before request for access.
Renew notification called when the app using ACAccount is in background after facebook account changed. Currently, I only saw changes of access right triggers the notification.
If the user changes password, the system will pop out an alert when the user attempt to post something, which ask the user to change password.
I think monitor notifications of account change is enough to handle the changes. I'll accept the first answer.
You should renew the user acc everytime it is out of sync. This may happen if the user has changed his password or when the acc session has expired.
Yo can know you are in that scenario using the following notification:
ACAccountStoreDidChangeNotification
I don't think there is active way , best is to write renew function and call
renewCredentialsForAccount of the framework

Using the Google APIs with OAuth 2.0 for gmail login in iPhone

I have found a services from Google which provides to access to Google APIs for various Google Services. I could set up a project in iPhone and create API access for iOS applications (via OAuth2.0) and native applications. I wanted to use the native API for my iPhone app. It API gives me email,fullname,firstname,lastname,google_id,gender,dob,profile_image. How do I use these in my iPhone Application, Any sample apps, snippets available?
Please help me.
Here is my code :
-(void) loadGmail_Login
{
NSString *keychainItemName = nil;
if ([self shouldSaveInKeychain]) {
keychainItemName = kKeychainItemName;
}
// For GTM applications, the scope is available as
NSString *scope = #"http://www.google.com/m8/feeds/";
// ### Important ###
// GTMOAuthViewControllerTouch is not designed to be reused. Make a new
// one each time you are going to show it.
// Display the autentication view.
GTMOAuthAuthentication *auth;
auth = [GTMOAuthViewControllerTouch authForGoogleFromKeychainForName:kKeychainItemName];
GTMOAuthViewControllerTouch *viewController = [[[GTMOAuthViewControllerTouch alloc]
initWithScope:scope
language:nil
appServiceName:keychainItemName
delegate:self
finishedSelector:#selector(viewController:finishedWithAuth:error:)] autorelease];
// You can set the title of the navigationItem of the controller here, if you want.
// Optional: display some html briefly before the sign-in page loads
NSString *html = #"<html><body bgcolor=silver><div align=center>Loading sign-in page...</div></body></html>";
[viewController setInitialHTMLString:html];
[[self navigationController] pushViewController:viewController animated:YES];
}
- (void)viewController:(GTMOAuthViewControllerTouch *)viewController
finishedWithAuth:(GTMOAuthAuthentication *)auth
error:(NSError *)error
{
if (error != nil)
{
// Authentication failed (perhaps the user denied access, or closed the
// window before granting access)
NSLog(#"Authentication error: %#", error);
NSData *responseData = [[error userInfo] objectForKey:#"data"]; // kGTMHTTPFetcherStatusDataKey
if ([responseData length] > 0) {
// show the body of the server's authentication failure response
NSString *str = [[[NSString alloc] initWithData:responseData
encoding:NSUTF8StringEncoding] autorelease];
NSLog(#"%#", str);
}
[self setAuthentication:nil];
}
else
{
// save the authentication object
[self setAuthentication:auth];
// Just to prove we're signed in, we'll attempt an authenticated fetch for the
// signed-in user
[self doAnAuthenticatedAPIFetch];
}
}
- (void)doAnAuthenticatedAPIFetch
{
NSString *urlStr;
// Google Contacts feed
//
// https://www.googleapis.com/oauth2/v2/userinfo
urlStr = #"http://www.google.com/m8/feeds/contacts/default/thin";
NSURL *url = [NSURL URLWithString:urlStr];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[mAuth authorizeRequest:request];
NSError *error = nil;
NSURLResponse *response = nil;
NSData *data = [NSURLConnection sendSynchronousRequest:request
returningResponse:&response
error:&error];
if (data) {
// API fetch succeeded
NSString *str = [[[NSString alloc] initWithData:data
encoding:NSUTF8StringEncoding] autorelease];
NSLog(#"API response: %#", str);
GGCXml_Adaptor *localAlphabetXMLParser = [[GGCXml_Adaptor alloc] init];
[localAlphabetXMLParser processBooksXML:data];
[localAlphabetXMLParser release];
// [self updateUI];
} else {
// fetch failed
NSLog(#"API fetch error: %#", error);
}
}
- (void)setAuthentication:(GTMOAuthAuthentication *)auth {
[mAuth autorelease];
mAuth = [auth retain];
}
First you will need to get token from Google API, For this 1st step you will have to follow this tutorial and in the end of this link there is whole source code for iOS for getting token from google API
http://technogerms.com/login-with-google-using-oauth-2-0-for-ios-xcode-objective-c/
Then in the next step you have to send that token to Google API to request user Data, I just needed the first step So I am sharing my searchings
Try this Tutorial and Source code Link.. It's works fine for me.
1. Tutorial Reference: http://technogerms.com/login-with-google-using-oauth-2-0-for-ios-xcode-objective-c/
2. Api Reference : https://code.google.com/apis/console/
3. Source code: https://github.com/emysa341/Login-with-gmail-google-g--using-oath-2.0-protocol/archive/master.zip
i think this will help anybody else
Follow the below steps to integrate gmail with your application .
1.Add following classes to you project .
GTMHTTPFetcher.h , GTMHTTPFetcher.m ,GTMOAuth2Authentication.h, GTMOAuth2Authentication.m,GTMOAuth2SignIn.h,GTMOAuth2SignIn.m,GTMOAuth2ViewControllerTouch.h,GTMOAuth2ViewControllerTouch.m,GTMOAuth2ViewTouch.xib,SBJSON.h , SBJSON.m
you will get these classes here : https://github.com/jonmountjoy/Force.com-iOS-oAuth-2.0-Example
Note : if you are working under ARC Environment then you have to disable the ARC for following files :
GTMHTTPFetcher.m , GTMOAuth2Authentication.m , GTMOAuth2SignIn.m, GTMOAuth2ViewControllerTouch.m
To disable ARC for source files in Xcode 4, select the project and the target in Xcode. Under the target "Build Phases" tab, expand the Compile Sources build phase, select the library source files, then press Enter to open an edit field, and type -fno-objc-arc as the compiler flag for those files.
2. add the following frameworks
security.framework , systemConfiguration.framework
3. Register your app to google api console …. here : https://code.google.com/apis/console
Then go to ApiAccess section , create client id for iOS app .
then you will get clientID, ClientSecret and RedirectUrl
**4. Now it's time for coding . . . .**
create a signIn button in your controller and set the action for that . Here when the user click the button SignInGoogleButtonClicked method gets called .
//import GTMOAuth2Authentication , GTMOAuth2ViewControllerTouch
#define GoogleClientID #"paster your client id"
#define GoogleClientSecret #"paste your client secret"
#define GoogleAuthURL #"https://accounts.google.com/o/oauth2/auth"
#define GoogleTokenURL #"https://accounts.google.com/o/oauth2/token"
-(void) SignInGoogleButtonClicked
{
NSURL * tokenURL = [NSURL URLWithString:GoogleTokenURL];
NSString * redirectURI = #"urn:ietf:wg:oauth:2.0:oob";
GTMOAuth2Authentication * auth;
auth = [GTMOAuth2Authentication authenticationWithServiceProvider:#"google"
tokenURL:tokenURL
redirectURI:redirectURI
clientID:GoogleClientID
clientSecret:GoogleClientSecret];
auth.scope = #"https://www.googleapis.com/auth/plus.me";
GTMOAuth2ViewControllerTouch * viewcontroller = [[GTMOAuth2ViewControllerTouch alloc] initWithAuthentication:auth
authorizationURL:[NSURL URLWithString:GoogleAuthURL]
keychainItemName:#"GoogleKeychainName" delegate:self
finishedSelector:#selector(viewController:finishedWithAuth:error:)];
[self.navigationController pushViewController:viewcontroller animated:YES];
}
//this method is called when authentication finished
- (void)viewController:(GTMOAuth2ViewControllerTouch * )viewController finishedWithAuth:(GTMOAuth2Authentication * )auth error:(NSError * )error
{
if (error != nil) {
UIAlertView * alert = [[UIAlertView alloc] initWithTitle:#"Error Authorizing with Google"
message:[error localizedDescription]
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alert show];
}
else
{
UIAlertView * alert = [[UIAlertView alloc] initWithTitle:#"Alert !"
message:#"success"
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alert show];
}
}

Resources