{"ok":true,"module":"module-4-payments","meta":{"title":"Module 4 — Payments (Razorpay)","moduleRegistryPrefix":"PY / EC","sourcePath":"reference/concept-platform/Platform pahse 3 mvp/Module 4","specStack":"healthcare_platform_api (FastAPI) + razorpay SDK","layers":5,"overallCompletionPct":76,"paymentPipeline":"payment_pending → Razorpay order → captured webhook → paid → fulfillment","integratedWith":"hospitalnode.in — catalog orders, lab bookings, appointments, ledger","updated":"June 2026"},"runtime":{"razorpayConfigured":false,"webhookSecretSet":false},"integration":{"layers":5,"completionPct":76,"liveLayers":3,"partialLayers":2,"gapLayers":0},"layers":[{"layer":1,"id":"razorpay-order-create","name":"Razorpay order creation (server amount)","status":"live","routes":[{"label":"Create Razorpay order","href":"/api/payments/razorpay/create-order","status":"live"},{"label":"Checkout","href":"/checkout","status":"live"},{"label":"Pay reserve","href":"/customer/pay-reserve","status":"live"},{"label":"Lab booking payment","href":"/api/lab-bookings","status":"live"},{"label":"Appointment payment","href":"/api/appointments","status":"partial"}],"gaps":["No separate payments table row per attempt (razorpay_order_id on catalog_orders only)","409 guard for non-payment_pending status — uses paid/confirmed check instead","Production merchant KYC + live keys go-live checklist","Razorpay Route / vendor split not on capture"]},{"layer":2,"id":"webhook-capture","name":"Webhook HMAC + idempotent capture","status":"live","routes":[{"label":"Razorpay webhook","href":"/api/payments/razorpay/webhook","status":"live"},{"label":"Webhook events store","href":"/api/payments/razorpay/webhook","status":"live"},{"label":"Payment ledger","href":"/api/payments/razorpay/webhook","status":"live"}],"gaps":["Public HTTPS webhook URL required in production (hospitalnode.in)","Dual path: client POST /api/payments/confirm also marks paid — spec prefers webhook-only canonical","Blockchain Write 3 on delivery+payment — planned (/blockchain)","Lab/appointment webhooks share one endpoint — partial routing"]},{"layer":3,"id":"payment-history","name":"Payment attempt history","status":"partial","routes":[{"label":"Order payment summary","href":"/api/payments/order","status":"partial"},{"label":"Order detail","href":"/api/orders","status":"partial"},{"label":"Track order","href":"/customer/track-order","status":"live"}],"gaps":["No GET API returning all payment attempts per order (failed retries)","payments table model (created/paid/failed per attempt) not migrated","Customer cannot see full ledger timeline in UI"]},{"layer":4,"id":"client-confirm","name":"Client-side payment signature verify","status":"live","routes":[{"label":"Confirm payment","href":"/api/payments/confirm","status":"live"},{"label":"Lab confirm","href":"/api/lab-bookings","status":"partial"},{"label":"Appointment confirm","href":"/api/appointments","status":"partial"}],"gaps":["Demo mode marks paid without Razorpay — dev only, must be disabled in prod","Not in Module 4 spec — document as hospitalnode.in extension"]},{"layer":5,"id":"cod-manual","name":"COD / reserve / admin manual settle","status":"partial","routes":[{"label":"Pay on delivery","href":"/checkout","status":"partial"},{"label":"Reserve & pay later","href":"/customer/pay-reserve","status":"live"},{"label":"Legal payments","href":"/legal/payments","status":"live"},{"label":"Admin launch readiness","href":"/admin","status":"partial"}],"gaps":["Admin mark_paid for bank transfer reconciliation — gap","COD collection confirmation at delivery — no staff API","PMJAY / scheme billing (FA-01) — gap","Settlement ledger manual — no auto split on capture"]}],"securityChecks":[{"check":"Amount server-derived","spec":"order.total_paise never from client","platformRoute":"create-order reads catalog_orders.total_inr","status":"live"},{"check":"Webhook raw-body HMAC","spec":"X-Razorpay-Signature on raw bytes","platformRoute":"verifyRazorpayWebhookSignature","status":"live"},{"check":"Idempotent webhook","spec":"Duplicate payment.captured is no-op","platformRoute":"payment_webhook_events + ledger idempotency_key","status":"live"},{"check":"Order owner auth","spec":"create + history require JWT owner","platformRoute":"Supabase bearer on create-order / order GET","status":"live"},{"check":"Webhook no JWT","spec":"Trust signature only","platformRoute":"webhook route has no auth header check","status":"live"}],"paymentJourney":[{"step":"Place order (Module 3)","layer":"M3 L4","route":"/checkout","status":"live"},{"step":"Create Razorpay order","layer":"L1","route":"/api/payments/razorpay/create-order","status":"live"},{"step":"Customer pays (UPI/card)","layer":"L1","route":"/checkout","status":"live"},{"step":"Client confirm OR webhook","layer":"L2/L4","route":"/api/payments/confirm","status":"live"},{"step":"Order → paid","layer":"L2","route":"/api/payments/razorpay/webhook","status":"live"},{"step":"Fulfillment (Module 3 L5)","layer":"M3 L5","route":"/customer/track-order","status":"partial"}],"apiMap":[{"spec":"POST /payments/orders/{id}/create","platformRoute":"POST /api/payments/razorpay/create-order","status":"live"},{"spec":"POST /payments/webhook","platformRoute":"POST /api/payments/razorpay/webhook","status":"live"},{"spec":"GET /payments/orders/{id}","platformRoute":"GET /api/payments/order/[id] (partial shape)","status":"partial"},{"spec":"mark_paid() admin COD","platformRoute":"pay_at_pickup checkout + reserve confirm","status":"partial"},{"spec":"—","platformRoute":"POST /api/payments/confirm (client verify)","status":"live"},{"spec":"—","platformRoute":"POST /api/lab-bookings/[id]/payment","status":"live"}],"envKeys":["RAZORPAY_KEY_ID","RAZORPAY_KEY_SECRET","RAZORPAY_WEBHOOK_SECRET","RESEND_API_KEY (invoice email)","WHATSAPP_CLOUD_TOKEN (post-payment notify)"],"dashboard":"/module4","aheadOfSpec":["Real Razorpay SDK exercised (spec sandbox never hit live API)","POST /api/payments/confirm client signature verify","catalog_payment_ledger + payment_webhook_events","Lab + appointment payment routes","Refund webhook handling"]}