Skip to content

Commit

Permalink
return an error when checkout 404s. indicate to client that it may be…
Browse files Browse the repository at this point in the history
… due to store using checkout.liquid
  • Loading branch information
cianbuckley committed Oct 24, 2023
1 parent a680665 commit a058e24
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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.
Expand Down
6 changes: 6 additions & 0 deletions Sources/ShopifyCheckout/CheckoutError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
5 changes: 4 additions & 1 deletion Sources/ShopifyCheckout/CheckoutView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -180,6 +182,7 @@ extension CheckoutView: WKNavigationDelegate {
private func isCheckout(url: URL?) -> Bool {
return self.url == url
}

}

extension CheckoutView {
Expand Down

0 comments on commit a058e24

Please sign in to comment.