Skip to content

Commit 15ad9a4

Browse files
jaynewstrom-stripeamk-stripe
authored andcommitted
Update checkout session flow when state is set. (#13174)
1 parent ad60e01 commit 15ad9a4

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

paymentsheet/src/main/java/com/stripe/android/checkout/Checkout.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ class Checkout private constructor(
150150
set(value) {
151151
ensureNoMutationInFlight()
152152
internalState = value.internalState
153+
_checkoutSession.value = internalState.checkoutSessionResponse.asCheckoutSession()
153154
}
154155

155156
private val mutex = Mutex()

paymentsheet/src/test/java/com/stripe/android/checkout/CheckoutTest.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -776,6 +776,18 @@ class CheckoutTest {
776776
deferred.await()
777777
}
778778

779+
@Test
780+
fun `setting state updates checkoutSession flow`() = runCreateWithStateScenario {
781+
val initial = checkoutSessionTurbine.awaitItem()
782+
assertThat(initial.id).isEqualTo(DEFAULT_CHECKOUT_SESSION_ID)
783+
784+
val updatedResponse = CheckoutSessionResponseFactory.create(id = "cs_test_updated")
785+
checkout.state = CheckoutStateFactory.create(checkoutSessionResponse = updatedResponse)
786+
787+
val updated = checkoutSessionTurbine.awaitItem()
788+
assertThat(updated.id).isEqualTo("cs_test_updated")
789+
}
790+
779791
@Test
780792
fun `mutation returns failure when integrationLaunched is true`() = runCreateWithStateScenario(
781793
shouldValidateEvents = false,

0 commit comments

Comments
 (0)