Skip to content

Commit

Permalink
Fix issues related to Frimi Payments and code cleanup (#17)
Browse files Browse the repository at this point in the history
Co-authored-by: Thisura98 <[email protected]>
  • Loading branch information
PayHereDevs and Thisura98 authored Aug 4, 2022
1 parent 7e3b0e0 commit 7ff6fd8
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 11 deletions.
2 changes: 1 addition & 1 deletion payHereSDK.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
42 changes: 32 additions & 10 deletions payHereSDK/Sources/PHBottomViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down Expand Up @@ -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;
}
}
}
Expand Down
8 changes: 8 additions & 0 deletions payHereSDK/Sources/PHConstants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"

}

0 comments on commit 7ff6fd8

Please sign in to comment.