Skip to content

[Swift] Restore CheckoutDelegate with trimmed lifecycle API#131

Merged
tiagocandido merged 1 commit into
mainfrom
05-15-restore_checkoutdelegate_with_trimmed_lifecycle_api
May 19, 2026
Merged

[Swift] Restore CheckoutDelegate with trimmed lifecycle API#131
tiagocandido merged 1 commit into
mainfrom
05-15-restore_checkoutdelegate_with_trimmed_lifecycle_api

Conversation

@tiagocandido
Copy link
Copy Markdown
Contributor

@tiagocandido tiagocandido commented May 15, 2026

What changes are you making?

Restores the CheckoutDelegate protocol on iOS for host-level lifecycle callbacks, trimmed to:

  • checkoutDidCancel()
  • checkoutDidFail(error:)

CheckoutDelegate covers lifecycle outcomes the host app needs to react to (cancel, fail). Completion and link clicks are delivered through the protocol client (CheckoutProtocol.complete, ec.window.open_request), so they're not part of this surface. Recovery is decided internally using CheckoutError.isRecoverable, and checkoutDidFail(error:) only fires once the SDK has given up recovering — not on each intermediate failure.

UIKit consumers can now observe cancel/fail by passing a delegate to ShopifyCheckoutKit.present(checkout:from:delegate:client:). SwiftUI still uses .onCancel/.onFail; there's no .delegate(_:) modifier — SwiftUI structs can't hold a weak delegate reliably across recreations.

How to test

  • Build the sample app, present checkout, verify the delegate fires on cancel and on an induced failure

Before you merge

Important

  • I've added tests to support my implementation
  • I have read and agree with the Contribution Guidelines
  • I have read and agree with the Code of Conduct
  • I've updated the relevant platform README (`platforms/swift/README.md` and/or `platforms/android/README.md`)

Copy link
Copy Markdown
Contributor Author

tiagocandido commented May 15, 2026

@tiagocandido tiagocandido changed the title Restore CheckoutDelegate with trimmed lifecycle API [Swift] Restore CheckoutDelegate with trimmed lifecycle API May 15, 2026
@tiagocandido tiagocandido force-pushed the 05-15-restore_checkoutdelegate_with_trimmed_lifecycle_api branch from d27977c to 7dceb15 Compare May 15, 2026 14:50
@tiagocandido tiagocandido added the #gsd:50662 Rebase Checkout Kit on UCP label May 15, 2026 — with Graphite App
@tiagocandido tiagocandido force-pushed the 05-15-restore_checkoutdelegate_with_trimmed_lifecycle_api branch from 7dceb15 to 86ecd8b Compare May 15, 2026 16:07
@tiagocandido tiagocandido marked this pull request as ready for review May 15, 2026 16:15
@tiagocandido tiagocandido requested a review from a team as a code owner May 15, 2026 16:15
@tiagocandido tiagocandido force-pushed the 05-15-restore_checkoutdelegate_with_trimmed_lifecycle_api branch from 86ecd8b to 9aa6c02 Compare May 15, 2026 16:46
Comment thread platforms/swift/Sources/ShopifyCheckoutKit/CheckoutWebView.swift Outdated
@tiagocandido tiagocandido changed the base branch from kieran-osgood/05-14-featremovecheckoutlifecyclefromreact-native to graphite-base/131 May 18, 2026 09:42
@tiagocandido tiagocandido force-pushed the 05-15-restore_checkoutdelegate_with_trimmed_lifecycle_api branch from 9aa6c02 to b4e5670 Compare May 18, 2026 09:42
@tiagocandido tiagocandido changed the base branch from graphite-base/131 to main May 18, 2026 09:42
Comment thread platforms/swift/README.md
}
}
```
External links opened from within checkout (HTTPS, deep links, `mailto:`, `tel:`) are forwarded to `UIApplication.shared.open(_:)` by the kit, so universal links and Offsite Payments redirects route back to your app automatically once the rest of the universal-links setup is in place.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will likely need to test this a bit more I just wanted to note that for our tracking

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Acked — agreed the universal-links / offsite payments path still needs end-to-end coverage. Tracking that separately, not in this PR.

let id = orderId ?? ""
let orderJson = orderId.map { ",\"order\":{\"id\":\"\($0)\"}" } ?? ""
return "{\"jsonrpc\":\"2.0\",\"method\":\"ec.complete\","
+ "\"params\":{\"id\":\"\(id)\",\"currency\":\"\",\"line_items\":[],\"links\":[],"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CheckoutWebView.swift builds the synthetic ec.complete as params: { id, currency, ... }, but the Swift protocol decoder only dispatches checkout notifications when the payload is nested at params.checkout (Codec.swift). As written, client.process(message) decodes this as .unknown, so .on(CheckoutProtocol.complete) handlers never fire in the recovery confirmation path.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch — that was the actual bug, decoder was hitting .unknown and dropping completion in recovery. Construction now lives in CheckoutProtocol.encodeRecoveryCompleteNotification(orderId:) which nests under params.checkout. Added round-trip tests on both encode and dispatch.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update: helper is gone, your params.checkout catch is now moot for this PR. Keeping the note for when synthesis comes back properly — the bug would have shipped without it.

@tiagocandido tiagocandido force-pushed the 05-15-restore_checkoutdelegate_with_trimmed_lifecycle_api branch from b4e5670 to b578111 Compare May 18, 2026 15:51
Copy link
Copy Markdown
Contributor

@kieran-osgood-shopify kieran-osgood-shopify left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The delegate changes look good for cancel and fail
I think the recovery mode changes can be trimmed back at this point?

@tiagocandido tiagocandido force-pushed the 05-15-restore_checkoutdelegate_with_trimmed_lifecycle_api branch from b578111 to dfa64f0 Compare May 19, 2026 11:09
@tiagocandido tiagocandido force-pushed the 05-15-restore_checkoutdelegate_with_trimmed_lifecycle_api branch from dfa64f0 to 4037fe6 Compare May 19, 2026 12:47
Comment thread platforms/swift/README.md

1. The checkout experience may look different to buyers. Though the kit will attempt to load any checkout customizations for the storefront, there is no guarantee they will show in recovery mode.
2. The `checkoutDidComplete(event:)` will be emitted with partial data. Invocations will only receive the order ID via `event.orderDetails.id`.
2. Completion events delivered via `CheckoutProtocol.complete` during recovery may contain partial data — typically only the order ID.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Recovery completion events are not emitted. This should be updated.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@tiagocandido tiagocandido force-pushed the 05-15-restore_checkoutdelegate_with_trimmed_lifecycle_api branch from 4037fe6 to 623b169 Compare May 19, 2026 14:02
@tiagocandido tiagocandido force-pushed the 05-15-restore_checkoutdelegate_with_trimmed_lifecycle_api branch from 623b169 to 70531ba Compare May 19, 2026 14:29
@tiagocandido tiagocandido merged commit 43837e4 into main May 19, 2026
20 checks passed
@tiagocandido tiagocandido deleted the 05-15-restore_checkoutdelegate_with_trimmed_lifecycle_api branch May 19, 2026 14:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

#gsd:50662 Rebase Checkout Kit on UCP

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants