Skip to content

Commit e996e07

Browse files
authored
Merge pull request #1 from Tap-Payments/FT_get_view_controller_from_data_source
Get view controller from data source
2 parents e12cebf + f90b19e commit e996e07

File tree

6 files changed

+7
-21
lines changed

6 files changed

+7
-21
lines changed

.DS_Store

0 Bytes
Binary file not shown.

TapApplePayKit-Example/ViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ class ViewController: UIViewController {
182182

183183
func authorisePayment() {
184184

185-
tapApplePay.authorizePayment(in: self, for: myTapApplePayRequest) { [weak self] (token) in
185+
tapApplePay.authorizePayment(for: myTapApplePayRequest) { [weak self] (token) in
186186
self?.showTokenizedData(with: token)
187187
} onErrorOccured: { error in
188188
let alertControl = UIAlertController(title: "Invalid data passed", message: error.TapApplePayRequestValidationErrorRawValue(), preferredStyle: .alert)

TapApplePayKit-iOS.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Pod::Spec.new do |spec|
1616
#
1717

1818
spec.name = "TapApplePayKit-iOS"
19-
spec.version = "1.0.23"
19+
spec.version = "1.0.24"
2020
spec.summary = "Provide an interface and an easy wrapper for Apple Pay functionalities."
2121

2222
# This description is used to generate tags and improve search results.
Binary file not shown.

TapApplePayKit-iOS/Core/public/Controllers/TapApplePay.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ import TapNetworkKit_iOS
7575
- Parameter tokenized: The block to be called once the user successfully authorize the payment
7676
- Parameter onErrorOccured: The block to call whenever there's an issue showing apple pay sheet
7777
*/
78-
@objc public func authorizePayment(in presenter:UIViewController, for tapApplePayRequest:TapApplePayRequest, tokenized:@escaping ((TapApplePayToken)->()), onErrorOccured: @escaping((TapApplePayRequestValidationError)->())) {
78+
@objc public func authorizePayment(for tapApplePayRequest:TapApplePayRequest, tokenized:@escaping ((TapApplePayToken)->()), onErrorOccured: @escaping((TapApplePayRequestValidationError)->())) {
7979

8080
// let us make sure the passed data are valid and allowed as merchant configuration
8181
guard validate(tapApplePayRequest: tapApplePayRequest) == .Valid else {

TapApplePayKit-iOS/Core/public/Controllers/TapApplePayButton.swift

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ import PassKit
2929
- Parameter appleToken: The correctly and authorized tokenized payment data from Apple Pay kit
3030
*/
3131
func tapApplePayValidationError(error:TapApplePayRequestValidationError)->()
32+
33+
34+
3235
}
3336
/// Class represents the UIView that has Apple pay button wrapped inside Tap Kit
3437
@objcMembers public class TapApplePayButton: UIView {
@@ -139,9 +142,8 @@ import PassKit
139142
internal func startApplePaymentAuthorization() {
140143
// It is a must to have a data source, henc the payment request itself
141144
if let nonNullDataSource = dataSource {
142-
143145
// Initiate the authorization and wait for the feedback from Apple
144-
tapApplePay.authorizePayment(in: self.findViewController()!, for: nonNullDataSource.tapApplePayRequest , tokenized: { [weak self] (token) in
146+
tapApplePay.authorizePayment(for: nonNullDataSource.tapApplePayRequest , tokenized: { [weak self] (token) in
145147
if let nonNullDelegate = self?.delegate {
146148
// If there is alistener, let him know that the authorization is done with the provided tokem
147149
nonNullDelegate.tapApplePayFinished(with: token)
@@ -162,22 +164,6 @@ extension String: LocalizedError {
162164
}
163165

164166

165-
internal extension UIView {
166-
/**
167-
An extension method to detect the viewcontroller which the current view is embedded in
168-
- Returns: UIViewcontroller that holds the current view or nil if not found for any case
169-
**/
170-
func findViewController() -> UIViewController? {
171-
if let nextResponder = self.next as? UIViewController {
172-
return nextResponder
173-
} else if let nextResponder = self.next as? UIView {
174-
return nextResponder.findViewController()
175-
} else {
176-
return nil
177-
}
178-
}
179-
}
180-
181167

182168

183169
fileprivate extension UIView {

0 commit comments

Comments
 (0)