Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ internal class CheckoutConfirmationResultHandler @Inject constructor(
onSucceeded: suspend (CheckoutSessionResponse?) -> Unit,
) {
// Synchronous confirmation carries the latest response. Next-action confirmation does not,
// so the controller retrieves the completed Checkout Session before delivering the result.
// so the controller retrieves the completed Checkout Session before clearing its state.
onSucceeded(result.metadata[CheckoutSessionResponseKey])
resultCallback.onResult(CheckoutController.Result.Completed())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ class CheckoutController @Inject internal constructor(
}

/**
* The latest [Session] data, or `null` until [configure] has completed successfully.
* The latest [Session] data, or `null` until [configure] completes successfully and after a
* payment flow completes.
*/
val session: StateFlow<Session?>
get() = stateHolder.session
Expand Down Expand Up @@ -303,6 +304,7 @@ class CheckoutController @Inject internal constructor(
) {
runSerialized {
confirmationStateUpdater.update(checkoutSessionResponse)
stateHolder.state = null
kotlin.Result.success(Unit)
}
}
Expand Down Expand Up @@ -1006,7 +1008,8 @@ class CheckoutController @Inject internal constructor(
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
sealed interface Result {
/**
* The customer completed the payment flow.
* The customer completed the payment flow. The controller's loaded [session] is cleared
* before this result is delivered.
*/
@CheckoutSessionPreview
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1024,7 +1024,7 @@ internal class CheckoutControllerTest {
}

@Test
fun `successful confirmation waits for an in-flight mutation then refreshes state`() =
fun `successful confirmation waits for an in-flight mutation then clears state`() =
runMutationScenario(assertLoadingConsumed = true) {
val holdMutation = CountDownLatch(1)
networkRule.checkoutUpdate(
Expand Down Expand Up @@ -1056,8 +1056,8 @@ internal class CheckoutControllerTest {
confirmation.await()

assertThat(isUpdatingTurbine.awaitItem()).isFalse()
assertThat(committedState().checkoutSessionResponse).isEqualTo(confirmedResponse)
assertThat(controller.session.value).isNotNull()
assertThat(committedStateOrNull()).isNull()
assertThat(controller.session.value).isNull()
}

@Test
Expand Down