Shopify / checkout-sheet-kit-swift

Shopify’s Checkout Sheet Kit makes it simple to perform a checkout inside your Swift native app.
MIT License
38 stars 15 forks source link

Checkout Sheet Kit doesn't work with an extensibility preview store #186

Closed joshgare closed 4 months ago

joshgare commented 4 months ago

We're trying to test our implementation of CSK using a developer preview store setup with checkout extensibility.

However, as we are using a preview store we are asked to enter the store password in the checkout flow which redirects the user back to the homepage rather than the checkout flow. This effectively makes it impossible to test the CSK.

https://github.com/Shopify/checkout-sheet-kit-swift/assets/113687/ba2a7d84-7744-484e-a9e5-4c5c33f79e66

kiftio commented 4 months ago

Hi @joshgare, I'd have thought the login page would have redirected to checkout, but it doesn't seem to be the case. I'll try to find out if that's a regression

In the meantime, when you enter a valid password, a cookie should be dropped into your cookie store allowing you to bypass the password page next time you open checkout.

It should be the storefront_digest cookie mentioned here

joshgare commented 4 months ago

@kiftio the cookie doesn't seem to be retained across Checkout Sheet Kit sessions - do you have an example how we can do this? Or shall we wait for the redirect to be fixed?

kiftio commented 4 months ago

Ah, apologies for that. It's not so convenient, but to unblock testing you should be able to do something like this:

import WebKit

// ...

let cookieStore = WKWebsiteDataStore.default().httpCookieStore

var cookieProperties = [HTTPCookiePropertyKey: Any]()
cookieProperties[.domain] = "checkout-sdk.myshopify.com"
cookieProperties[.path] = "/"
cookieProperties[.name] = "storefront_digest"
cookieProperties[.value] = "<the digest>"
cookieProperties[.secure] = true
cookieProperties[.expires] = Date().addingTimeInterval(31536000)

if let cookie = HTTPCookie(properties: cookieProperties) {
    cookieStore.setCookie(cookie) {
        print("Cookie added")
    }
}

Somewhere in your app. I just tried it in AppDelegate.swift in the MobileBuyIntegration sample

Replace the domain with your test shop's domain, and <the digest> with the digest for that store. You can grab the value out of a desktop session by entering the password and checking the cookie value via chrome dev tools > application tab > cookies.

allyshiasewdat commented 4 months ago

Closing this based on @kiftio's response above.