@@ -41,9 +41,13 @@ public class CardClient: NSObject {
41
41
/// - Parameters:
42
42
/// - vaultRequest: The request containing setupTokenID and card
43
43
/// - completion: A completion block that is invoked when the request is completed. If the request succeeds,
44
- /// a `CardVaultResult` with `setupTokenID` and `status` are returned and `error` will be `nil`;
45
- /// if it fails, `CardVaultResult will be `nil` and `error` will describe the failure
46
- public func vault( _ vaultRequest: CardVaultRequest , completion: @escaping ( CardVaultResult ? , CoreSDKError ? ) -> Void ) {
44
+ /// The closure returns a `Result`:
45
+ /// - `.success(CardVaultResult)` containing:
46
+ /// - `setupTokenID`: The ID of the token that was updated.
47
+ /// - `status`: The setup token status.
48
+ /// - `didAttemptThreeDSecureAuthentication`: A flag indicating if 3D Secure authentication was attempted.
49
+ /// - `.failure(CoreSDKError)`: Describes the reason for failure.
50
+ public func vault( _ vaultRequest: CardVaultRequest , completion: @escaping ( Result < CardVaultResult , CoreSDKError > ) -> Void ) {
47
51
analyticsService = AnalyticsService ( coreConfig: config, setupToken: vaultRequest. setupTokenID)
48
52
analyticsService? . sendEvent ( " card-payments:vault-wo-purchase:started " )
49
53
Task {
@@ -79,11 +83,12 @@ public class CardClient: NSObject {
79
83
/// - Throws: A `CoreSDKError` describing failure
80
84
public func vault( _ vaultRequest: CardVaultRequest ) async throws -> CardVaultResult {
81
85
try await withCheckedThrowingContinuation { continuation in
82
- vault ( vaultRequest) { result, error in
83
- if let error {
86
+ vault ( vaultRequest) { result in
87
+ switch result {
88
+ case . success( let cardVaultResult) :
89
+ continuation. resume ( returning: cardVaultResult)
90
+ case . failure( let error) :
84
91
continuation. resume ( throwing: error)
85
- } else if let result {
86
- continuation. resume ( returning: result)
87
92
}
88
93
}
89
94
}
@@ -94,10 +99,14 @@ public class CardClient: NSObject {
94
99
/// - Parameters:
95
100
/// - orderId: Order id for approval
96
101
/// - request: The request containing the card
97
- /// - completion: A completion block that is invoked when the request is completed. If the request succeeds,
98
- /// a `CardResult` with `orderID` , `status` and `didAttemptThreeDSecureAuthentication` are returned and `error` will be `nil`;
99
- /// if it fails, `CardResult will be `nil` and `error` will describe the failure
100
- public func approveOrder( request: CardRequest , completion: @escaping ( CardResult ? , CoreSDKError ? ) -> Void ) {
102
+ /// - completion: A completion block that is invoked when the request is completed.
103
+ /// The closure returns a `Result`:
104
+ /// - `.success(CardResult)` containing:
105
+ /// - `orderID`: The ID of the approved order.
106
+ /// - `status`: The approval status.
107
+ /// - `didAttemptThreeDSecureAuthentication`: A flag indicating if 3D Secure authentication was attempted.
108
+ /// - `.failure(CoreSDKError)`: Describes the reason for failure.
109
+ public func approveOrder( request: CardRequest , completion: @escaping ( Result < CardResult , CoreSDKError > ) -> Void ) {
101
110
analyticsService = AnalyticsService ( coreConfig: config, orderID: request. orderID)
102
111
analyticsService? . sendEvent ( " card-payments:approve-order:started " )
103
112
Task {
@@ -136,11 +145,12 @@ public class CardClient: NSObject {
136
145
/// - Throws: A `CoreSDKError` describing failure
137
146
public func approveOrder( request: CardRequest ) async throws -> CardResult {
138
147
try await withCheckedThrowingContinuation { continuation in
139
- approveOrder ( request: request) { result, error in
140
- if let error {
148
+ approveOrder ( request: request) { result in
149
+ switch result {
150
+ case . success( let cardResult) :
151
+ continuation. resume ( returning: cardResult)
152
+ case . failure( let error) :
141
153
continuation. resume ( throwing: error)
142
- } else if let result {
143
- continuation. resume ( returning: result)
144
154
}
145
155
}
146
156
}
@@ -149,7 +159,7 @@ public class CardClient: NSObject {
149
159
private func startThreeDSecureChallenge(
150
160
url: URL ,
151
161
orderId: String ,
152
- completion: @escaping ( CardResult ? , CoreSDKError ? ) -> Void
162
+ completion: @escaping ( Result < CardResult , CoreSDKError > ) -> Void
153
163
) {
154
164
155
165
webAuthenticationSession. start (
@@ -188,7 +198,7 @@ public class CardClient: NSObject {
188
198
private func startVaultThreeDSecureChallenge(
189
199
url: URL ,
190
200
setupTokenID: String ,
191
- completion: @escaping ( CardVaultResult ? , CoreSDKError ? ) -> Void
201
+ completion: @escaping ( Result < CardVaultResult , CoreSDKError > ) -> Void
192
202
) {
193
203
194
204
webAuthenticationSession. start (
@@ -220,54 +230,54 @@ public class CardClient: NSObject {
220
230
)
221
231
}
222
232
223
- private func notifyCheckoutSuccess( for result: CardResult , completion: ( CardResult ? , CoreSDKError ? ) -> Void ) {
233
+ private func notifyCheckoutSuccess( for result: CardResult , completion: ( Result < CardResult , CoreSDKError > ) -> Void ) {
224
234
analyticsService? . sendEvent ( " card-payments:approve-order:succeeded " )
225
- completion ( result, nil )
235
+ completion ( . success ( result) )
226
236
}
227
237
228
- private func notify3dsCheckoutSuccess( for result: CardResult , completion: ( CardResult ? , CoreSDKError ? ) -> Void ) {
238
+ private func notify3dsCheckoutSuccess( for result: CardResult , completion: ( Result < CardResult , CoreSDKError > ) -> Void ) {
229
239
analyticsService? . sendEvent ( " card-payments:approve-order:auth-challenge:succeeded " )
230
- completion ( result, nil )
240
+ completion ( . success ( result) )
231
241
}
232
242
233
- private func notifyCheckoutFailure( with error: CoreSDKError , completion: ( CardResult ? , CoreSDKError ? ) -> Void ) {
243
+ private func notifyCheckoutFailure( with error: CoreSDKError , completion: ( Result < CardResult , CoreSDKError > ) -> Void ) {
234
244
analyticsService? . sendEvent ( " card-payments:approve-order:failed " )
235
- completion ( nil , error)
245
+ completion ( . failure ( error) )
236
246
}
237
247
238
- private func notify3dsCheckoutFailure( with error: CoreSDKError , completion: ( CardResult ? , CoreSDKError ? ) -> Void ) {
248
+ private func notify3dsCheckoutFailure( with error: CoreSDKError , completion: ( Result < CardResult , CoreSDKError > ) -> Void ) {
239
249
analyticsService? . sendEvent ( " card-payments:approve-order:auth-challenge:failed " )
240
- completion ( nil , error)
250
+ completion ( . failure ( error) )
241
251
}
242
252
243
- private func notify3dsCheckoutCancelWithError( with error: CoreSDKError , completion: ( CardResult ? , CoreSDKError ? ) -> Void ) {
253
+ private func notify3dsCheckoutCancelWithError( with error: CoreSDKError , completion: ( Result < CardResult , CoreSDKError > ) -> Void ) {
244
254
analyticsService? . sendEvent ( " card-payments:approve-order:auth-challenge:canceled " )
245
- completion ( nil , error)
255
+ completion ( . failure ( error) )
246
256
}
247
257
248
- private func notifyVaultSuccess( for vaultResult: CardVaultResult , completion: ( CardVaultResult ? , CoreSDKError ? ) -> Void ) {
258
+ private func notifyVaultSuccess( for vaultResult: CardVaultResult , completion: ( Result < CardVaultResult , CoreSDKError > ) -> Void ) {
249
259
analyticsService? . sendEvent ( " card-payments:vault-wo-purchase:succeeded " )
250
- completion ( vaultResult, nil )
260
+ completion ( . success ( vaultResult) )
251
261
}
252
262
253
- private func notify3dsVaultSuccess( for vaultResult: CardVaultResult , completion: ( CardVaultResult ? , CoreSDKError ? ) -> Void ) {
263
+ private func notify3dsVaultSuccess( for vaultResult: CardVaultResult , completion: ( Result < CardVaultResult , CoreSDKError > ) -> Void ) {
254
264
analyticsService? . sendEvent ( " card-payments:vault-wo-purchase:auth-challenge:succeeded " )
255
- completion ( vaultResult, nil )
265
+ completion ( . success ( vaultResult) )
256
266
}
257
267
258
- private func notifyVaultFailure( with vaultError: CoreSDKError , completion: ( CardVaultResult ? , CoreSDKError ? ) -> Void ) {
268
+ private func notifyVaultFailure( with vaultError: CoreSDKError , completion: ( Result < CardVaultResult , CoreSDKError > ) -> Void ) {
259
269
analyticsService? . sendEvent ( " card-payments:vault-wo-purchase:failed " )
260
- completion ( nil , vaultError)
270
+ completion ( . failure ( vaultError) )
261
271
}
262
272
263
- private func notify3dsVaultFailure( with vaultError: CoreSDKError , completion: ( CardVaultResult ? , CoreSDKError ? ) -> Void ) {
273
+ private func notify3dsVaultFailure( with vaultError: CoreSDKError , completion: ( Result < CardVaultResult , CoreSDKError > ) -> Void ) {
264
274
analyticsService? . sendEvent ( " card-payments:vault-wo-purchase:auth-challenge:failed " )
265
- completion ( nil , vaultError)
275
+ completion ( . failure ( vaultError) )
266
276
}
267
277
268
- private func notify3dsVaultCancelWithError( with vaultError: CoreSDKError , completion: ( CardVaultResult ? , CoreSDKError ? ) -> Void ) {
278
+ private func notify3dsVaultCancelWithError( with vaultError: CoreSDKError , completion: ( Result < CardVaultResult , CoreSDKError > ) -> Void ) {
269
279
analyticsService? . sendEvent ( " card-payments:vault-wo-purchase:auth-challenge:canceled " )
270
- completion ( nil , vaultError)
280
+ completion ( . failure ( vaultError) )
271
281
}
272
282
}
273
283
0 commit comments