From 7ff6fd803c645a6713615e6211030db9cd94da7c Mon Sep 17 00:00:00 2001 From: PayHereDevs Date: Thu, 4 Aug 2022 15:52:00 +0530 Subject: [PATCH] Fix issues related to Frimi Payments and code cleanup (#17) Co-authored-by: Thisura98 --- payHereSDK.podspec | 2 +- .../Sources/PHBottomViewController.swift | 42 ++++++++++++++----- payHereSDK/Sources/PHConstants.swift | 8 ++++ 3 files changed, 41 insertions(+), 11 deletions(-) diff --git a/payHereSDK.podspec b/payHereSDK.podspec index 16c591b..c118d17 100644 --- a/payHereSDK.podspec +++ b/payHereSDK.podspec @@ -8,7 +8,7 @@ s.summary = "Mobile SDK for payHere" s.requires_arc = true # 2 -s.version = "3.0.4" +s.version = "3.0.5" # 3 s.license = { :type => "MIT", :file => "LICENSE" } diff --git a/payHereSDK/Sources/PHBottomViewController.swift b/payHereSDK/Sources/PHBottomViewController.swift index ce13875..6879ef9 100644 --- a/payHereSDK/Sources/PHBottomViewController.swift +++ b/payHereSDK/Sources/PHBottomViewController.swift @@ -50,6 +50,7 @@ internal class PHBottomViewController: UIViewController { internal var keyBoardHeightMax : CGFloat = 0 internal var shouldShowSucessView : Bool = true + private var ignoreProgressBarInNextNavigation: Bool = false private var didHandlePaymentStatus: Bool = false private var count : Int = 5 private var statusResponse : StatusResponse? @@ -1292,26 +1293,47 @@ extension PHBottomViewController : WKUIDelegate,WKNavigationDelegate{ internal func webView(_ webView: WKWebView, didStartProvisionalNavigation navigation: WKNavigation!) { + guard !ignoreProgressBarInNextNavigation else { + self.webView.isHidden = false + self.progressBar.isHidden = true + return + } + self.webView.isHidden = true self.progressBar.isHidden = false - } internal func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) { - xprint(navigationAction.request.mainDocumentURL?.absoluteString ?? "Navigating to unknown location") + let optUrl = navigationAction.request.mainDocumentURL?.absoluteString + xprint(optUrl ?? "Navigating to unknown location") + ignoreProgressBarInNextNavigation = false - if((navigationAction.request.mainDocumentURL?.absoluteString.contains("https://www.payhere.lk/pay/payment/complete"))! || (navigationAction.request.mainDocumentURL?.absoluteString.contains("https://sandbox.payhere.lk/pay/payment/complete"))!){ - if(self.initResponse?.data?.order != nil){ - if isSandBoxEnabled{ - - DispatchQueue.main.asyncAfter(deadline: .now()+1) { + if let url = optUrl{ + if((url.contains(PHConstants.kLiveCompleteURL)) || (url.contains(PHConstants.kSandboxCompleteURL))){ + if(self.initResponse?.data?.order != nil){ + if isSandBoxEnabled{ + + DispatchQueue.main.asyncAfter(deadline: .now()+1) { + self.checkStatus(orderKey: self.initResponse?.data!.order?.orderKey ?? "", showProgress: true) + } + + }else{ self.checkStatus(orderKey: self.initResponse?.data!.order?.orderKey ?? "", showProgress: true) } - - }else{ - self.checkStatus(orderKey: self.initResponse?.data!.order?.orderKey ?? "", showProgress: true) + } + } + else if url.contains(PHConstants.kProgressBarWhitelistKeywordFrimi){ + // Fix for issue Prevent progress bar hiding the Frimi steps + ignoreProgressBarInNextNavigation = true + + if url.contains(PHConstants.kProgressBarWhitelistKeywordFrimiResponse){ + // Fix for issue where Frimi steps don't load the first time + DispatchQueue.main.asyncAfter(deadline: .now() + 2.0) { + decisionHandler(.allow) + } + return; } } } diff --git a/payHereSDK/Sources/PHConstants.swift b/payHereSDK/Sources/PHConstants.swift index 682992a..d320d1b 100644 --- a/payHereSDK/Sources/PHConstants.swift +++ b/payHereSDK/Sources/PHConstants.swift @@ -16,5 +16,13 @@ public class PHConstants { internal static let dummyUrl : String = "https://www.payhere.lk/complete/ios"; internal static let UI : String = "Ui" + /// Payment Completion URL (Live) + internal static let kLiveCompleteURL = "https://www.payhere.lk/pay/payment/complete" + + /// Payment Completion URL (Sandbox) + internal static let kSandboxCompleteURL = "https://sandbox.payhere.lk/pay/payment/complete" + + internal static let kProgressBarWhitelistKeywordFrimi = "frimi" + internal static let kProgressBarWhitelistKeywordFrimiResponse = "frimi/1/response" }