We have an app that requires a user to make a payment. We have a third party provider that handles the payments. On our website, when the user makes a payment they get directed to the payment portal on the third party's website and after payment, they get redirected back to our website.
I have been tasked to implement the same thing in our iOS Swift 3 app. I have an idea of what I want to do but I am not quite sure how to do it. I started by thinking that I could open the user's browser with a POST request (I know now that I can't) and then using Universal Linking, grab the redirect with the app once payment is complete.
So since I cannot do POST requests on the user's browser, I thought I would implement a UIWebView in my app. Basically I have the code to do this. My question is. How do I capture the redirect from the UiWebView? As far as I can tell, upon successful payment the UIWebView will stay active and the page will redirect, showing our website inside of our app. This is not what I want.
Can anyone explain a better way of doing this? No Code required, but will be greatly appreciated.
Yes, Its possible and many apps are doing the same. There are various methods to do it but What I am doing, I can share. I am opening payment page in webview and after success on payment page. The page is redirecting to Success page with SuccessURL. When SuccessURL/FailedURL(Predefined) started loading, I take user back to native app.
func webView(webView: UIWebView, shouldStartLoadWithRequest request: NSURLRequest, navigationType: UIWebViewNavigationType) -> Bool {
if request.url == "sucessURL" {
//do whatever you want
return false
}
if request.url == "failedURL" {
////do whatever you want
return false
}
else {
return true
}
}