ADR-00029 — Server-Side Razorpay Order Creation (payment-service) vs. Client-Constructed Payment Order

By Engineering Team•October 6, 2026•4 min read
  • Status: Approved / Implemented
  • Date: 2026-10-06
  • Authors: Engineering Team

Context

BRD-015 BR-01 requires that a payment be genuinely, verifiably collected — not just recorded against a selected method — and that guarantee only holds if the amount actually charged is the amount the backend itself computed, never a number the client supplies. SR-016 FR-01 already states that order-service’s checkout saga calls payment-service’s CreatePaymentOrder RPC to create the real Razorpay order; this ADR settles the question behind that line — where the Razorpay order (and the amount it will charge) is constructed: server-side in payment-service, or directly by the ui-application Flutter client talking to Razorpay itself.

Decision Drivers (FRs & NFRs)

  • SR-016 FR-01 — real payment-provider order creation, not a client-asserted success.
  • SR-016 NFR-03 — server-authoritative order amount, no client-constructed payment order.
  • BRD-011 — the order total this payment amount must match is itself a backend-computed, trustworthy figure; a second, independently client-submitted amount at the payment step would undermine that guarantee by construction.
  • The platform’s security standards — secrets (here, Razorpay’s API key secret) are never shipped into client code.

Options Evaluated

Option 1 — payment-service creates the Razorpay order server-side, from the saga’s own trusted amount (CHOSEN)

As implemented: the checkout saga’s CreatePaymentOrderActivity calls payment-service’s CreatePaymentOrder RPC with the order_id/amount/currency the saga already holds as its own validated input — never anything freshly supplied by the client at this step. payment-service calls Razorpay’s order-creation endpoint via repository/razorpay/create_order, persists payment_gateway_orders, and returns only razorpay_order_id/razorpay_key_id to the saga, which the saga then republishes on the order-level SSE stream for the client to open Razorpay’s hosted checkout UI with.

  • Pros:
    • The charged amount can never diverge from the backend’s own trustworthy total. Because the amount passed to Razorpay comes from the saga’s own input, not a second client-submitted value, there is no path by which a tampered or buggy client could cause Razorpay to charge something other than what the order was actually priced at.
    • Razorpay’s API secret (RAZORPAY_KEY_SECRET) never leaves the backend. Only payment-service holds it; the client only ever receives the public razorpay_key_id plus a specific razorpay_order_id already scoped to one amount, which is exactly the credential shape Razorpay’s own checkout SDK expects from an untrusted client.
    • The webhook has a reliable identity to resolve against. Because payment-service itself initiated the order and persisted payment_gateway_orders before any webhook can arrive, find_by_razorpay_order_id always has a row to resolve tenant_id/order_id from — a client-initiated order would have no equivalent backend-side record to anchor that lookup to.
  • Cons & Accepted Trade-offs:
    • The client cannot open Razorpay’s checkout UI until the saga’s CreatePaymentOrderActivity round-trip completes — an extra hop versus calling Razorpay directly. This cost is already inherent to the asynchronous saga design and carries no additional cost beyond what ADR-00027 already accepted.

Option 2 — ui-application (Flutter) constructs and submits the payment order directly to Razorpay

  • Pros: Removes one network hop before the checkout UI opens — the client could call Razorpay the moment it has an amount, without waiting on the saga.
  • Cons (Why Rejected):
    • Requires shipping a Razorpay credential capable of creating orders into the mobile client. A secret embedded in a distributed mobile binary is not a secret — it can be extracted by reverse-engineering the app — directly violating the platform’s security standards’ “secrets are never hardcoded/shipped to a client” rule.
    • Nothing server-side would validate the amount before Razorpay is asked to charge it. A modified or compromised client could submit any amount it wants, decoupling what Razorpay actually charges from the order total the backend itself computed — directly undermining both BRD-015 BR-01 and BRD-011’s trustworthy-totals guarantee, since the two would no longer be the same number by construction.
    • Breaks the webhook’s own tenant/order resolution path. payment-service’s webhook handler resolves tenant_id/order_id by looking up payment_gateway_orders via razorpay_order_id — a row only payment-service’s own CreatePaymentOrder call creates. A client-initiated order would leave no such row for the webhook to resolve against.

Final Decision

Option 1 is selected and implemented. The Razorpay order — and the amount it charges — is always created by payment-service from the checkout saga’s own already-validated input, never by the client. The client receives only razorpay_order_id/razorpay_key_id, scoped to an amount it never had the ability to set itself.