Skip to content

Commit 588fc9f

Browse files
committed
No cancel after success
1 parent c60ff58 commit 588fc9f

File tree

7 files changed

+87
-66
lines changed

7 files changed

+87
-66
lines changed

BenefitPay-iOS.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = 'BenefitPay-iOS'
3-
s.version = '0.0.2'
3+
s.version = '0.0.3'
44
s.summary = 'From the shelf pay with benefit pay button by Tap Payments'
55
s.homepage = 'https://github.com/Tap-Payments/BenefitPay-iOS'
66
s.license = { :type => 'MIT', :file => 'LICENSE' }

BenefitPayExampleApp/BenefitPayExampleApp.xcodeproj/xcuserdata/osamarabie.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,4 @@
33
uuid = "2B99122E-2F1D-4D14-938C-E8DB4CC2F500"
44
type = "1"
55
version = "2.0">
6-
<Breakpoints>
7-
<BreakpointProxy
8-
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
9-
<BreakpointContent
10-
uuid = "F0CFC2C5-30F8-45D1-AD73-6ACAD81611A5"
11-
shouldBeEnabled = "Yes"
12-
ignoreCount = "0"
13-
continueAfterRunningActions = "No"
14-
filePath = "BenefitPayExampleApp/BenefitPayButtonExample.swift"
15-
startingColumnNumber = "9223372036854775807"
16-
endingColumnNumber = "9223372036854775807"
17-
startingLineNumber = "101"
18-
endingLineNumber = "101"
19-
landmarkName = "generateTapHashString(publicKey:secretKey:amount:currency:postUrl:transactionReference:)"
20-
landmarkType = "7">
21-
</BreakpointContent>
22-
</BreakpointProxy>
23-
</Breakpoints>
246
</Bucket>

BenefitPayExampleApp/BenefitPayExampleApp/Info.plist

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,9 @@
2828
<string>fetch</string>
2929
<string>processing</string>
3030
</array>
31+
<key>BGTaskSchedulerPermittedIdentifiers</key>
32+
<array>
33+
<string>tap.BenefitPayExampleApp</string>
34+
</array>
3135
</dict>
3236
</plist>

Sources/BenefitPay-iOS/Logic/SdkBasedButtons/BenefitPay/private/extensions/TapBenefitPay + SwiftEntry.swift

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,7 @@ internal extension BenefitPayButton {
6868
func createBenefitPayPopUpView() -> UIViewController {
6969
// The container iew
7070
let view:UIView = .init()
71-
view.backgroundColor = .clear
72-
71+
view.backgroundColor = .black
7372
//webView.isHidden = true
7473
webView.removeFromSuperview()
7574
view.addSubview(webView)
@@ -86,7 +85,7 @@ internal extension BenefitPayButton {
8685
let left = webView.leftAnchor.constraint(equalTo: view.leftAnchor)
8786
let right = webView.rightAnchor.constraint(equalTo: view.rightAnchor)
8887
let bottom = webView.bottomAnchor.constraint(equalTo: view.bottomAnchor)
89-
88+
9089
// Define the constraints of the loader to be centered
9190
let loaderCenterY = benefitGifLoader!.centerYAnchor.constraint(equalTo: view.centerYAnchor)
9291
let loaderCenterX = benefitGifLoader!.centerXAnchor.constraint(equalTo: view.centerXAnchor)
@@ -101,8 +100,8 @@ internal extension BenefitPayButton {
101100

102101

103102
let ctr:UIViewController = .init()
104-
ctr.view.backgroundColor = .clear
105-
ctr.modalPresentationStyle = .overCurrentContext
103+
ctr.view.backgroundColor = .red
104+
ctr.modalPresentationStyle = .fullScreen
106105
ctr.view.addSubview(view)
107106
ctr.restorationIdentifier = "BenefitQRVC"
108107
view.translatesAutoresizingMaskIntoConstraints = false
@@ -201,7 +200,7 @@ internal extension BenefitPayButton {
201200
return nil
202201
}
203202

204-
func showGifLoader(show:Bool) {
203+
/*func showGifLoader(show:Bool) {
205204
if(show) {
206205
self.webView.isUserInteractionEnabled = false
207206
self.benefitGifLoader?.isHidden = false
@@ -217,5 +216,5 @@ internal extension BenefitPayButton {
217216
self.benefitGifLoader?.isHidden = true
218217
self.webView.isUserInteractionEnabled = true
219218
}
220-
}
219+
}*/
221220
}

Sources/BenefitPay-iOS/Logic/SdkBasedButtons/BenefitPay/private/extensions/TapBenefitPay+WebDelegate.swift

Lines changed: 45 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,19 @@ extension BenefitPayButton:WKNavigationDelegate {
2525

2626
guard let url = navigationAction.request.url else { return }
2727

28-
if url.absoluteString.hasPrefix(payButtonType.webSdkScheme()) {
29-
print("navigationAction", url.absoluteString)
28+
if url.absoluteString.lowercased().hasPrefix(payButtonType.webSdkScheme()) {
29+
print("navigationAction1", url.absoluteString)
3030
action = .cancel
3131
}else{
32-
print("navigationAction", url.absoluteString)
32+
print("navigationAction2", url.absoluteString)
3333
}
3434
// In all cases when we get a feedback from the web view we will need to hide the loader if it is being displayed
35-
self.loadingView.isHidden = true
3635
// Let us see if the web sdk is telling us something
37-
if( url.absoluteString.contains(payButtonType.webSdkScheme())) {
36+
if( url.absoluteString.lowercased().contains(payButtonType.webSdkScheme())) {
3837
switch url.absoluteString {
3938
case _ where url.absoluteString.contains(CallBackSchemeEnum.onError.rawValue):
4039
self.handleOnError(data: tap_extractDataFromUrl(url, for: "data", shouldBase64Decode: true))
40+
self.loadingView.isHidden = true
4141
break
4242
case _ where url.absoluteString.contains(CallBackSchemeEnum.onOrderCreated.rawValue):
4343
delegate?.onOrderCreated?(data: tap_extractDataFromUrl(url, for: "data", shouldBase64Decode: false))
@@ -46,38 +46,23 @@ extension BenefitPayButton:WKNavigationDelegate {
4646
delegate?.onChargeCreated?(data: tap_extractDataFromUrl(url, for: "data", shouldBase64Decode: true))
4747
break
4848
case _ where url.absoluteString.contains(CallBackSchemeEnum.onSuccess.rawValue):
49-
50-
let notificationContent = UNMutableNotificationContent()
51-
notificationContent.title = "Payment updated"
52-
notificationContent.body = "Return to \(Bundle.main.infoDictionary?[kCFBundleNameKey as String] as? String ?? "the app") to complete your transaction."
53-
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 0.5,
54-
repeats: false)
55-
let request = UNNotificationRequest(identifier: "testNotification",
56-
content: notificationContent,
57-
trigger: trigger)
58-
59-
UNUserNotificationCenter.current().add(request) { (error) in
60-
if let error = error {
61-
print("Notification Error: ", error)
62-
}
63-
}
64-
// If app is in background we will not do anything and will save the data onSuccess so when he focuses again, we dispatch the event
65-
if UIApplication.shared.applicationState == .active {
66-
self.handleOnSuccess(url:url)
67-
}else{
68-
self.webView.isHidden = true
69-
self.onSuccessURL = url
70-
}
49+
self.handleOnSuccess(url:url)
7150
break
7251
case _ where url.absoluteString.contains(CallBackSchemeEnum.onReady.rawValue):
52+
self.loadingView.isHidden = true
7353
delegate?.onReady?()
7454
break
7555
case _ where url.absoluteString.contains(CallBackSchemeEnum.onClick.rawValue):
7656
self.handleOnClick()
7757
break
7858
case _ where url.absoluteString.contains(CallBackSchemeEnum.onCancel.rawValue):
79-
if self.onSuccessURL == nil {
80-
self.removeBenefitPayPopupEntry(handleOnCancel: true) {
59+
self.loadingView.isHidden = true
60+
self.removeBenefitPayPopupEntry(handleOnCancel: true) {
61+
DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(3)) {
62+
guard !BenefitPayButton.onSuccessCalled else {
63+
BenefitPayButton.onSuccessCalled = false
64+
return
65+
}
8166
self.delegate?.onCanceled?()
8267
}
8368
}
@@ -105,19 +90,21 @@ extension BenefitPayButton:WKNavigationDelegate {
10590
self.loadingView.isHidden = false
10691
// Handle the on cancel and inform the consumer app that on click is triggered
10792
self.handleOnCancel = true
93+
BenefitPayButton.onSuccessCalled = false
10894
delegate?.onClick?()
10995
}
11096

11197
func handleOnSuccess(url:URL) {
98+
BenefitPayButton.onSuccessCalled = true
11299
self.webView.isHidden = false
113100
if !self.removeBenefitPayAppEntry(onDismiss: {
114101
self.removeBenefitPayPopupEntry(handleOnCancel: false) {
115102
self.delegate?.onSuccess?(data: tap_extractDataFromUrl(url, for: "data", shouldBase64Decode: true))
116103
//self.openUrl(url: self.currentlyLoadedConfigurations)
117104
}
118105
}) {
106+
self.delegate?.onSuccess?(data: tap_extractDataFromUrl(url, for: "data", shouldBase64Decode: true))
119107
self.removeBenefitPayPopupEntry(handleOnCancel: false) {
120-
self.delegate?.onSuccess?(data: tap_extractDataFromUrl(url, for: "data", shouldBase64Decode: true))
121108
//self.openUrl(url: self.currentlyLoadedConfigurations)
122109
}
123110
}
@@ -130,19 +117,43 @@ extension BenefitPayButton:WKNavigationDelegate {
130117

131118
if !self.removeBenefitPayAppEntry(onDismiss: {
132119
if (self.removeBenefitPayPopupEntry(handleOnCancel: false, onDismiss: {
133-
self.delegate?.onError?(data:data)
120+
DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(3)) {
121+
guard !BenefitPayButton.onSuccessCalled else {
122+
BenefitPayButton.onSuccessCalled = false
123+
return
124+
}
125+
self.delegate?.onError?(data:data)
126+
}
134127
self.webView.isUserInteractionEnabled = true
135128
})){} else{
136-
self.delegate?.onError?(data:data)
129+
DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(3)) {
130+
guard !BenefitPayButton.onSuccessCalled else {
131+
BenefitPayButton.onSuccessCalled = false
132+
return
133+
}
134+
self.delegate?.onError?(data:data)
135+
}
137136
self.webView.isUserInteractionEnabled = true
138137
}
139138
}) {
140139
if (self.removeBenefitPayPopupEntry(handleOnCancel: false) {
141-
self.delegate?.onError?(data: data)
140+
DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(3)) {
141+
guard !BenefitPayButton.onSuccessCalled else {
142+
BenefitPayButton.onSuccessCalled = false
143+
return
144+
}
145+
self.delegate?.onError?(data:data)
146+
}
142147
self.webView.isUserInteractionEnabled = true
143148
//self.openUrl(url: self.currentlyLoadedConfigurations)
144149
}){}else{
145-
self.delegate?.onError?(data: data)
150+
DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(3)) {
151+
guard !BenefitPayButton.onSuccessCalled else {
152+
BenefitPayButton.onSuccessCalled = false
153+
return
154+
}
155+
self.delegate?.onError?(data:data)
156+
}
146157
self.webView.isUserInteractionEnabled = true
147158
}
148159
}

Sources/BenefitPay-iOS/Logic/SdkBasedButtons/BenefitPay/views/private/TapBenefitPayView.swift

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ internal class BenefitPayButton: PayButtonBaseView {
2323
internal var handleOnCancel:Bool = true
2424
/// Keeps a reference to the gif loader we will display when coming back from pay with benefit pay app
2525
internal var benefitGifLoader:UIImageView?
26-
/// Holds the latest onSuccess url called when the app is in background. Will be used to call when the user focuses the app agian
27-
internal var onSuccessURL:URL? = nil
2826
/// Holds a reference to a loader to display on top of the button when clicked until charge api responds
2927
internal var loadingView:UIActivityIndicatorView = .init(style: .large)
28+
/// Declares if we recieved an onSuccess
29+
internal static var onSuccessCalled:Bool = false
3030

3131
//MARK: - Init methods
3232
override public init(frame: CGRect) {
@@ -45,7 +45,7 @@ internal class BenefitPayButton: PayButtonBaseView {
4545
// Set the button type
4646
payButtonType = .BenefitPay
4747
// Set the loader color
48-
loadingView.color = .white
48+
loadingView.color = .gray
4949
loadingView.startAnimating()
5050
// Setuo the web view contais the web sdk
5151
setupWebView()
@@ -62,7 +62,7 @@ internal class BenefitPayButton: PayButtonBaseView {
6262
// First, check if the current screen is the paywithebenefitpayapp popup, then we remove it and show the loader on the pay qith benefit qr popup
6363
if !removeBenefitPayAppEntry() {
6464
// This means, we are already in the pay with benefit qr ode and we only need to how the loader maybe the chrge will be updated
65-
showGifLoader(show: true)
65+
//showGifLoader(show: true)
6666
}
6767
/*
6868
// SWIPE Now let us check if the benefitpay app popup is displayed
@@ -95,7 +95,8 @@ internal class BenefitPayButton: PayButtonBaseView {
9595
preferences.javaScriptCanOpenWindowsAutomatically = true
9696
let configuration = WKWebViewConfiguration()
9797
configuration.defaultWebpagePreferences.preferredContentMode = .desktop
98-
98+
configuration.setURLSchemeHandler(self, forURLScheme: "tapBenefitPayWebSDK");
99+
99100
webView = WKWebView(frame: .zero, configuration: configuration)
100101
// Let us make sure it is of a clear background and opaque, not to interfer with the merchant's app background
101102
webView.isOpaque = false
@@ -160,7 +161,7 @@ internal class BenefitPayButton: PayButtonBaseView {
160161

161162
// If this is the pay with benefitpayapp popup page, we need to go back to the benefitPay page and show the loader
162163
topMostVC.dismiss(animated: true) {
163-
self.showGifLoader(show: true)
164+
//self.showGifLoader(show: true)
164165
onDismiss()
165166
}
166167
return true
@@ -236,3 +237,27 @@ internal class BenefitPayButton: PayButtonBaseView {
236237
}
237238
}
238239
}
240+
241+
242+
extension BenefitPayButton:WKURLSchemeHandler {
243+
func webView(_ webView: WKWebView, start urlSchemeTask: WKURLSchemeTask) {
244+
print("Function: \(#function), line: \(#line)")
245+
print("==> \(urlSchemeTask.request.url?.absoluteString ?? "")\n")
246+
247+
// You can find the url pattern by using urlSchemeTask.request.url. and create NSData from your local resource and send the data using 3 delegate method like done below.
248+
// You can also call server api from this native code and return the data to the task.
249+
// You can also cache the data coming from server and use it during offline access of this html.
250+
// When you are returning html the the mime type should be 'text/html'. When you are trying to return Json data then we should change the mime type to 'application/json'.
251+
// For returning json data you need to return NSHTTPURLResponse which has base classs of NSURLResponse with status code 200.
252+
253+
// Handle WKURLSchemeTask delegate methods
254+
255+
}
256+
257+
func webView(_ webView: WKWebView, stop urlSchemeTask: WKURLSchemeTask) {
258+
print("Function: \(#function), line: \(#line)")
259+
print("==> \(urlSchemeTask.request.url?.absoluteString ?? "")\n")
260+
}
261+
262+
263+
}

0 commit comments

Comments
 (0)