Payment-Service — Payment Methods, Razorpay Orders & Webhooks

By Engineering Team•September 24, 2026•6 min read

Responsibility

payment-service owns tenant-scoped payment configuration and the Razorpay payment-order lifecycle.

  • Serves allowed-payment-methods lookup per tenant over gRPC (paymentinfo.proto) — shop-service’s checkout resolution (GetCheckoutDetails) is the first and, today, only consumer, caching the result into its checkout-session snapshot per SR-012 FR-15.
  • Creates a Razorpay payment order for a checkout (paymentorder.proto’s CreatePaymentOrder), wrapping Razorpay’s order-creation API behind a dedicated repository/razorpay/ provider integration.
  • Receives Razorpay’s webhook (POST /payment/webhook/razorpay), verifies its signature, and persists the resulting captured/failed/refund.processed event via a WebhookEventStrategy per event type — the only REST route this service exposes.
  • Is a gRPC client of order-service, notifying it of payment outcomes as part of the checkout saga.
  • Payment history, payment-status tracking, and payment-gateway integration beyond Razorpay order creation are future scope — not built, not scaffolded speculatively.

Tech Stack

Concern Choice
Language Rust
gRPC framework tonic
REST framework Axum (Razorpay webhook receiver only)
Data store PostgreSQL, via SeaORM
Template @templates/rust-postgres-microservice
Server bootstrap Both servers run concurrently via tokio::try_join! in one binary
Core library rust-lang-core-lib (typed errors, logging macros, #[tracing::instrument], Pub/Sub publisher)
Observability Tracing + OpenTelemetry

Ports

Gateway HTTP (host → container) gRPC (host → container) Service Name
development/nginx.conf routes POST /payment/webhook/razorpay only; every other capability is gRPC-only 8094 50060 → 50053 payment-service

Data Model — PostgreSQL

Table Purpose
allowed_payment_methods Tenant-scoped list of enabled payment methods, served by PaymentInfoService
payment_gateway_orders One row per Razorpay order created via CreatePaymentOrder
razorpay_events Raw webhook event record, keyed by Razorpay’s own event id for idempotency
payment_ledger Derived ledger entries (capture/failure/refund) written atomically alongside razorpay_events

PaymentEventRepositoryTrait/PaymentLedgerRepositoryTrait deviate from this service’s other repositories by taking an explicit &DatabaseTransaction parameter, so a webhook’s event record and its ledger entry commit atomically — both writes belong to a single outcome, so a partial commit would leave the ledger and the raw event record disagreeing.

gRPC Contract

  • paymentinfo.proto — tenant-scoped allowed-payment-methods lookup.
  • paymentorder.proto — CreatePaymentOrder, the only write path into payment_gateway_orders; RefundPayment, called by order-service’s checkout saga as its fulfillment-failure compensating action — see SR-017 FR-04. RefundPayment’s own response is not a ledger write — the payment_ledger entry is written later, only once Razorpay’s refund.processed webhook is processed.

CreatePaymentOrder implementation

Follows the repository-per-provider pattern (see the platform’s layered architecture standard “Repository wraps every outbound call” section): repository/razorpay/ (Razorpay’s own wire-format DTOs, one method per Razorpay endpoint — currently just create_order, since only one Razorpay endpoint is integrated today) is a separate repository from repository/paymentorder/ (the Postgres persistence for payment_gateway_orders). service/ never holds a raw reqwest::Client directly — the Razorpay HTTP call is wrapped behind RazorpayRepositoryTrait, composed via a build(cfg) -> Arc<dyn RazorpayRepositoryTrait> factory.

Razorpay webhook implementation

POST /payment/webhook/razorpay — controller → parser → signature-verifier → strategy dispatch:

  1. Signature verification — the raw request body is HMAC-verified against Razorpay’s webhook secret before any parsing proceeds.
  2. Parsing — the verified payload is decoded into a typed event.
  3. Strategy dispatch — a WebhookEventStrategy trait with one implementation per event type (PaymentCapturedStrategy, PaymentFailedStrategy, RefundProcessedStrategy) persists the event and its ledger entry inside one transaction. Adding a new Razorpay event type adds a new strategy implementation, never a branch inside an existing one.

Document audit trail — message_publisher/documentaudit_publisher.rs

payment-service is the first instrumented publisher into document-service’s audit trail sink, and the reference Rust implementation the pattern is documented against.

  • A DocumentAuditPublisherTrait with a publish_audit_event method, calling rust_lang_core_lib::pubsub::publish — never a raw Pub/Sub client held in service/.
  • Two call sites publish fire-and-forget via tokio::spawn: Razorpay order creation (transaction_name: "create_payment_order") and the webhook handler (one event per Razorpay webhook delivery). Both send the full, unmasked request/response JSON — masking happens exclusively inside document-service, never here.
  • A publish failure is logged and never propagates into the RPC/webhook response that triggered it, per SR-002 NFR-01.
  • RefundPayment is not a third call site. Unlike CreatePaymentOrder, the RefundPayment RPC implementation has no audit-publish call of its own — the only audit record of a refund comes later, from the webhook handler picking up Razorpay’s refund.processed event. Tracked as a gap, not an oversight — see Technical Debt — Payment Transaction Ledger & Refund Audit Gaps, TD-01.

Implementation Notes

  • The webhook route is the only REST surface in an otherwise gRPC-only service — everything else (paymentinfo, paymentorder) is served over gRPC, running alongside the Axum webhook server in the same binary via tokio::try_join!.
  • PaymentEventRepositoryTrait/PaymentLedgerRepositoryTrait’s explicit-transaction parameter is a deliberate deviation from this service’s other repositories (which don’t take a transaction handle) — needed specifically because a webhook’s raw event and its derived ledger entry must commit together or not at all.

Full service reference: payment-service/CLAUDE.md. Audit-trail pipeline overview: ADR-00002 — Subscribe-Only Audit Sink, Mask-Once-At-Persistence.