|
12 | 12 | import UIKit |
13 | 13 |
|
14 | 14 | @objc |
15 | | -internal protocol InternalCardComponentsManagerDelegate { |
| 15 | +protocol InternalCardComponentsManagerDelegate { |
16 | 16 | /// The cardComponentsManager(_:clientTokenCallback:) can be used to provide the CardComponentsManager |
17 | 17 | /// with an access token from the merchants backend. |
18 | 18 | /// This delegate function is optional since you can initialize the CardComponentsManager with an access token. |
@@ -70,18 +70,20 @@ final class InternalCardComponentsManager: NSObject, InternalCardComponentsManag |
70 | 70 | var merchantIdentifier: String? |
71 | 71 | var amount: Int? |
72 | 72 | var currency: Currency? |
73 | | - internal var decodedJWTToken: DecodedJWTToken? { |
| 73 | + var decodedJWTToken: DecodedJWTToken? { |
74 | 74 | return PrimerAPIConfigurationModule.decodedJWTToken |
75 | 75 | } |
76 | | - internal var paymentMethodsConfig: PrimerAPIConfiguration? |
77 | | - internal var primerPaymentMethodType: PrimerPaymentMethodType |
78 | | - private(set) public var isLoading: Bool = false |
79 | | - internal private(set) var paymentMethod: PrimerPaymentMethodTokenData? |
| 76 | + var paymentMethodsConfig: PrimerAPIConfiguration? |
| 77 | + var primerPaymentMethodType: PrimerPaymentMethodType |
| 78 | + public private(set) var isLoading: Bool = false |
| 79 | + private(set) var paymentMethod: PrimerPaymentMethodTokenData? |
80 | 80 |
|
81 | 81 | let tokenizationService: TokenizationServiceProtocol |
82 | 82 |
|
83 | 83 | deinit { |
84 | | - setIsLoading(false) |
| 84 | + if isLoading { |
| 85 | + delegate.cardComponentsManager?(self, isLoading: false) |
| 86 | + } |
85 | 87 | } |
86 | 88 |
|
87 | 89 | /// The CardComponentsManager can be initialized with/out an access token. |
@@ -119,7 +121,8 @@ final class InternalCardComponentsManager: NSObject, InternalCardComponentsManag |
119 | 121 | super.init() |
120 | 122 | } |
121 | 123 |
|
122 | | - internal func setIsLoading(_ isLoading: Bool) { |
| 124 | + @MainActor |
| 125 | + func setIsLoading(_ isLoading: Bool) { |
123 | 126 | if self.isLoading == isLoading { return } |
124 | 127 | self.isLoading = isLoading |
125 | 128 | delegate.cardComponentsManager?(self, isLoading: isLoading) |
@@ -201,7 +204,7 @@ and 4 characters for expiry year separated by '/'. |
201 | 204 | billingAddressFieldViews?.filter { $0.isTextValid == false }.forEach { |
202 | 205 | if let simpleCardFormTextFieldView = $0 as? PrimerSimpleCardFormTextFieldView { |
203 | 206 | switch simpleCardFormTextFieldView.validation { |
204 | | - case .invalid(let error): errors.append(handled(error: error!)) |
| 207 | + case let .invalid(error): errors.append(handled(error: error!)) |
205 | 208 | default: break |
206 | 209 | } |
207 | 210 | } |
@@ -254,9 +257,8 @@ and 4 characters for expiry year separated by '/'. |
254 | 257 | } |
255 | 258 |
|
256 | 259 | public func tokenize() { |
257 | | - setIsLoading(true) |
258 | | - |
259 | 260 | Task { |
| 261 | + await setIsLoading(true) |
260 | 262 | do { |
261 | 263 | try validateCardComponents() |
262 | 264 | _ = try await self.fetchClientTokenIfNeeded() |
@@ -317,12 +319,12 @@ and 4 characters for expiry year separated by '/'. |
317 | 319 | throw handled(primerError: error.asPrimerError) |
318 | 320 | } |
319 | 321 |
|
320 | | - } catch PrimerError.underlyingErrors(let errors, _) { |
| 322 | + } catch let PrimerError.underlyingErrors(errors, _) { |
321 | 323 | delegate.cardComponentsManager?(self, tokenizationFailedWith: errors) |
322 | | - setIsLoading(false) |
| 324 | + await setIsLoading(false) |
323 | 325 | } catch { |
324 | 326 | delegate.cardComponentsManager?(self, tokenizationFailedWith: [error]) |
325 | | - setIsLoading(false) |
| 327 | + await setIsLoading(false) |
326 | 328 | } |
327 | 329 | } |
328 | 330 | } |
|
0 commit comments