Pods integration:
Add the next source(s) in the top of the Podfile:
source 'https://github.com/CocoaPods/Specs.git'
source 'https://github.com/SafeChargeInternational/Pods.git'
Add the next pods in under the relevant target(s) in the Podfile:
pod 'NuveiCashierHelper', '~> 3.0.1'
Carthage integration:
Add the next pods in under the relevant target(s) in the Cartfile:
github "SafeChargeInternational/NuveiCashierHelper-iOS" ~> 3.0.1
github "SafeChargeInternational/CodeScanner" ~> 1.8.2
The SDK works with WKWebView, so add the next line before you load Nuvei cashier page in the web view (e.g. in viewDidLoad of the view controller that displays the web view):
override func viewDidLoad() {
super.viewDidLoad()
webView.navigationDelegate = self
// Prepare the cashier URL
let rawUrl = "<YOUR CASHIER URL WITHOUT '#' TAG IN THE END>"
// CashierHelper.update will throw an exception if rawUrl already contains '#'
let finalUrl = try? CashierHelper.update(url: rawUrl, with: [.qr, .card]) ?? cashierUrl
// Setup web view and the rest of the view controller...
webView.load(URLRequest(url: finalUrl))
// Call this line after the webView is part of the view hierarchy
CashierHelper.connect(to: webView, viewController: self)
}
Implement the WKNavigationDelegate
in your view controller:
extension WebViewController: WKNavigationDelegate {
func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) {
do {
if let url = navigationAction.request.url?.absoluteString, try NuveiCashierHelper.handleURL(url) {
// Handled by NuveiCashierHelper, no need to do anything else, cancel the URL loading
decisionHandler(.cancel)
} else {
// Not handled by NuveiCashierHelper, add your logic and/or complete the loading of the URL
decisionHandler(.allow)
}
} catch {
debugPrint(#function, "error = \(error)")
decisionHandler(.allow)
}
}
}
See: LICENSE