Add StripeClient per-instance publishable key to EmbeddedPaymentElement 🪿✨#13303
Draft
tjclawson-stripe wants to merge 2 commits into
Draft
Conversation
…nt.configure() - Add StripeClient class (publishableKey + optional stripeAccountId, Parcelable) - Add StripeClientHolder @singleton to carry per-configure() StripeClient - Add StripeClientModule replacing PaymentConfigurationModule in EmbeddedCommonModule; falls back to PaymentConfiguration singleton when no StripeClient is set - Add optional stripeClient param to both EmbeddedPaymentElement.configure() overloads; writes to holder before delegating to coordinator - Add TODO comment in EmbeddedConfigurationHandler noting that the cache key does not yet incorporate stripeClient - Add StripeClientTest covering key validation and field defaults Committed-By-Agent: goose
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Minion run
Summary
Adds an optional
stripeClient: StripeClient?parameter to bothEmbeddedPaymentElement.configure()overloads, allowing each instance to supply its own publishable key instead of always reading from the globalPaymentConfigurationsingleton. WhenstripeClientisnull, behavior is unchanged.New classes introduced:
StripeClient— a@Parcelize @Pokovalue type holding apublishableKeyand optionalstripeAccountId, validated on construction.StripeClientHolder— a@SingletonDagger-injected holder whosestripeClientfield is written byconfigure()and read by the key-providing lambdas on every network request.StripeClientModule— a@Modulethat replacesPaymentConfigurationModulein the Embedded Dagger component only, sourcingPaymentConfiguration,@Named(PUBLISHABLE_KEY), and@Named(STRIPE_ACCOUNT_ID)from the holder with aPaymentConfiguration.getInstance()fallback.PaymentConfigurationModuleis left intact for PaymentSheet, CustomerSheet, and all other integrations.A TODO comment was added in
EmbeddedConfigurationHandlernoting that theArgumentscache key does not yet incorporatestripeClient, so callingconfigure()twice with the same intent/configuration but a differentstripeClientwill return the cached result from the first call.Motivation
EmbeddedPaymentElementcurrently reads its publishable key from the globalPaymentConfigurationsingleton, which prevents apps from using different keys for differentEmbeddedPaymentElementinstances (e.g. multi-merchant or connect scenarios). This change makes the key a per-configure()call concern while preserving full backwards compatibility for callers that don't pass aStripeClient.Because the Dagger component is constructed before
configure()is ever called,@BindsInstanceis not a viable approach. TheStripeClientHoldersingleton pattern allows the@Named(PUBLISHABLE_KEY)lambda — whichStripeApiRepositorycaptures as() -> Stringrather thanString— to read the current value fresh on every request.Testing
StripeClientTestcovers:pk_test_key is acceptedsk_throwsIllegalArgumentExceptionstripeAccountIdisnullby defaultstripeAccountIdis set correctly when providedScreenshots
N/A — no UI changes.
Changelog
[Added]
StripeClient— pass an optionalstripeClienttoEmbeddedPaymentElement.configure()to supply a per-instance publishable key instead of relying on the globalPaymentConfigurationsingleton.