Pending Checkout + Order History
core/services/local_storage.dart · pending checkout + order history
Overview
SharedPreferences slice for recovery: savePendingCheckout (after backend cart creation), clearPendingCheckout (on success), addOrderToHistory (after completeCart). Lets the app reopen a half-finished checkout when relaunched mid-payment.
User Flow
- After initCheckout: savePendingCheckout(cartId, selectedVariantIds).
- After successful completeCart: addOrderToHistory(cartId) and clearPendingCheckout.
- Order history is read by the orders feature to render the user's purchase list independent of backend availability.
Cases & Edge Cases
- If the app dies between createPaymentSession and presentPaymentSheet, the saved pending-checkout lets us resume on next launch — but only if the backend cart hasn't been cleaned up server-side.
- addOrderToHistory only stores the cart/order id; full order data is re-fetched via OrderService on demand.
- Multiple pending checkouts overwrite each other — the implementation is single-slot.
Code References
- lib/src/core/services/local_storage.dart // savePendingCheckout / clearPendingCheckout / addOrderToHistory
- lib/src/features/shared/checkout/controllers/checkout_controller.dart:57 // savePendingCheckout
- lib/src/features/shared/checkout/controllers/checkout_controller.dart:393 // addOrderToHistory
API Calls
Notes
Multi-cart resume is not supported by design — assumption is the user finishes (or abandons) one checkout at a time. Local storage contracts (SharedPreferences — no HTTP): • savePendingCheckout({ cartId, selectedVariantIds }) — write keys 'pending_checkout_cart_id' + 'pending_checkout_variant_ids' — screen: lib/src/features/shared/checkout/views/checkout_screen.dart (after initCheckout creates the backend cart) • clearPendingCheckout() — remove keys — screen: checkout_screen.dart (post-completeCart success) • addOrderToHistory(cartOrOrderId) — append to 'order_history' list — screen: checkout_screen.dart (after completeCart) — consumed by lib/src/features/shared/orders/views/orders_screen.dart for offline fallback