Reputation: 1566
I am integrating stripe in my app. The code works but I would like to get the description error and show it to user with a Alert in case something goes wrong (Mobile number, postal code not correct etc) stripe return html format below:
Html Format
<h4>An uncaught Exception was encountered</h4>
<p>Type: Stripe\Exception\InvalidRequestException</p>
<p>Message: You cannot use a live bank account number when making transfers or debits in test mode</p>
Question: How to show the stripe error in app?
Can someone please explain to me how to show error.
Any help would be greatly appreciated.
Thanks in advance.
Upvotes: 0
Views: 199
Reputation: 5052
An easy solution is to create a custom alert view with UIwebview/wkwebview and load the Html string. In case, if you don't like to show the desired message from the Html, you need to parse the Html string and show in AlertViewController.
Also, you can use AlerViewController with webview. Here is a code sample, call this method when you get the error:
func showError(with html: String) {
let alertController = UIAlertController(title: "", message: nil, preferredStyle: .alert)
let webView = UIWebView()
webView.loadHTMLString(html, baseURL: nil)
alertController.view.addSubview(webView)
webView.translatesAutoresizingMaskIntoConstraints = false
webView.topAnchor.constraint(equalTo: alertController.view.topAnchor, constant: 45).isActive = true
webView.rightAnchor.constraint(equalTo: alertController.view.rightAnchor, constant: -10).isActive = true
webView.leftAnchor.constraint(equalTo: alertController.view.leftAnchor, constant: 10).isActive = true
webView.heightAnchor.constraint(equalToConstant: 250).isActive = true
alertController.view.translatesAutoresizingMaskIntoConstraints = false
alertController.view.heightAnchor.constraint(equalToConstant: 330).isActive = true
let cancelAction = UIAlertAction(title: "Cancel", style: .cancel, handler: nil)
alertController.addAction(cancelAction)
self.present(alertController, animated: true, completion: nil)
}
Upvotes: 1