Skip to content

Commit c874fb0

Browse files
authored
Fix PaymentSelection being null on errors for wallets. (#10544)
1 parent 86692c8 commit c874fb0

File tree

2 files changed

+103
-1
lines changed

2 files changed

+103
-1
lines changed

paymentsheet/src/main/java/com/stripe/android/paymentsheet/PaymentSheetViewModel.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ internal class PaymentSheetViewModel @Inject internal constructor(
502502
message: ResolvableString
503503
) {
504504
eventReporter.onPaymentFailure(
505-
paymentSelection = selection.value,
505+
paymentSelection = inProgressSelection,
506506
error = error,
507507
)
508508

paymentsheet/src/test/java/com/stripe/android/paymentsheet/PaymentSheetViewModelTest.kt

+102
Original file line numberDiff line numberDiff line change
@@ -1167,6 +1167,7 @@ internal class PaymentSheetViewModelTest {
11671167
val error = APIException()
11681168

11691169
viewModel.updateSelection(selection)
1170+
viewModel.checkout()
11701171

11711172
viewModel.paymentMethodMetadata.test {
11721173
confirmationHandler.state.value = ConfirmationHandler.State.Complete(
@@ -2596,6 +2597,37 @@ internal class PaymentSheetViewModelTest {
25962597
assertThat(paymentSuccessCall.paymentSelection).isEqualTo(PaymentSelection.GooglePay)
25972598
}
25982599

2600+
@Test
2601+
fun `On checkout with Google Pay, should report failure as expected`() = runTest {
2602+
val confirmationHandler = FakeConfirmationHandler().apply {
2603+
awaitResultTurbine.add(null)
2604+
awaitResultTurbine.add(null)
2605+
}
2606+
val eventReporter = FakeEventReporter()
2607+
val viewModel = createViewModel(
2608+
args = ARGS_CUSTOMER_WITH_GOOGLEPAY,
2609+
isGooglePayReady = true,
2610+
eventReporter = eventReporter,
2611+
confirmationHandlerFactory = {
2612+
confirmationHandler
2613+
}
2614+
)
2615+
2616+
viewModel.checkoutWithGooglePay()
2617+
2618+
confirmationHandler.state.value = ConfirmationHandler.State.Complete(
2619+
ConfirmationHandler.Result.Failed(
2620+
cause = IllegalStateException("This failed!"),
2621+
message = "This failed".resolvableString,
2622+
type = ConfirmationHandler.Result.Failed.ErrorType.GooglePay(errorCode = 10),
2623+
)
2624+
)
2625+
2626+
val paymentFailureCall = eventReporter.paymentFailureCalls.awaitItem()
2627+
2628+
assertThat(paymentFailureCall.paymentSelection).isEqualTo(PaymentSelection.GooglePay)
2629+
}
2630+
25992631
@Test
26002632
fun `On checkout with Link, should report success as expected`() = runTest {
26012633
val confirmationHandler = FakeConfirmationHandler().apply {
@@ -2630,6 +2662,41 @@ internal class PaymentSheetViewModelTest {
26302662
assertThat(paymentSuccessCall.paymentSelection).isEqualTo(PaymentSelection.Link(useLinkExpress = false))
26312663
}
26322664

2665+
@Test
2666+
fun `On checkout with Link, should report failure as expected`() = runTest {
2667+
val confirmationHandler = FakeConfirmationHandler().apply {
2668+
awaitResultTurbine.add(null)
2669+
awaitResultTurbine.add(null)
2670+
}
2671+
val eventReporter = FakeEventReporter()
2672+
val viewModel = createViewModel(
2673+
args = ARGS_CUSTOMER_WITH_GOOGLEPAY,
2674+
linkState = LinkState(
2675+
configuration = LINK_CONFIG,
2676+
loginState = LinkState.LoginState.LoggedOut,
2677+
signupMode = null
2678+
),
2679+
eventReporter = eventReporter,
2680+
confirmationHandlerFactory = {
2681+
confirmationHandler
2682+
}
2683+
)
2684+
2685+
viewModel.checkoutWithLink()
2686+
2687+
confirmationHandler.state.value = ConfirmationHandler.State.Complete(
2688+
ConfirmationHandler.Result.Failed(
2689+
cause = IllegalStateException("This failed!"),
2690+
message = "This failed".resolvableString,
2691+
type = ConfirmationHandler.Result.Failed.ErrorType.GooglePay(errorCode = 10),
2692+
)
2693+
)
2694+
2695+
val paymentFailureCall = eventReporter.paymentFailureCalls.awaitItem()
2696+
2697+
assertThat(paymentFailureCall.paymentSelection).isEqualTo(PaymentSelection.Link(useLinkExpress = false))
2698+
}
2699+
26332700
@Test
26342701
fun `On checkout with Link Express, should report success as expected`() = runTest {
26352702
val confirmationHandler = FakeConfirmationHandler().apply {
@@ -2664,6 +2731,41 @@ internal class PaymentSheetViewModelTest {
26642731
assertThat(paymentSuccessCall.paymentSelection).isEqualTo(PaymentSelection.Link(useLinkExpress = true))
26652732
}
26662733

2734+
@Test
2735+
fun `On checkout with Link Express, should report failure as expected`() = runTest {
2736+
val confirmationHandler = FakeConfirmationHandler().apply {
2737+
awaitResultTurbine.add(null)
2738+
awaitResultTurbine.add(null)
2739+
}
2740+
val eventReporter = FakeEventReporter()
2741+
2742+
createViewModel(
2743+
args = ARGS_CUSTOMER_WITH_GOOGLEPAY,
2744+
linkState = LinkState(
2745+
configuration = LINK_CONFIG,
2746+
loginState = LinkState.LoginState.LoggedIn,
2747+
signupMode = null
2748+
),
2749+
linkConfigurationCoordinator = FakeLinkConfigurationCoordinator(),
2750+
eventReporter = eventReporter,
2751+
confirmationHandlerFactory = {
2752+
confirmationHandler
2753+
}
2754+
)
2755+
2756+
confirmationHandler.state.value = ConfirmationHandler.State.Complete(
2757+
ConfirmationHandler.Result.Failed(
2758+
cause = IllegalStateException("This failed!"),
2759+
message = "This failed".resolvableString,
2760+
type = ConfirmationHandler.Result.Failed.ErrorType.GooglePay(errorCode = 10),
2761+
)
2762+
)
2763+
2764+
val paymentFailureCall = eventReporter.paymentFailureCalls.awaitItem()
2765+
2766+
assertThat(paymentFailureCall.paymentSelection).isEqualTo(PaymentSelection.Link(useLinkExpress = true))
2767+
}
2768+
26672769
@Test
26682770
fun `Can complete payment after switching to another LPM from card selection with inline Link signup state`() =
26692771
runTest {

0 commit comments

Comments
 (0)