Mobile Checkout Flow
Overview
This document details the complete user journey through the unified checkout system, including both reorder and order completion flows. The checkout system provides a seamless experience for patients to complete their medication orders with integrated payment processing.Flow Types
The mobile app supports two distinct checkout flows that converge into a unified checkout system:1. Reorder Flow
- Purpose: Create new order with health data collection
- Entry Point: Patient selects medications from previous orders
- Health Data: Weight, height, blood pressure collection required
- Order Type:
reorder_request
2. Order Completion Flow
- Purpose: Complete existing prescription from doctor
- Entry Point: Patient views prescription from clinical system
- Delivery Choice: ADHD Simple delivery vs Paper Script
- Order Type:
order_completion
Checkout Flow Diagram
Screen Flow Details
Unified Checkout Screens
All checkout flows converge at these shared screens:1. Delivery Address (/checkout/delivery-address)
- Purpose: Select or add delivery address
- Features:
- Load saved addresses from patient profile
- Add new address option
- Set default address
- Address validation
- Integration: Uses
usePatientAddresseshook
2. Delivery Preference (/checkout/delivery-preference)
- Purpose: Choose delivery method
- Options:
- Standard delivery (free for members)
- Express delivery (additional cost)
- Pickup locations (where available)
- Pricing: Dynamic pricing based on member status
3. Payment (/checkout/payment)
- Purpose: Select payment method and complete order
- Features:
- Saved payment methods
- Add new card with Stripe
- Order summary and total
- Final confirmation
4. Success (/checkout/success)
- Purpose: Order confirmation
- Features:
- Celebration animation
- Order number display
- Next steps information
- Return to orders button
Edge Functions (Backend Processing)
Payment Functions
create-setup-intent- Saves new payment cards securelyget-payment-methods- Retrieves saved payment methodscreate-payment-intent- Creates Stripe payments
Order Functions
submit-order- Creates/updates orders based on order_typeassign-order-number- Generates unique order numbersprocess-new-order- Extracts and processes health data
Webhook Functions
stripe-webhook-handler- Handles payment eventsupdate-order-payment- Updates payment status
Key Technical Features
Duplicate Prevention System
The webhook system includes intelligent duplicate prevention logic to handle cases where a prescription is created from a patient app request before the payment webhook processes:- Webhook checks for existing requests with the same payment intent ID
- Detects if prescription already created (
clinical_decision: "prescription_created") - Skips duplicate processing and updates payment status only
- Continues normal flow for genuinely new requests
Unified Checkout System
Both reorder and order completion flows converge at/checkout/ screens to eliminate code duplication while maintaining distinct business logic through the order_type parameter.
Payment Integration
- Stripe Elements: Secure card collection
- Saved Cards: Reuse payment methods
- Webhook Processing: Reliable payment confirmation
- Error Handling: Retry logic for failed payments
Offline Support
- Draft Orders: Created locally before submission
- Sync on Submit: Orders sync when internet available
- Local Storage: Payment methods cached locally
Error Handling
- Payment Failures: Clear error messages with retry options
- Network Issues: Graceful degradation with retry mechanisms
- Validation: Client and server-side validation
Order Status Flow
Customer-Facing Statuses
- Waiting for Review - Request with clinician
- Prescription Processing - Preparing prescription
- Approved - Prescription ready
- Awaiting Payment - Waiting for payment
- Processing - Preparing order
- Sent to Pharmacy - Forwarded to pharmacy
- Being Dispensed - Pharmacy preparing medication
- Packed - Order packed and ready
- Shipped - On the way
- Delivered - Order arrived
Security Considerations
Payment Security
- PCI Compliance: Stripe handles card data
- Tokenization: Cards stored as tokens
- 3D Secure: Additional authentication when required
Data Privacy
- Patient Data: Encrypted in transit and at rest
- Address Data: Isolated per patient
- Health Data: HIPAA-compliant handling
Authentication
- Session Management: Secure token-based auth
- Multi-factor: Optional 2FA support
- Rate Limiting: Protection against abuse
Performance Optimizations
Lazy Loading
- Payment forms loaded on demand
- Stripe Elements initialized when needed
- Images optimized and cached
Caching Strategy
- Payment methods cached locally
- Address data cached with sync
- Order history available offline
Network Optimization
- Minimal API calls during checkout
- Batch sync operations
- Retry logic for network failures