From ebad6704717ae5852c877c45122e1a2aa62f42ac Mon Sep 17 00:00:00 2001 From: Mark Murray Date: Mon, 22 Apr 2024 11:27:19 +0100 Subject: [PATCH] Add isRecoverable property to CheckoutError --- .../MobileBuyIntegration/CartViewController.swift | 2 +- .../ShopifyCheckoutSheetKit/CheckoutDelegate.swift | 2 +- Sources/ShopifyCheckoutSheetKit/CheckoutError.swift | 11 +++++++++++ .../CheckoutWebViewController.swift | 9 +-------- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/Samples/MobileBuyIntegration/MobileBuyIntegration/CartViewController.swift b/Samples/MobileBuyIntegration/MobileBuyIntegration/CartViewController.swift index 4b2df0fb..897509b4 100644 --- a/Samples/MobileBuyIntegration/MobileBuyIntegration/CartViewController.swift +++ b/Samples/MobileBuyIntegration/MobileBuyIntegration/CartViewController.swift @@ -170,7 +170,7 @@ extension CartViewController: CheckoutDelegate { } func shouldRecoverFromError(error: CheckoutError) -> Bool { - return true + return error.isRecoverable } func checkoutDidFail(error: ShopifyCheckoutSheetKit.CheckoutError) { diff --git a/Sources/ShopifyCheckoutSheetKit/CheckoutDelegate.swift b/Sources/ShopifyCheckoutSheetKit/CheckoutDelegate.swift index 43fb6dde..1ea03ddd 100644 --- a/Sources/ShopifyCheckoutSheetKit/CheckoutDelegate.swift +++ b/Sources/ShopifyCheckoutSheetKit/CheckoutDelegate.swift @@ -60,7 +60,7 @@ extension CheckoutDelegate { } public func shouldRecoverFromError(error: CheckoutError) -> Bool { - return true + return error.isRecoverable } private func handleUrl(_ url: URL) { diff --git a/Sources/ShopifyCheckoutSheetKit/CheckoutError.swift b/Sources/ShopifyCheckoutSheetKit/CheckoutError.swift index b7e104be..e168d6a4 100644 --- a/Sources/ShopifyCheckoutSheetKit/CheckoutError.swift +++ b/Sources/ShopifyCheckoutSheetKit/CheckoutError.swift @@ -72,6 +72,17 @@ public enum CheckoutError: Swift.Error { /// This may happen when the user has paused on checkout for a long period (hours) and then attempted to proceed again with the same checkout url /// In event of checkoutExpired, a new checkout url will need to be generated case checkoutExpired(message: String, code: CheckoutErrorCode, recoverable: Bool = false) + + public var isRecoverable: Bool { + switch self { + case .authenticationError(_, _, let recoverable), + .checkoutExpired(_, _, let recoverable), + .checkoutUnavailable(_, _, let recoverable), + .configurationError(_, _, let recoverable), + .sdkError(_, let recoverable): + return recoverable + } + } } internal enum CheckoutErrorGroup: String, Codable { diff --git a/Sources/ShopifyCheckoutSheetKit/CheckoutWebViewController.swift b/Sources/ShopifyCheckoutSheetKit/CheckoutWebViewController.swift index 0b03334e..960a0f84 100644 --- a/Sources/ShopifyCheckoutSheetKit/CheckoutWebViewController.swift +++ b/Sources/ShopifyCheckoutSheetKit/CheckoutWebViewController.swift @@ -240,13 +240,6 @@ extension CheckoutWebViewController: CheckoutWebViewDelegate { } private func isErrorRecoverable(error: CheckoutError) -> Bool { - switch error { - case .authenticationError(_, _, let recoverable), - .checkoutExpired(_, _, let recoverable), - .checkoutUnavailable(_, _, let recoverable), - .configurationError(_, _, let recoverable), - .sdkError(_, let recoverable): - return recoverable - } + return error.isRecoverable } }