checkout-sheet-kit-swift icon indicating copy to clipboard operation
checkout-sheet-kit-swift copied to clipboard

Inconsistent Behavior in CheckoutDelegateWrapper Callbacks (onComplete, onCancel)

Open sumeyyekazanci opened this issue 1 year ago • 6 comments

What area is the issue related to?

Checkout Sheet Kit

What version of Checkout Sheet Kit are you using?

3.0.4-3.1.2

Reproducible sample code

No response

Steps to Reproduce

  • When the app state changes to inactive and then returns to the foreground, the onCancel callback does not get triggered.

  • iOS 17.0 onCancel never works

  • onComplete is not stable.

Expected Behavior

The onComplete, onCancel, and other related callbacks should trigger reliably when the associated events occur.

Actual Behavior

The Shopify Sheet Kit SDK does not work stably in certain scenarios, and specifically, callback functions such as onComplete and onCancel defined within the CheckoutDelegateWrapper behave inconsistently. This issue prevents users from receiving feedback during certain operations and causes problems in the application flow.

Screenshots/Videos/Log output

No response

Storefront domain

flyingtiger-tr.myshopify.com

sumeyyekazanci avatar Jan 09 '25 16:01 sumeyyekazanci

Hey @sumeyyekazanci, can you provide some sample code to demonstrate how you're using the kit?

Any videos or logs would also be helpful for us to debug.

markmur avatar Jan 13 '25 17:01 markmur

Here is some sample code if using SwiftUI to integrate → https://github.com/Shopify/checkout-sheet-kit-swift/blob/d319147ec5e4cb113f0b27a955aecd4b4d71fc19/Samples/SwiftUIExample/SwiftUIExample/CartView.swift#L63-L100

You can also configure the logLevel of the kit to .all to output more information.

ShopifyCheckoutSheetKit.configuration.logLevel = .all

markmur avatar Jan 13 '25 17:01 markmur

Hey I was also running into this issue. For me, the issue happened when the view hosting the CheckoutSheet updated. I think it's because the CheckoutWebViewController only has a weak ref to the delegate object. When the CheckoutSheet is updated, a new delegate is instantiated so the old one is deallocated. Setting a breakpoint here, delegate was nil. I guess you'd have to update the delegate somehow in updateUIViewController

I did a workaround by making the host view Equatable based off of url so that the CheckoutSheet doesn't update. That fixed the issue for me

randonnee avatar Jan 31 '25 02:01 randonnee

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs in 30 days. Thank you for your contributions.

github-actions[bot] avatar Mar 27 '25 03:03 github-actions[bot]

This issue has been automatically closed because it has not had recent activity. Please re-open it if it is still relevant.

github-actions[bot] avatar Apr 03 '25 03:04 github-actions[bot]

@randonnee @sumeyyekazanci - I have looked into this a bit today

Whilst I haven't been able to reproduce a case where the delegate goes to nil (if you are able to provide source code for a reproduction, I will look into it further), I have a PR here going along the lines you suggested @randonnee to ensure delegate is set when updateUIViewController is called.

If you fancy giving that a test and see if you still have any issues that'd be helpful before we look to merge.

On a related note, I have noticed that one of our samples /CartView.swift suggests using a sheet modifier to render the checkout sheet, and if the user were to swipe the sheet down the onCancel is never triggered, which may be a source of confusion.

    .sheet(isPresented: $isShowingCheckout) {
        if let url = CartManager.shared.cart?.checkoutUrl {
            let _ = print("[CartView] Creating CheckoutSheet with URL: \(url)")
            CheckoutSheet(checkout: url)
                .onCancel {
                    print("❌ CANCELLED")
                }
                .onComplete { _ in
                    print("✅ COMPLETE")
                }
                /// Configuration
                .title("SHEET")
        }
    }

kieran-osgood-shopify avatar May 09 '25 16:05 kieran-osgood-shopify

I've just merged the above patch and released v3.2.0 I'll close this issue for now as theres not been any activity, but get back to us if you find you're still having issue

kieran-osgood-shopify avatar Jun 20 '25 14:06 kieran-osgood-shopify