fooddelivery: actually show the order confirmation after payment
- Commit
fd1bb201963e86006f6be102df373f01ab6fbd6a- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-07 20:01 UTC (29 days ago)
- Parents
3b77aca
Symptom: after a successful Stripe payment the user landed straight on the Orders tab and never saw the 'Order placed!' confirmation, even though a CheckoutSuccess screen exists for exactly that. Root cause: the PaymentSheet Completed callback set orderSuccess=true and immediately called onOrderPlaced(), whose MainActivity implementation cleared the cart and reset the back stack in the same pass -- the Checkout route (and its success state) was destroyed before the confirmation could render. CheckoutSuccess also had no way forward of its own. Fix: split clearing from leaving. A new onOrderCompleted (defaulting to onOrderPlaced) clears the cart at payment time, so a paid cart can never be paid twice from the back stack, while onOrderPlaced now only navigates and is invoked by the confirmation's new 'View orders' button. Callers passing only onOrderPlaced see no change. Verification: new FoodUiComposeTest.checkoutSuccessContinueFires renders the confirmation and clicks through; full module test run follows in the final verification.
Diff
fooddelivery/src/main/java/com/vayunmathur/fooddelivery/MainActivity.kt
diff --git a/fooddelivery/src/main/java/com/vayunmathur/fooddelivery/MainActivity.kt b/fooddelivery/src/main/java/com/vayunmathur/fooddelivery/MainActivity.ktindex f2af6b4ceb..c8c3dd0fd8 100644--- a/fooddelivery/src/main/java/com/vayunmathur/fooddelivery/MainActivity.kt+++ b/fooddelivery/src/main/java/com/vayunmathur/fooddelivery/MainActivity.kt@@ -273,9 +273,11 @@ private fun FoodDeliveryApp( items = cart, onBack = { backStack.pop() }, onOrderPlaced = {+ backStack.reset(Route.Main(initialTab = 3))+ },+ onOrderCompleted = { cart.clear() CartStore.clear(context)- backStack.reset(Route.Main(initialTab = 3)) }, ) }
fooddelivery/src/main/java/com/vayunmathur/fooddelivery/ui/CheckoutScreen.kt
diff --git a/fooddelivery/src/main/java/com/vayunmathur/fooddelivery/ui/CheckoutScreen.kt b/fooddelivery/src/main/java/com/vayunmathur/fooddelivery/ui/CheckoutScreen.ktindex 64b2b31ac0..c79eb17889 100644--- a/fooddelivery/src/main/java/com/vayunmathur/fooddelivery/ui/CheckoutScreen.kt+++ b/fooddelivery/src/main/java/com/vayunmathur/fooddelivery/ui/CheckoutScreen.kt@@ -60,6 +60,10 @@ fun CheckoutScreen( items: List<CartItem>, onBack: () -> Unit, onOrderPlaced: () -> Unit,+ // Payment has succeeded: clear the cart, but stay here so the confirmation+ // is actually seen. Defaults to onOrderPlaced for callers that want the old+ // navigate-away-immediately behaviour.+ onOrderCompleted: () -> Unit = onOrderPlaced, ) { val context = LocalContext.current @@ -225,7 +229,10 @@ fun CheckoutScreen( is PaymentSheetResult.Completed -> { orderSuccess = true OrderTrackingService.start(context, checkoutResponse?.order?.id)- onOrderPlaced()+ // Clear the cart now (a paid cart must not be payable again from+ // the back stack), but do not navigate yet: leaving here is what+ // the confirmation's button does, via onOrderPlaced.+ onOrderCompleted() } is PaymentSheetResult.Canceled -> { paying = false@@ -238,7 +245,7 @@ fun CheckoutScreen( } if (orderSuccess) {- CheckoutSuccess()+ CheckoutSuccess(onContinue = onOrderPlaced) return }
fooddelivery/src/main/java/com/vayunmathur/fooddelivery/ui/CheckoutSuccess.kt
diff --git a/fooddelivery/src/main/java/com/vayunmathur/fooddelivery/ui/CheckoutSuccess.kt b/fooddelivery/src/main/java/com/vayunmathur/fooddelivery/ui/CheckoutSuccess.ktindex a8c06cc59c..71540558c6 100644--- a/fooddelivery/src/main/java/com/vayunmathur/fooddelivery/ui/CheckoutSuccess.kt+++ b/fooddelivery/src/main/java/com/vayunmathur/fooddelivery/ui/CheckoutSuccess.kt@@ -15,13 +15,14 @@ import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.unit.dp import com.vayunmathur.fooddelivery.R import com.vayunmathur.library.ui.AppScaffold+import com.vayunmathur.library.ui.Button import com.vayunmathur.library.ui.IconCheck import com.vayunmathur.library.ui.MaterialTheme import com.vayunmathur.library.ui.Text import com.vayunmathur.library.ui.appBarScrollBehavior @Composable-internal fun CheckoutSuccess() {+internal fun CheckoutSuccess(onContinue: () -> Unit = {}) { AppScaffold( title = stringResource(R.string.order_confirmed), scrollBehavior = appBarScrollBehavior(),@@ -37,6 +38,8 @@ internal fun CheckoutSuccess() { Spacer(Modifier.height(8.dp)) Text(stringResource(R.string.your_order_is_being_prepared), style = MaterialTheme.typography.bodyMedium, color = MaterialTheme.colorScheme.onSurfaceVariant)+ Spacer(Modifier.height(24.dp))+ Button(onClick = onContinue) { Text(stringResource(R.string.view_orders)) } } } }
fooddelivery/src/main/res/values/strings.xml
diff --git a/fooddelivery/src/main/res/values/strings.xml b/fooddelivery/src/main/res/values/strings.xmlindex fbb477243b..1e370b688f 100644--- a/fooddelivery/src/main/res/values/strings.xml+++ b/fooddelivery/src/main/res/values/strings.xml@@ -4,6 +4,7 @@ <string name="order_confirmed">Order Confirmed</string> <string name="order_placed">Order placed!</string> <string name="your_order_is_being_prepared">Your order is being prepared.</string>+ <string name="view_orders">View orders</string> <string name="checkout">Checkout</string> <string name="order_summary">Order Summary</string> <string name="order_type">Order Type</string>
fooddelivery/src/test/java/com/vayunmathur/fooddelivery/ui/FoodUiComposeTest.kt
diff --git a/fooddelivery/src/test/java/com/vayunmathur/fooddelivery/ui/FoodUiComposeTest.kt b/fooddelivery/src/test/java/com/vayunmathur/fooddelivery/ui/FoodUiComposeTest.ktindex fd505da226..8bab83602b 100644--- a/fooddelivery/src/test/java/com/vayunmathur/fooddelivery/ui/FoodUiComposeTest.kt+++ b/fooddelivery/src/test/java/com/vayunmathur/fooddelivery/ui/FoodUiComposeTest.kt@@ -147,6 +147,12 @@ class FoodUiComposeTest { } rule.waitForIdle() }+ @Test fun checkoutSuccessContinueFires() {+ var continued = false+ rule.setContent { CheckoutSuccess(onContinue = { continued = true }) }+ rule.onNodeWithText("View orders").assertIsDisplayed().performClick()+ assertTrue(continued)+ } @Test fun emailVerificationStates() { var verified = false rule.setContent { EmailVerificationScreen("cust-1", "tok", { verified = true }) }