From d6cde54904de3c317c9fe4ea17f451f81c4cab33 Mon Sep 17 00:00:00 2001 From: Victoria Park Date: Wed, 6 Nov 2024 22:37:45 -0800 Subject: [PATCH 1/4] Simplify cancel errors --- Sources/CardPayments/CardClient.swift | 4 ++-- Sources/CardPayments/CardClientError.swift | 8 ++++---- Sources/PayPalWebPayments/PayPalWebCheckoutClient.swift | 4 ++-- .../PayPalWebPayments/PayPalWebCheckoutClientError.swift | 8 ++++---- UnitTests/CardPaymentsTests/CardClient_Tests.swift | 8 ++++---- .../PayPalWebCheckoutClient_Tests.swift | 6 +++--- 6 files changed, 19 insertions(+), 19 deletions(-) diff --git a/Sources/CardPayments/CardClient.swift b/Sources/CardPayments/CardClient.swift index ab042b1d..66ab9b2c 100644 --- a/Sources/CardPayments/CardClient.swift +++ b/Sources/CardPayments/CardClient.swift @@ -170,7 +170,7 @@ public class CardClient: NSObject { if let error = error { switch error { case ASWebAuthenticationSessionError.canceledLogin: - self.notifyCheckoutCancelWithError(with: CardClientError.threeDSecureCancellation, completion: completion) + self.notifyCheckoutCancelWithError(with: CardClientError.canceled, completion: completion) return default: self.notifyCheckoutFailure(with: CardClientError.threeDSecureError(error), completion: completion) @@ -206,7 +206,7 @@ public class CardClient: NSObject { if let error = error { switch error { case ASWebAuthenticationSessionError.canceledLogin: - self.notifyVaultCancelWithError(with: CardClientError.threeDSecureCancellation, completion: completion) + self.notifyVaultCancelWithError(with: CardClientError.canceled, completion: completion) return default: self.notifyVaultFailure(with: CardClientError.threeDSecureError(error), completion: completion) diff --git a/Sources/CardPayments/CardClientError.swift b/Sources/CardPayments/CardClientError.swift index d068833b..6c5f4206 100644 --- a/Sources/CardPayments/CardClientError.swift +++ b/Sources/CardPayments/CardClientError.swift @@ -39,7 +39,7 @@ enum CardClientError { case malformedDeeplinkURLError /// 10. Cancellation from 3DS verification - case threeDSCancellation + case canceledError } static let unknownError = CoreSDKError( @@ -68,10 +68,10 @@ enum CardClientError { errorDescription: "An invalid 3DS URL was returned. Contact developer.paypal.com/support." ) - static let threeDSecureCancellation = CoreSDKError( - code: Code.threeDSCancellation.rawValue, + static let canceled = CoreSDKError( + code: Code.canceledError.rawValue, domain: domain, - errorDescription: "3DS verification has been cancelled by the user." + errorDescription: "3DS verification has been canceled by the user." ) static let noVaultTokenDataError = CoreSDKError( diff --git a/Sources/PayPalWebPayments/PayPalWebCheckoutClient.swift b/Sources/PayPalWebPayments/PayPalWebCheckoutClient.swift index 4f1bde35..228424ed 100644 --- a/Sources/PayPalWebPayments/PayPalWebCheckoutClient.swift +++ b/Sources/PayPalWebPayments/PayPalWebCheckoutClient.swift @@ -64,7 +64,7 @@ public class PayPalWebCheckoutClient: NSObject { switch error { case ASWebAuthenticationSessionError.canceledLogin: self.notifyCheckoutCancelWithError( - with: PayPalWebCheckoutClientError.payPalCancellationError, + with: PayPalWebCheckoutClientError.checkoutCanceled, completion: completion ) return @@ -153,7 +153,7 @@ public class PayPalWebCheckoutClient: NSObject { switch error { case ASWebAuthenticationSessionError.canceledLogin: self.notifyVaultCancelWithError( - with: PayPalWebCheckoutClientError.payPalVaultCancellationError, + with: PayPalWebCheckoutClientError.vaultCanceled, completion: completion ) return diff --git a/Sources/PayPalWebPayments/PayPalWebCheckoutClientError.swift b/Sources/PayPalWebPayments/PayPalWebCheckoutClientError.swift index 8fc0146c..48f32bb0 100644 --- a/Sources/PayPalWebPayments/PayPalWebCheckoutClientError.swift +++ b/Sources/PayPalWebPayments/PayPalWebCheckoutClientError.swift @@ -57,15 +57,15 @@ enum PayPalWebCheckoutClientError { errorDescription: "Error parsing PayPal vault response" ) - static let payPalCancellationError = CoreSDKError( + static let checkoutCanceled = CoreSDKError( code: Code.payPalCancellationError.rawValue, domain: domain, - errorDescription: "PayPal checkout has been cancelled by the user" + errorDescription: "PayPal checkout has been canceled by the user" ) - static let payPalVaultCancellationError = CoreSDKError( + static let vaultCanceled = CoreSDKError( code: Code.payPalVaultCancellationError.rawValue, domain: domain, - errorDescription: "PayPal vault has been cancelled by the user" + errorDescription: "PayPal vault has been canceled by the user" ) } diff --git a/UnitTests/CardPaymentsTests/CardClient_Tests.swift b/UnitTests/CardPaymentsTests/CardClient_Tests.swift index e23065c7..2985a174 100644 --- a/UnitTests/CardPaymentsTests/CardClient_Tests.swift +++ b/UnitTests/CardPaymentsTests/CardClient_Tests.swift @@ -203,8 +203,8 @@ class CardClient_Tests: XCTestCase { XCTAssertNil(result) if let error = error as? CoreSDKError { XCTAssertEqual(error.domain, CardClientError.domain) - XCTAssertEqual(error.code, CardClientError.Code.threeDSCancellation.rawValue) - XCTAssertEqual(error.localizedDescription, CardClientError.threeDSecureCancellation.localizedDescription) + XCTAssertEqual(error.code, CardClientError.Code.canceledError.rawValue) + XCTAssertEqual(error.localizedDescription, CardClientError.canceled.localizedDescription) } else { XCTFail("Expected error to be of type CoreSDKError") } @@ -361,8 +361,8 @@ class CardClient_Tests: XCTestCase { XCTAssertNil(result) if let error = error as? CoreSDKError { XCTAssertEqual(error.domain, CardClientError.domain) - XCTAssertEqual(error.code, CardClientError.threeDSecureCancellation.code) - XCTAssertEqual(error.localizedDescription, CardClientError.threeDSecureCancellation.localizedDescription) + XCTAssertEqual(error.code, CardClientError.canceled.code) + XCTAssertEqual(error.localizedDescription, CardClientError.canceled.localizedDescription) } else { XCTFail("Expected error to be of type CoreSDKError") } diff --git a/UnitTests/PayPalWebPaymentsTests/PayPalWebCheckoutClient_Tests.swift b/UnitTests/PayPalWebPaymentsTests/PayPalWebCheckoutClient_Tests.swift index 6b43fa9b..12ca902b 100644 --- a/UnitTests/PayPalWebPaymentsTests/PayPalWebCheckoutClient_Tests.swift +++ b/UnitTests/PayPalWebPaymentsTests/PayPalWebCheckoutClient_Tests.swift @@ -80,7 +80,7 @@ class PayPalClient_Tests: XCTestCase { if let error = error as? CoreSDKError { XCTAssertEqual(error.domain, PayPalWebCheckoutClientError.domain) XCTAssertEqual(error.code, PayPalWebCheckoutClientError.Code.payPalVaultCancellationError.rawValue) - XCTAssertEqual(error.localizedDescription, "PayPal vault has been cancelled by the user") + XCTAssertEqual(error.localizedDescription, "PayPal vault has been canceled by the user") } else { XCTFail("Expected error to be of type CoreSDKError") } @@ -159,8 +159,8 @@ class PayPalClient_Tests: XCTestCase { XCTAssertNil(result) if let error = error as? CoreSDKError { XCTAssertEqual(error.domain, PayPalWebCheckoutClientError.domain) - XCTAssertEqual(error.code, PayPalWebCheckoutClientError.payPalCancellationError.code) - XCTAssertEqual(error.localizedDescription, PayPalWebCheckoutClientError.payPalCancellationError.localizedDescription) + XCTAssertEqual(error.code, PayPalWebCheckoutClientError.checkoutCanceled.code) + XCTAssertEqual(error.localizedDescription, PayPalWebCheckoutClientError.checkoutCanceled.localizedDescription) } else { XCTFail("Expected error to be of type CoreSDKError") } From 986eabd3a172dc62f28385d1bdd6c6b147239ebe Mon Sep 17 00:00:00 2001 From: Victoria Park Date: Thu, 7 Nov 2024 07:05:48 -0800 Subject: [PATCH 2/4] CHANGELOG for the cancel errors --- CHANGELOG.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c8bea1fe..ed7b97cc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ * Add `vault(vaultRequest:completion(PayPalVaultResult?, Error?) -> Void)` to `PayPalWebCheckoutClient` * Add `start(request:) async throws -> PayPalCheckoutResult` * Add `vault(vaultRequest:) async throws -> PayPalVaultResult` + * Add `.checkoutCanceled` and `.vaultCanceled` to `PayPalWebCheckoutClientError` * CardPayments * Replace delegate pattern with completion handlers and Swift concurrency * Remove `CardDelegate` and `CardVaultDelegate` @@ -22,7 +23,8 @@ * Add `approveOrder(request:completion:(CardResult?, Error?) -> Void)` to `CardClient` * Add `vault(request:completion:(CardVaultResult?, Error?) -> Void)` to `CardClient` * Add `approveOrder(request:) async throws -> CardResult` - * Add `vault(vaultRequest:) async throws -> CardVaultResult` + * Add `vault(vaultRequest:) async throws -> CardVaultResult` + * Add `.canceled` to `CardClientError` * PayPalWebPayments * Deprecate `PayPalVaultRequest(url:setupTokenID:)` * Add `PayPalVaultRequest(setupTokenID:)` From 83270eebf525f53fd3f1ef80ab349eebc6de3a8d Mon Sep 17 00:00:00 2001 From: Victoria Park Date: Thu, 7 Nov 2024 08:40:44 -0800 Subject: [PATCH 3/4] Steven PR feedback: change back CardClientError.canceled to .threeDSecureCanceled --- Sources/CardPayments/CardClient.swift | 4 ++-- Sources/CardPayments/CardClientError.swift | 6 +++--- UnitTests/CardPaymentsTests/CardClient_Tests.swift | 8 ++++---- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Sources/CardPayments/CardClient.swift b/Sources/CardPayments/CardClient.swift index 66ab9b2c..9104f5c0 100644 --- a/Sources/CardPayments/CardClient.swift +++ b/Sources/CardPayments/CardClient.swift @@ -170,7 +170,7 @@ public class CardClient: NSObject { if let error = error { switch error { case ASWebAuthenticationSessionError.canceledLogin: - self.notifyCheckoutCancelWithError(with: CardClientError.canceled, completion: completion) + self.notifyCheckoutCancelWithError(with: CardClientError.threeDSecureCanceled, completion: completion) return default: self.notifyCheckoutFailure(with: CardClientError.threeDSecureError(error), completion: completion) @@ -206,7 +206,7 @@ public class CardClient: NSObject { if let error = error { switch error { case ASWebAuthenticationSessionError.canceledLogin: - self.notifyVaultCancelWithError(with: CardClientError.canceled, completion: completion) + self.notifyVaultCancelWithError(with: CardClientError.threeDSecureCanceled, completion: completion) return default: self.notifyVaultFailure(with: CardClientError.threeDSecureError(error), completion: completion) diff --git a/Sources/CardPayments/CardClientError.swift b/Sources/CardPayments/CardClientError.swift index 6c5f4206..fa94319b 100644 --- a/Sources/CardPayments/CardClientError.swift +++ b/Sources/CardPayments/CardClientError.swift @@ -39,7 +39,7 @@ enum CardClientError { case malformedDeeplinkURLError /// 10. Cancellation from 3DS verification - case canceledError + case threeDSCancellationError } static let unknownError = CoreSDKError( @@ -68,8 +68,8 @@ enum CardClientError { errorDescription: "An invalid 3DS URL was returned. Contact developer.paypal.com/support." ) - static let canceled = CoreSDKError( - code: Code.canceledError.rawValue, + static let threeDSecureCanceled = CoreSDKError( + code: Code.threeDSCancellationError.rawValue, domain: domain, errorDescription: "3DS verification has been canceled by the user." ) diff --git a/UnitTests/CardPaymentsTests/CardClient_Tests.swift b/UnitTests/CardPaymentsTests/CardClient_Tests.swift index 2985a174..53534faf 100644 --- a/UnitTests/CardPaymentsTests/CardClient_Tests.swift +++ b/UnitTests/CardPaymentsTests/CardClient_Tests.swift @@ -203,8 +203,8 @@ class CardClient_Tests: XCTestCase { XCTAssertNil(result) if let error = error as? CoreSDKError { XCTAssertEqual(error.domain, CardClientError.domain) - XCTAssertEqual(error.code, CardClientError.Code.canceledError.rawValue) - XCTAssertEqual(error.localizedDescription, CardClientError.canceled.localizedDescription) + XCTAssertEqual(error.code, CardClientError.Code.threeDSCancellationError.rawValue) + XCTAssertEqual(error.localizedDescription, CardClientError.threeDSecureCanceled.localizedDescription) } else { XCTFail("Expected error to be of type CoreSDKError") } @@ -361,8 +361,8 @@ class CardClient_Tests: XCTestCase { XCTAssertNil(result) if let error = error as? CoreSDKError { XCTAssertEqual(error.domain, CardClientError.domain) - XCTAssertEqual(error.code, CardClientError.canceled.code) - XCTAssertEqual(error.localizedDescription, CardClientError.canceled.localizedDescription) + XCTAssertEqual(error.code, CardClientError.threeDSecureCanceled.code) + XCTAssertEqual(error.localizedDescription, CardClientError.threeDSecureCanceled.localizedDescription) } else { XCTFail("Expected error to be of type CoreSDKError") } From ceeb3f5987b218c19460dc85ff1292360560357f Mon Sep 17 00:00:00 2001 From: Victoria Park Date: Thu, 7 Nov 2024 08:42:08 -0800 Subject: [PATCH 4/4] CHANGELOG update --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ed7b97cc..ed74e087 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,7 +24,7 @@ * Add `vault(request:completion:(CardVaultResult?, Error?) -> Void)` to `CardClient` * Add `approveOrder(request:) async throws -> CardResult` * Add `vault(vaultRequest:) async throws -> CardVaultResult` - * Add `.canceled` to `CardClientError` + * Add `.threeDSecureCanceled` to `CardClientError` * PayPalWebPayments * Deprecate `PayPalVaultRequest(url:setupTokenID:)` * Add `PayPalVaultRequest(setupTokenID:)`