Skip to content

Commit 41b0f03

Browse files
authored
Make PayPalError and CardError Code enum consistent (#298)
1 parent f3b8fc0 commit 41b0f03

File tree

7 files changed

+31
-32
lines changed

7 files changed

+31
-32
lines changed

CHANGELOG.md

+6-7
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616
* Add `vault(vaultRequest:) async throws -> PayPalVaultResult`
1717
* Add `.checkoutCanceled` and `.vaultCanceled` to `PayPalWebCheckoutClientError`
1818
* Rename `PayPalWebCheckoutClientError` to `PayPalError`
19+
* Add `.checkoutCanceledError` and `vaultCanceledError` to `PayPalError`
1920
* Add public static functions `isCheckoutCanceled(Error)` and `isVaultCanceled(Error)` to `PayPalError` to distinguish cancellation errors in PayPal flows.
21+
* Make `PayPalError` public to expose cancellation error handling helpers
2022
* CardPayments
2123
* Replace delegate pattern with completion handlers and Swift concurrency
2224
* Remove `CardDelegate` and `CardVaultDelegate`
@@ -27,16 +29,13 @@
2729
* Add `approveOrder(request:) async throws -> CardResult`
2830
* Add `vault(vaultRequest:) async throws -> CardVaultResult`
2931
* Add `.threeDSecureCanceled` to `CardClientError`
30-
* Rename `PayPalClientError` to `PayPalError`
31-
* Add public static function `isThreeDSecureCanceled(Error)` to `CardClientError` to distinguish cancellation error from threeDSecure verification
32+
* Rename `CardClientError` to `CardError`
33+
* Add `threeDSecureCanceledError` to `CardError`
34+
* Add public static function `isThreeDSecureCanceled(Error)` to `CardError` to distinguish cancellation error from threeDSecure verification
35+
* Make `CardError` public to expose cancellation error handling helper
3236
* PayPalWebPayments
3337
* Deprecate `PayPalVaultRequest(url:setupTokenID:)`
3438
* Add `PayPalVaultRequest(setupTokenID:)`
35-
* Add new error types for cancellation handling:
36-
* `PayPalWebCheckoutClientError.payPalCancellationError`
37-
* `PayPalWebCheckoutClientError.payPalVaultCancellationError`
38-
* CardPayments
39-
* Add new error type `CardClientError.threeDSecureCancellation` for handling 3DS cancellation
4039

4140
## 1.4.0 (2024-07-09)
4241
* PayPalNativePayments (DEPRECATED)

Sources/CardPayments/CardClient.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ public class CardClient: NSObject {
170170
if let error = error {
171171
switch error {
172172
case ASWebAuthenticationSessionError.canceledLogin:
173-
self.notifyCheckoutCancelWithError(with: CardError.threeDSecureCanceled, completion: completion)
173+
self.notifyCheckoutCancelWithError(with: CardError.threeDSecureCanceledError, completion: completion)
174174
return
175175
default:
176176
self.notifyCheckoutFailure(with: CardError.threeDSecureError(error), completion: completion)
@@ -210,7 +210,7 @@ public class CardClient: NSObject {
210210
if let error = error {
211211
switch error {
212212
case ASWebAuthenticationSessionError.canceledLogin:
213-
self.notifyVaultCancelWithError(with: CardError.threeDSecureCanceled, completion: completion)
213+
self.notifyVaultCancelWithError(with: CardError.threeDSecureCanceledError, completion: completion)
214214
return
215215
default:
216216
self.notifyVaultFailure(with: CardError.threeDSecureError(error), completion: completion)

Sources/CardPayments/CardError.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public enum CardError {
3939
case malformedDeeplinkURLError
4040

4141
/// 10. Cancellation from 3DS verification
42-
case threeDSCancellationError
42+
case threeDSecureCanceledError
4343
}
4444

4545
static let unknownError = CoreSDKError(
@@ -68,8 +68,8 @@ public enum CardError {
6868
errorDescription: "An invalid 3DS URL was returned. Contact developer.paypal.com/support."
6969
)
7070

71-
static let threeDSecureCanceled = CoreSDKError(
72-
code: Code.threeDSCancellationError.rawValue,
71+
static let threeDSecureCanceledError = CoreSDKError(
72+
code: Code.threeDSecureCanceledError.rawValue,
7373
domain: domain,
7474
errorDescription: "3DS verification has been canceled by the user."
7575
)
@@ -97,6 +97,6 @@ public enum CardError {
9797
guard let error = error as? CoreSDKError else {
9898
return false
9999
}
100-
return error.domain == CardError.domain && error.code == CardError.threeDSecureCanceled.code
100+
return error.domain == CardError.domain && error.code == CardError.threeDSecureCanceledError.code
101101
}
102102
}

Sources/PayPalWebPayments/PayPalError.swift

+10-10
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ public enum PayPalError {
2424
/// 4. Vault result did not return a token id
2525
case payPalVaultResponseError
2626

27-
/// 5. Websession is cancelled by the user
28-
case payPalCancellationError
27+
/// 5. Checkout websession is cancelled by the user
28+
case checkoutCanceledError
2929

30-
/// 6. Websession is cancelled by the user
31-
case payPalVaultCancellationError
30+
/// 6. Vault websession is cancelled by the user
31+
case vaultCanceledError
3232
}
3333

3434
static let webSessionError: (Error) -> CoreSDKError = { error in
@@ -57,14 +57,14 @@ public enum PayPalError {
5757
errorDescription: "Error parsing PayPal vault response"
5858
)
5959

60-
static let checkoutCanceled = CoreSDKError(
61-
code: Code.payPalCancellationError.rawValue,
60+
static let checkoutCanceledError = CoreSDKError(
61+
code: Code.checkoutCanceledError.rawValue,
6262
domain: domain,
6363
errorDescription: "PayPal checkout has been canceled by the user"
6464
)
6565

66-
static let vaultCanceled = CoreSDKError(
67-
code: Code.payPalVaultCancellationError.rawValue,
66+
static let vaultCanceledError = CoreSDKError(
67+
code: Code.vaultCanceledError.rawValue,
6868
domain: domain,
6969
errorDescription: "PayPal vault has been canceled by the user"
7070
)
@@ -74,14 +74,14 @@ public enum PayPalError {
7474
guard let error = error as? CoreSDKError else {
7575
return false
7676
}
77-
return error.domain == PayPalError.domain && error.code == PayPalError.checkoutCanceled.code
77+
return error.domain == PayPalError.domain && error.code == PayPalError.checkoutCanceledError.code
7878
}
7979

8080
// Helper function that allows handling of PayPal vault cancel errors separately without having to cast the error to CoreSDKError and checking code and domain properties.
8181
public static func isVaultCanceled(_ error: Error) -> Bool {
8282
guard let error = error as? CoreSDKError else {
8383
return false
8484
}
85-
return error.domain == PayPalError.domain && error.code == PayPalError.vaultCanceled.code
85+
return error.domain == PayPalError.domain && error.code == PayPalError.vaultCanceledError.code
8686
}
8787
}

Sources/PayPalWebPayments/PayPalWebCheckoutClient.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public class PayPalWebCheckoutClient: NSObject {
6464
switch error {
6565
case ASWebAuthenticationSessionError.canceledLogin:
6666
self.notifyCheckoutCancelWithError(
67-
with: PayPalError.checkoutCanceled,
67+
with: PayPalError.checkoutCanceledError,
6868
completion: completion
6969
)
7070
return
@@ -153,7 +153,7 @@ public class PayPalWebCheckoutClient: NSObject {
153153
switch error {
154154
case ASWebAuthenticationSessionError.canceledLogin:
155155
self.notifyVaultCancelWithError(
156-
with: PayPalError.vaultCanceled,
156+
with: PayPalError.vaultCanceledError,
157157
completion: completion
158158
)
159159
return

UnitTests/CardPaymentsTests/CardClient_Tests.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,8 @@ class CardClient_Tests: XCTestCase {
204204
XCTAssertNil(result)
205205
if let error {
206206
XCTAssertEqual(error.domain, CardError.domain)
207-
XCTAssertEqual(error.code, CardError.Code.threeDSCancellationError.rawValue)
208-
XCTAssertEqual(error.localizedDescription, CardError.threeDSecureCanceled.localizedDescription)
207+
XCTAssertEqual(error.code, CardError.Code.threeDSecureCanceledError.rawValue)
208+
XCTAssertEqual(error.localizedDescription, CardError.threeDSecureCanceledError.localizedDescription)
209209
} else {
210210
XCTFail("Expected error not to be nil")
211211
}
@@ -364,8 +364,8 @@ class CardClient_Tests: XCTestCase {
364364
XCTAssertNil(result)
365365
if let error = error {
366366
XCTAssertEqual(error.domain, CardError.domain)
367-
XCTAssertEqual(error.code, CardError.threeDSecureCanceled.code)
368-
XCTAssertEqual(error.localizedDescription, CardError.threeDSecureCanceled.localizedDescription)
367+
XCTAssertEqual(error.code, CardError.threeDSecureCanceledError.code)
368+
XCTAssertEqual(error.localizedDescription, CardError.threeDSecureCanceledError.localizedDescription)
369369
} else {
370370
XCTFail("Expected error")
371371
}

UnitTests/PayPalWebPaymentsTests/PayPalWebCheckoutClient_Tests.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ class PayPalClient_Tests: XCTestCase {
7979
XCTAssertNil(result)
8080
if let error {
8181
XCTAssertEqual(error.domain, PayPalError.domain)
82-
XCTAssertEqual(error.code, PayPalError.Code.payPalVaultCancellationError.rawValue)
82+
XCTAssertEqual(error.code, PayPalError.Code.vaultCanceledError.rawValue)
8383
XCTAssertEqual(error.localizedDescription, "PayPal vault has been canceled by the user")
8484
} else {
8585
XCTFail("Expected error not to be nil")
@@ -182,8 +182,8 @@ class PayPalClient_Tests: XCTestCase {
182182
XCTAssertNil(result)
183183
if let error {
184184
XCTAssertEqual(error.domain, PayPalError.domain)
185-
XCTAssertEqual(error.code, PayPalError.checkoutCanceled.code)
186-
XCTAssertEqual(error.localizedDescription, PayPalError.checkoutCanceled.localizedDescription)
185+
XCTAssertEqual(error.code, PayPalError.checkoutCanceledError.code)
186+
XCTAssertEqual(error.localizedDescription, PayPalError.checkoutCanceledError.localizedDescription)
187187
} else {
188188
XCTFail("Expected error not to be nil")
189189
}

0 commit comments

Comments
 (0)