ifixkart-admin/docs/commerce/razorpay.md
Adithiyan bbd3a3e959 feat: initial commit — full platform snapshot
- Backend: FastAPI app with all models, services, schemas, routes
- Admin Panel: Next.js dashboard with all modules
  (CRM, POS, repairs, warranties, billing, notifications, etc.)
- Ecommerce: storefront (submodule) + product catalog
- AI Agents: .agents/ skill library for Antigravity IDE
- Docs: architecture, billing, notification gateway markdown
- Submodules: Backend/OpenWA, Ecommerce/File 2/storefront
2026-10-13 12:59:47 +05:30

1.4 KiB

Razorpay Payment Integration Architecture

Dual Asynchronous Signal Architecture

Browser callbacks and server webhooks are processed as independent, asynchronous signals. Order state confirmation does not rely on the browser remaining open.

flowchart TD
    Razorpay["Razorpay Gateway"]
    
    Razorpay -.->|Signal 1: Browser Callback| Browser["FastAPI /payment/verify"]
    Razorpay -.->|Signal 2: Server Webhook| Webhook["FastAPI /payment/webhook"]

    subgraph Payment Processing Engine
        Browser --> IdempotencyCheck{"Payment Idempotency Guard\n(razorpay_payment_id)"}
        Webhook --> IdempotencyCheck
        
        IdempotencyCheck -->|First Time Received| VerifyHMAC["HMAC-SHA256 Verification"]
        IdempotencyCheck -->|Already Processed| ReturnExisting["Return Current Payment Status (ACK)"]
        
        VerifyHMAC --> PaymentLedger["Record in Payment Ledger"]
        PaymentLedger --> OrderStateMachine["Transition Order State\n(PAYMENT_CAPTURED -> ORDER_CONFIRMED)"]
    end

HMAC-SHA256 Verification Formula

import hmac
import hashlib

def verify_razorpay_signature(order_id: str, payment_id: str, signature: str, secret: str) -> bool:
    generated_signature = hmac.new(
        key=secret.encode('utf-8'),
        msg=f"{order_id}|{payment_id}".encode('utf-8'),
        digestmod=hashlib.sha256
    ).hexdigest()
    return hmac.compare_digest(generated_signature, signature)