Pago payment gateway Integration [duplicate] - iphone

This question already has answers here:
Accept payment on ios apps?
(4 answers)
Closed 9 years ago.
I would like to add a payment module on my Iphone Application that I am going to build,
I want the users to pay using Pago. When webpage loads a button is displayed, on clicking the button a new page opens in a new window.
On that page user enters the payment details and payment is processed. As we have no control over this window, So we are not able to call our custom url to return to our app on payment success.
So how can I return to App on payment success?

There is no easy way to do it.
Try opening the page in web view and add when the url of the success page match to the url in web view display the success message.

I want the users to pay using Pago. When webpage loads a button is displayed, on clicking ? the button a new page opens in a new window.
Does the new page opens inside a webview in your app?
If so, you just have to get the URL you get on payment success (if you can) and use the following web view delegate method to catch the URL:
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
NSString *urlString = [NSString stringWithFormat:#"%#", request.URL];
// If not found, load url
if ([urlString rangeOfString:#"http://you-url"].location == NSNotFound)
{
return YES;
}
// If found, intercept
else
{
// Do what you want here
return NO;
}
}

Related

facebook login on iphone leaves blank page

I created a simple test html page that contains a facebook like box. For testing purpose I uploaed the test page to my server.
On the desktop (being log out of facebook) there is the following situation:
Click on like
A popup appears with a form for login
After login the popup is closed and the like count is raised
However, using it on my iphone in chrome browser and being logged out of facebook the following happens:
Click on the like button
Redirect to the facebook login page
After login I'm redirected to a blank page.
The screenshot below shows the problem:
Is there a possibility to avoid this?
EDIT: The same happens when I try this in an iOS app using a UIWebView.
Okay, I found a solution for doing this in my iOS app for an integrated UIWebView.
When someone is not logged in to facebook a popup opens and requests a login. After logging in the user is redirected back to the page from where he hit the like button. However in the UIWebView this redirect URL leaves the user with a blank page. The solution to the problem is to intercept the redirect URL and reload the page with the like button.
So, with UIWebView one can intercept the requests before the actual webpage is loaded and react on certain URLs. The code for this look like this:
- (void)viewDidLoad
{
[super viewDidLoad];
self.webview.delegate = self;
[self.webview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:#"http://www.example.com/facebook_like_box.html"]]];
}
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
if( [[request.URL description] rangeOfString:#"lugins/close_popup.php"].location != NSNotFound) {
// We intercepted the redirect URL of facebook after logging in. Instead of loading a blank page recall the URL of the like box
// manually on the uiwebview.
[self.webview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:#"http://www.example.com/facebook_like_box.html"]]];
//returning NO indicates the the page is not further loaded.
return NO;
}
//Any other page should be loaded
return YES;
}

Reverse back to app from safari [duplicate]

This question already has answers here:
Return to app from safari
(4 answers)
Closed 9 years ago.
In my application I am calling an url in safari on a button click,I am using the following code
In safari I am using pay pal payment.Is there any chance to reverse back to my app after donate button click.
-(BOOL) webView:(UIWebView *)inWeb shouldStartLoadWithRequest:(NSURLRequest *)inRequest navigationType:(UIWebViewNavigationType)inType {
if ( inType == UIWebViewNavigationTypeLinkClicked ) {
[[UIApplication sharedApplication] openURL:[inRequest URL]];
return NO;
}
return YES;
}
NO That is not possible in case of websites that you dont have control. Instead, you can open the link in your webview.
If you have developed website, you can redirect it to your app using custom URL. For details refer this tutorial
For your case i.e. Paypal, it is not possible
If you are trying to navigate from Safari to your app, you would need to have control of the web page that you send the user to. Create a button on the webpage that links to the custom URL scheme of your application. Then when the user clicks on the button, your app will open on the device.
Instead of using [[UIApplication sharedApplication] openURL:] method, you can open your website into website inside your viewcontroller, with back button.Thus you can go back into your app from safari..
Follow this snippet,
`NSURL *url = [NSURL URLWithString:<YOUR_URL>];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
webViewBrowser.delegate = self;
[webViewBrowser loadRequest:request];`
Enjoy Programming!!

Facebook login fails in UIWebView

In my app I have to load a web page in UIWebView where user can login with Facebook. The problem is that when user clicks login, blank page appears.
Is it possible to get back to first page and be logged in?
Web page works perfectly in Safari and opens new window and after login it closes it and gets back to where it left.
EDIT: wrong URL was provided to UIWebView
I think the sample of facebook SDK for iOS does the log in way you want.
Please refer to the link:
facebook-iOS-SDK-sample: https://github.com/facebook/facebook-ios-sdk/tree/master/sample/Hackbook
Especially this part in https://github.com/facebook/facebook-ios-sdk/blob/master/sample/Hackbook/Hackbook/RootViewController.m
/**
* Show the authorization dialog.
*/
- (void)login {
HackbookAppDelegate *delegate = (HackbookAppDelegate *)[[UIApplication sharedApplication] delegate];
if (![[delegate facebook] isSessionValid]) {
[[delegate facebook] authorize:permissions];
} else {
[self showLoggedIn];
}
}
When you click on log in button, it will open a login dialog, and ask for permission. This is what it looks like: https://developers.facebook.com/docs/mobile/screenshots/ios/#iphone-native
I think the best way to implement the "facebook-related" app is to start with the Hacbook. It is really a nice and detailed sample.
If you want to reload a specific url after the facebook login popup is closed to prevent being stuck on a blank page you can use this code.
First include the UIWebViewDelegate and set your delegate somewhere in your code.
[yourwebView setDelegate:self];
Then use the shouldStartLoadWithRequest method to check request url for close_popup.php which is used by Facebook to close their popup.
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
NSString *urlString = [NSString stringWithFormat:#"%#", request];
if ([urlString rangeOfString:#"close_popup.php"].location == NSNotFound) {
//The close_pop.php is not found. (Do nothing)
} else {
//Facebook closed the popup so we should load the page we now want the user to see.
NSURL*url=[NSURL URLWithString:#"http://www.example.ca/thepageyouwanttoreload.html"];
NSURLRequest*request=[NSURLRequest requestWithURL:url];
[webView loadRequest:request];
}
return YES;
}
SSL issue? As per Joanne use the facebook SDK and you get loads of extra functionality for free, including logging in via the facebook native app if its installed.

iPhone: After UIWebView opens external browser, then returning to app opens it a second time

I have a UIWebView which loads an HTML page which has some links to the App Store (<a herf="http://itunes/bla/bla/bla"> type of links).
Clicking a link, opens external Safari, then opens external App Store app and successfully goes to correct page.
If you then click Home button and return to springboard and click on app again, it will briefly open to the the UIWebView that was displayed and then jump to external Safari and external App Store app again.
If you go back to app one more time it stays in the app.
So what is happening is that returning to app after opening external browser link from UIWebView HTML page, will then jump back to the same link a second time.
Anybody have any ideas what might be causing this?
Am using Xcode 4.2.1 and it happens in simulator as well as on an actual device (iPad 1 with iOS 4.3).
EDIT - SOLUTION:
Ok, here is what I had to do to solve the problem (Thanks to Ben's response below who got me looking at the right areas):
This was my original method:
- (BOOL)webView:(UIWebView *)_webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
if (didLoad) { //Do not jump to URL when view first loads
return YES;
}
[[UIApplication sharedApplication] openURL:[request URL]];
return YES;
}
And this is my fixed method that does not keep jumping to URL:
- (BOOL)webView:(UIWebView *)_webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
if (didShowURL) { //Do not jump to URL when returning to app
didShowURL = 0;
return NO;
}
if (didLoad) { //Do not jump to URL when view first loads
return YES;
}
didShowURL = 1;
[[UIApplication sharedApplication] openURL:[request URL]];
return YES;
}
I would suggest using the itms-apps:// protocol for your link. This will send the user directly to the application in the App Store without the need for a redirect.
NSURL *appStoreLink = [NSURL URLWithString:#"itms-apps://itunes.apple.com/us/app/instagram/id389801252?mt=8"];
[[UIApplication sharedApplication] openURL:appStoreLink];
Your webview is being reloaded to its last page (the app store page) and is automatically redirecting the user away again. You just need to make sure that when the app is reloaded it is not trying to load the app store link again.
Depending on your app setup you could use
viewWillAppear
And reload the original HTML page with the links every time the view is brought to the front.

Appying our own action to Facebook Login button & closing all Facebook screens.

I am using fbconnect api in my project. When the login dialog gets opened where we entered our credentials, when we click on login button then it is redirected to the publish page how can we close the login page or post to wall page or view.
My problem is I don't want to open any page belongs to face book API, instead i want to open my own page. Any one can help or suggest.
In FBConnect there is a class FBDialog which is using UIWebView for Facebook login authentication. The FBDialog class implements the UIWebView delegate protocol. So if you want to perform your action on login button press then you can handle it in FBDialog.m in UIWebView delegate -
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request
navigationType:(UIWebViewNavigationType)navigationType
which will call when you press on login button.
You can open your own view depending upon your requirement. After successful Login following delegate method is called
- (void)session:(FBSession*)session didLogin:(FBUID)uid
{
self.usession=session;
[self postToWall];
}
Here i am calling my own custom method postToWall. Where i create publish dialog as below:
-(void)postToWall
{
FBStreamDialog *dialog=[[[FBStreamDialog alloc]init]autorelease];
dialog.userMessagePrompt=#"Enter Message to Post";
[dialog show];
}
You can create your own view in postToWall in place of FBStreamDialog OR if you want to load request of another page then load that URL in Web View of FBStreamDialog.m class.