fix(android): forward stripeAccountId and catch errors in retrievePaymentIntent / retrieveSetupIntent#2403
Open
adityapsbisht wants to merge 2 commits into
Conversation
…mentIntent / retrieveSetupIntent Both @ReactMethod entry points were calling the 1-arg overload of Stripe#retrievePaymentIntentSynchronous / retrieveSetupIntentSynchronous, dropping the configured stripeAccountId. For connected-account intents this hits the platform account and the Stripe Android SDK throws InvalidRequestException ("No such payment_intent: 'pi_…'"). The call also ran inside CoroutineScope(Dispatchers.IO).launch { … } with no try/catch, so the exception escaped the coroutine as an uncaught error and crashed the app before the JS Promise could reject. The matching iOS implementation already forwards stripeAccountId and resolves errors via the Promise. Wrap both coroutine bodies in runCatching, pass stripeAccountId to the synchronous SDK calls, and resolve a structured error via createError(RetrievePaymentIntentErrorType.Unknown, …) / createError(RetrieveSetupIntentErrorType.Unknown, …) so the JS caller can handle it the same way as on iOS. Related: stripe#322 (closed without fix), likely stripe#1800. Made-with: Cursor
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.
Summary
On Android,
retrievePaymentIntentandretrieveSetupIntenthave two defects that together cause a hard, un-catchable app crash whenever the underlying PaymentIntent/SetupIntent belongs to a connected Stripe account:stripeAccountIdis not forwarded to the native call. Every other public API inStripeSdkModule.ktthat touches the Stripe Android SDK passesstripeAccountId(createCardTokenSynchronous,createPiiTokenSynchronous,createBankAccountTokenSynchronous, everyPaymentLauncherFragment.forXxx, and the module's own internal Google Pay path). ButretrievePaymentIntent/retrieveSetupIntentwere calling the 1-arg overloads:So the request hits the platform account rather than the connected account, and Stripe responds with
InvalidRequestException: No such payment_intent: 'pi_…'.The coroutine body is unguarded. The network call runs inside
CoroutineScope(Dispatchers.IO).launch { … }with notry/catch/runCatching, soInvalidRequestExceptionescapes the coroutine and becomes an uncaught exception. The app crashes before thePromiseis ever rejected, so a JS-sidetry/catcharoundretrievePaymentIntentcannot help.The matching iOS implementation already forwards
stripeAccountIdand resolves errors via thePromise— this PR brings Android behavior in line.Reproduction
client_secret.await retrievePaymentIntent(clientSecret)(even with a JStry/catch).iOS with the same client secret works correctly.
Fix
Two targeted changes to
android/src/main/java/com/reactnativestripesdk/StripeSdkModule.kt:stripeAccountIdtoretrievePaymentIntentSynchronous/retrieveSetupIntentSynchronous(the 2-arg overloads already exist onStripe).runCatching { … }.onFailure { … }and resolve the promise with a structured error viacreateError(RetrievePaymentIntentErrorType.Unknown, …)/createError(RetrieveSetupIntentErrorType.Unknown, …)— both enums already exist inutils/Errors.kt.Net diff: 20 insertions, 4 deletions, one file.
Impact
retrievePaymentIntent/retrieveSetupIntenton Android (PaymentSheet flows that need to re-read intent status post-confirmation, amount display after deep-linking back from SCA, etc.).Verified
v0.50.3throughv0.64.0(currentmaster) — the 1-arg overload has been used since the original implementation and was never updated alongside other native calls that adoptedstripeAccountId.stripeAccountIdis nullable and the 2-arg overload acceptsnull).Related
retrievePaymentIntent+ Custom Connect bug, reported in 2021, closed without a code fix.No such payment_intentmisdiagnosed as device-specific; almost certainly this same issue surfacing on devices that happen to exercise the connected-account path.Happy to add an e2e test if there's a reasonable way to set one up against
example-stripe-connect/— pointers welcome.Made with Cursor