From a058e24bf413f281c65cb60c0e3ff03fade56c0d Mon Sep 17 00:00:00 2001 From: Cian Buckley Date: Tue, 24 Oct 2023 16:55:36 +0200 Subject: [PATCH] return an error when checkout 404s. indicate to client that it may be due to store using checkout.liquid --- README.md | 5 +++++ Sources/ShopifyCheckout/CheckoutError.swift | 6 ++++++ Sources/ShopifyCheckout/CheckoutView.swift | 5 ++++- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a9374fa6..eec6c4f0 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,7 @@ ### Requirements - Swift 5.7+ - iOS SDK 13.0+ +- The SDK is not compatable with checkout.liquid. The Shopify Store must be migrated for extensibility ### Getting Started The SDK is an open-source [Swift Package library](https://www.swift.org/package-manager/). As a quick start, see [sample projects](Samples/README.md) or use one of the following ways to integrate the SDK into your project: @@ -163,6 +164,10 @@ extension MyViewController: ShopifyCheckoutDelegate { /// Internal error: exception within the Checkout SDK code /// You can inspect and log the Erorr and stacktrace to identify the problem. case sdkError(underlying: Swift.Error) + + /// Issued when the provided checkout URL results in a 404. + /// The SDK only supports stores migrated for extensibility. This can be an indicator that the store is still using checkout.liquid and needs to be migrated to extensibility + case sdkError(underlying: CheckoutLiquidError.unmigratedCheckout) /// Unavailable error: checkout cannot be initiated or completed, e.g. due to network or server-side error /// The provided message describes the error and may be logged and presented to the buyer. diff --git a/Sources/ShopifyCheckout/CheckoutError.swift b/Sources/ShopifyCheckout/CheckoutError.swift index 8d345fdf..309e40f3 100644 --- a/Sources/ShopifyCheckout/CheckoutError.swift +++ b/Sources/ShopifyCheckout/CheckoutError.swift @@ -37,3 +37,9 @@ public enum CheckoutError: Swift.Error { /// In event of checkoutExpired, a new checkout url will need to be generated case checkoutExpired(message: String) } + +public enum CheckoutLiquidError: Swift.Error { + /// Issued when the provided checkout URL results in a 404. + /// The SDK only supports stores migrated for extensibility. This can be an indicator that the store is still using checkout.liquid and needs to be migrated to extensibility + case unmigratedCheckoutError(message: String) +} diff --git a/Sources/ShopifyCheckout/CheckoutView.swift b/Sources/ShopifyCheckout/CheckoutView.swift index e17a153f..fdc74200 100644 --- a/Sources/ShopifyCheckout/CheckoutView.swift +++ b/Sources/ShopifyCheckout/CheckoutView.swift @@ -142,8 +142,10 @@ extension CheckoutView: WKNavigationDelegate { if isCheckout(url: response.url) && response.statusCode >= 400 { CheckoutView.cache = nil switch response.statusCode { - case 404, 410: + case 410: viewDelegate?.checkoutViewDidFailWithError(error: .checkoutExpired(message: "Checkout has expired")) + case 404: + viewDelegate?.checkoutViewDidFailWithError(error: .sdkError(underlying: CheckoutLiquidError.unmigratedCheckoutError(message: "The checkout url provided has resulted in a 404. It may be possible that the provided checkout url is not valid. It is also possible the store is still using checkout.liquid. This checkout SDK only supports checkout with extensibility. Please ensure that the store is migrated to extensibility"))) case 500: viewDelegate?.checkoutViewDidFailWithError(error: .checkoutUnavailable(message: "Checkout unavailable due to error")) default: @@ -180,6 +182,7 @@ extension CheckoutView: WKNavigationDelegate { private func isCheckout(url: URL?) -> Bool { return self.url == url } + } extension CheckoutView {