Skip to content

Prototype: Redesign CheckoutInstances registry#13264

Closed
cttsai-stripe wants to merge 6 commits into
masterfrom
cttsai/checkout-instances-redesign
Closed

Prototype: Redesign CheckoutInstances registry#13264
cttsai-stripe wants to merge 6 commits into
masterfrom
cttsai/checkout-instances-redesign

Conversation

@cttsai-stripe

@cttsai-stripe cttsai-stripe commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Summary

Simplifies CheckoutInstances before more checkout session code depends on it.

What changed:

  • Replace MutableList<WeakReference<Checkout>> with a single strong reference per key
  • Remove self-registration from Checkout.init; registration is now SDK-managed at configureWithCheckout / EmbeddedPaymentElement.configure entry points
  • Unregistration at integration teardown (FlowController's onDestroy, Embedded's onCleared)
  • Sub-Activities call markIntegrationDismissed() on dismiss but do not unregister
  • Remove dead CheckoutCurrencyUpdater code

Why:

  • Every new call site currently has to choose between .firstOrNull() and .forEach on the list. The list is not a valid state; it's a lifecycle gap from createWithState() producing same-key objects.
  • Lifecycle is implicit (register on init, never unregister, depend on GC). Explicit register/unregister is simpler to reason about.
  • Not fixing bugs today. Simplifying the pattern before more code depends on it.

Design doc: https://docs.google.com/document/d/1pvw4EGCdEkBjpCIBQ64CpDXge6N78W74YSBQg_dg5RQ

Status

This is a prototype PR. Missing integration-level tests (reconfigure with different key, FlowController multi-step lifecycle).

Test plan

  • CheckoutInstancesTest rewritten and passing
  • All 5,544 paymentsheet unit tests pass
  • Integration tests for reconfigure-with-different-key
  • Integration tests for FlowController multi-step lifecycle

🤖 Generated with Claude Code

cttsai-stripe and others added 6 commits June 17, 2026 21:51
…oped registration

Replace WeakReference list-based registry with a strong-reference, single-instance-per-key
design. Registration is now SDK-managed at configure/present entry points with unregistration
at integration teardown. No merchant-facing cleanup required.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Committed-By-Agent: claude
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Committed-By-Agent: claude
…tances-redesign

Committed-By-Agent: claude

# Conflicts:
#	paymentsheet/src/main/java/com/stripe/android/paymentsheet/PaymentSheet.kt
presentWithCheckout was removed from master; no one registers
for PaymentSheet anymore, so onDestroy unregistration is dead.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Committed-By-Agent: claude
register() now takes an owner string. Same Checkout registered by a
different owner throws, catching the integration error where one Checkout
is configured into two live integrations simultaneously.

Also adds @mainthread annotations and removes orphaned
FakeCheckoutCurrencyUpdater.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Committed-By-Agent: claude
Callers pass `this` as the owner. Two different integration instances
registering the same Checkout throw based on object identity, not
string comparison.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Committed-By-Agent: claude
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant