Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep reference to pending payment result #7704

Merged

Conversation

tillh-stripe
Copy link
Collaborator

@tillh-stripe tillh-stripe commented Dec 5, 2023

Summary

This pull request makes a first improvement to how we handle process death during the auth flow, with more improvements such as full state restoration still to come.

In the case of process death, the paymentLauncher used in PaymentSheetViewModel will return an InternalPaymentResult upon process recreation. However, the ViewModel is not yet in the correct state to handle this, as it hasn’t reloaded the StripeIntent. The requireNotNull(stripeIntent.value) will throw.

With this change, we’re delaying the handling of the InternalPaymentResult until the intent has been loaded again. If the intent has been confirmed by the user, then loading the intent will fail with a PaymentIntentInTerminalState exception. This is where we intercept: Instead of returning a fatal error to the caller, we handle the completed payment and return a PaymentResult.Completed.

Due to how PaymentLauncher works, this is unfortunately very difficult to test 😔

Motivation

Resolves #7590

Testing

  • Added tests
  • Modified tests
  • Manually verified

Screenshots

Before After
before screenshot after screenshot

Changelog

@tillh-stripe tillh-stripe force-pushed the tillh/7590-3ds-not-working-when-activity-gets-recreated branch from 67cfa84 to a3799dc Compare December 5, 2023 18:00
@tillh-stripe tillh-stripe marked this pull request as ready for review December 6, 2023 16:30
@tillh-stripe tillh-stripe requested review from a team as code owners December 6, 2023 16:30
samer-stripe
samer-stripe previously approved these changes Dec 7, 2023
Copy link
Collaborator

@jaynewstrom-stripe jaynewstrom-stripe left a comment

Choose a reason for hiding this comment

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

A few comments that could maybe improve things, but nothing blocking.

)
}

private fun handlePaymentSheetStateLoadFailure(error: Throwable) {
val pendingResult = pendingPaymentResult
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we need to set pendingPaymentResult to null after this? Or do we just assume the view model will go away?

if (intent == null) {
// We're recovering from process death. Wait for the pending payment result
// to be handled after re-loading.
pendingPaymentResult = launcherResult
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should this live in the view model? Seems like we could model this to be opaque to the view model.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Will follow up with a better abstraction.

@tillh-stripe tillh-stripe merged commit 9ef33fa into master Dec 8, 2023
8 checks passed
@tillh-stripe tillh-stripe deleted the tillh/7590-3ds-not-working-when-activity-gets-recreated branch December 8, 2023 18:48
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.

[BUG] 3DS not working when activity gets re-created
3 participants