Flutter UI Walkthrough — Payment Method & Razorpay Payment Flow
Where this flow starts
At the bottom of the Checkout screen (or Buy Now Checkout’s identical bottom section) sits a Payment Method card — Online Payment (“Pay via UPI, Credit/Debit Card, Netbanking, or Wallets”) vs. Cash on Delivery (“Pay with cash when your package arrives”) — and a sticky bottom bar with the Payable Amount and a Place Order & Pay button. Switching methods re-queries the server for a fresh price, since Cash on Delivery can add its own surcharge; that live recalculation is covered in the Checkout screen’s own doc.
Tapping Place Order & Pay is a real, immediate call, not a local stub: CheckoutController.placeOrder() calls orderService.placeOrder(...), a genuine POST /api/v1/order against order-service. That request schedules order-service’s checkout saga (a Temporal workflow) and returns as soon as the order record and saga are created — it does not wait for payment, inventory, or shipment to resolve inline. Neither payment method opens a gateway from Checkout itself: on a successful order-creation response, the controller immediately pushes (not replaces) the Payment Processing screen — Get.toNamed(AppRoutes.paymentProcessing, parameters: {orderId, sagaOrderId}, arguments: {contactPhone, isBuyNow, pendingOrder}) — carrying the shipping phone number and the client-side order snapshot forward. It’s pushed rather than used to replace Checkout specifically so a failed payment can fall back to the still-alive Checkout screen behind it. Today there’s no separate code path for Cash on Delivery visible in Checkout itself — both methods route through this same Payment Processing hand-off, which is where the rest of this doc picks up.

What the shopper sees
Three layers, in sequence:
- A full-screen processing status card with no visible gateway yet — the screen is waiting on the backend, and back-navigation is blocked while it does.
- Razorpay’s own hosted checkout UI, opened automatically once the backend is ready: a Payment Options sheet (Cards / Netbanking / Wallet, “Secured by Razorpay”, the amount, and Continue), then card entry with a “Save your card as per RBI guidelines?” prompt, then a “Waiting for OTP from bank” screen with an auto-detecting OTP field and a countdown timeout.
- After Razorpay reports success, the screen returns to the same processing status card — it waits again before moving on, rather than treating the gateway’s success as the order being finished.
What the shopper does here
- Waits, invisibly, while the app is still preparing the payment order (nothing to tap yet).
- Inside Razorpay’s own UI: picks Cards, Netbanking, or Wallet; enters card details and optionally saves the card; enters (or lets the app auto-detect) the bank’s OTP.
- If the gateway reports a failure, the shopper sees a Retry button, which reopens the same payment order rather than starting over from Checkout.
How it’s built
Nothing here is hardcoded or client-chosen — every Razorpay credential comes off one server-pushed event. PaymentProcessingController._waitForPaymentReady() opens a Server-Sent-Events subscription (OrderStreamService, wrapping order-service’s GET /order/api/v1/order/:id/stream) and waits up to 30 seconds for a payment_ready event — pushed once order-service’s saga has actually called payment-service’s CreatePaymentOrder activity and gotten back a real Razorpay order. _openGateway() reads razorpay_order_id, razorpay_key_id, amount, and currency straight out of that event’s payload.
Razorpay’s checkout UI is the Razorpay Flutter SDK’s own screens, not this app’s. PaymentService (core/services/payment_service.dart) is the one place Razorpay() is instantiated and .open(options) is called — everything shown in Payment Options, card entry, and the bank-OTP screen belongs to the razorpay_flutter package, not to a View/Controller this app owns.
A gateway failure and a wallet payment are currently handled identically. EVENT_PAYMENT_SUCCESS, EVENT_PAYMENT_ERROR, and EVENT_EXTERNAL_WALLET all resolve the same outcome future; anything other than success — including a completed external-wallet payment — surfaces as a retryable failure today, with no distinct “paid via wallet” success path yet.
A client-side Razorpay success does not mean the order is done. On success, the controller caches the local order snapshot and clears the cart, but stays connected to the same SSE subscription — waiting up to 90 seconds for either shipment_created (the saga completed — proceed to confirmation) or saga_failed (the charge was captured but something broke afterward; shown as non-retryable, since retrying risks a second charge). The code’s own reasoning: Razorpay’s client callback only confirms the gateway accepted the charge, not that the saga has recorded payment_captured and created the shipment. If neither event arrives in time, the screen switches to a “taking longer than usual — we’ll update it automatically” state and keeps listening on the same connection rather than guessing an outcome.



Related Documents
- BRD-015 — Payment Capture & Confirmation
- SR-016 — Payment Capture & Confirmation System Requirements — real payment-order creation (FR-01), signature-verified webhook capture (FR-02), captured-only saga relay (FR-03)
- BRD-013 — Checkout Completion: Real Payment Capture and Reliable Fulfillment Handoff
- SR-014 — Checkout Completion: Payment Capture & Fulfillment Handoff System Requirements — the saga scheduled on order creation (FR-01)
- payment-service
- order-service
- See also: Checkout, Buy Now Checkout
- Previous: Checkout
- Next: Order Confirmation