contributors : @ankit_choudhary_2209, @jating06
If you've ever integrated a payment gateway, you know it's rarely as simple as the documentation makes it seem. API quirks, undocumented headers, field mappings that change between environments, and edge cases that only surface in production. At Razorpay, we integrate with dozens of banks and payment providers across India, and until recently, each new gateway meant 2-3 weeks of developer time, extensive testing, and inevitable deployment surprises.
The traditional approach: read hundreds of pages of documentation, map request/response fields between formats, implement error handling for dozens of failure scenarios, write integration code matching existing patterns, create comprehensive tests, and iterate through multiple rounds of bug fixes. This process is tedious, error-prone, and doesn't scale when you're adding three new gateways simultaneously or when banks update APIs and break existing integrations.
That's why we built the Gateway Integration Agent on our SWE Agent platform. This isn't just code generation; it's an intelligent system that understands bank documentation, learns from our existing implementations, and generates production-ready integration code with comprehensive test coverage. The result? We've reduced integration time from 2-3 weeks to 4-5 days, increased throughput by 3x, and freed developers to focus on genuinely complex edge cases. Even product managers can now initiate integrations.
The Problem: When Payment Integration Becomes a Bottleneck
Razorpay supports multiple payment methods across different gateways: credit cards, debit cards, UPI, netbanking, wallets. Each method has different workflows, API contracts, and failure modes. Integrating a new gateway means implementing support for whichever methods that gateway offers, often five or six different endpoints with distinct structures.
Documentation quality varies wildly. Some banks provide comprehensive API specs. Others give you PDFs with SOAP screenshots and vague field descriptions. You spend hours clarifying whether txn_id equals transaction_reference or something entirely different. Authentication schemes range from simple API keys to byzantine combinations of certificates, HMAC signatures, and rotating tokens.
Our integration codebase has accumulated patterns over years. Gateway implementations live in integrations-go with established conventions for client structure, retry handling, logging, and data transformation. New integrations must follow these patterns for consistency and maintainability. Developers can't just implement what bank docs say; they need to implement it the Razorpay way.
Testing is another massive time sink. Unit tests covering happy paths, error scenarios, timeout handling, retry logic. Integration tests verifying field transformation correctness. Handling cases where banks return success codes with error messages in the body. Writing comprehensive tests often takes as long as writing the integration code itself.
Gateway integrations became a bottleneck. Business partnerships signed, merchants requested specific banks, and the development backlog took weeks to clear. We needed dramatic acceleration without sacrificing code quality or test coverage.
Phase 1: Manual LLM-Assisted Integration
Our first attempt used Claude with cursor rules to assist developers. Load bank docs and a reference gateway into context, iteratively prompt for functions, error handlers, and tests. This augmented development approach cut integration time from weeks to days in many cases. Claude excelled at complex field mappings, boilerplate generation, and test case creation.
However, limitations emerged. Still required experienced developers to orchestrate the process and make architectural decisions. Context window limitations meant carefully curating what information to provide. Consistency varied based on how developers crafted prompts. Quality depended heavily on prompt engineering and output review.
What we learned: LLMs could handle payment gateway complexity when properly guided. The limitation wasn't model capability; it was lack of systematic orchestration. We needed to encode the entire workflow into an automated system applying best practices consistently.
Enter SWE Agent: Platform for Engineering Automation
SWE Agent is our internal automation platform for streamlining repetitive SDLC tasks through AI-powered workflows. An orchestration layer for developer productivity where you define agents that understand engineering contexts, make intelligent decisions, and execute complex multi-step tasks autonomously.
The React frontend democratizes automation access. Teams browse available agents, configure parameters, and monitor execution through a clean web interface without needing command-line expertise.
The FastAPI backend handles API routing, authentication, and job scheduling. An integrated MCP Server exposes the Model Context Protocol, allowing IDEs and external clients to interact programmatically.
LangGraph workflows provide intelligent orchestration with state machines and conditional logic. Workflows execute multi-step processes (Initialize → Run Parallel → Validate → Deploy → E2E Tests → Create PRs) that can branch, retry, or fail gracefully based on intermediate results. This is crucial for complex tasks where subsequent steps depend on earlier discoveries.
Background workers provide scalable async execution via SQS. Long-running tasks execute on horizontally scalable worker nodes without blocking APIs or hitting timeouts.
The Agent Execution Layer supports multiple headless CLI agents: Claude Code (via AWS Bedrock and Vertex AI), Gemini CLI (via Vertex AI), and Agent-to-Agent communication through Google ADK. MCP integrations extend capabilities: Memory, Sequential Thinking, Service Level, E2E Tests, K8s, Devstack, Infra, and Data Lake access.
Infrastructure includes MySQL for persistence, Redis for caching, GitHub CLI for repos, AWS EFS for shared codebase access, and dual LLM provider support (Bedrock and Vertex AI) for environment-specific model selection.
What makes this powerful is the combination: intelligent orchestration making context-aware decisions, robust execution infrastructure handling scale and retries, comprehensive tooling interacting with Git/GitHub/K8s/test frameworks like developers would, and an extensible agent catalogue where new agents integrate without core modifications.
Gateway Integration Workflow: The Complete Flow
Step 1: Configuration. User selects Gateway Integration Agent, provides gateway name, reference gateway, APIs to integrate, payment methods, and bank documentation in MDC (Markdown Catalog) format. MDC is structured documentation clearly delineating endpoints, schemas, authentication, error codes, and validations, allowing programmatic extraction.
Step 2: Documentation Analysis. LangGraph parses MDC semantically, identifying endpoint patterns, required vs optional fields, authentication schemes, error codes, and response mappings. This creates a knowledge graph of the gateway's API surface. The agent understands that to initiate payment, you call endpoint X with fields A, B, C; error 1001 means invalid credentials; the bank uses ISO 8601 timestamps in responses but expects epoch milliseconds in requests.
Step 3: Reference Learning. Agent clones the reference gateway repository and analyzes implementation patterns: client initialization structure, configuration constant placement, authentication token refresh handling, retry logic for network failures, transaction logging approaches, field transformation abstractions. This pattern recognition ensures new gateways match existing conventions automatically.
Step 4: Conditional Routing. Workflow checks payment methods being integrated. UPI QR payments route to specific repositories; other methods route to integrations-go. This dynamic routing based on configuration makes the system extensible without core rewrites.
Step 5: Code Generation. Agent generates gateway client (authentication, connection, request execution), field transformers (Razorpay format to bank format bidirectionally), error handlers (catching, classifying, standardizing errors), validators (pre-flight requirement checks), and logging instrumentation. The code is customized to specific bank quirks: custom headers, XML error responses, specific transaction ID patterns.
Step 6: Automated Error Resolution. Agent runs linters checking style violations, then compilers checking syntax errors and type mismatches. When errors occur, the workflow analyzes error messages, understands what went wrong, generates targeted fixes, applies them, and recompiles. This iterative process continues until achieving clean compilation.
Step 7: Test Generation. Agent generates comprehensive unit tests targeting 80%+ coverage: successful payment flows, error scenarios, timeout/retry logic, field transformation correctness, validation edge cases, authentication refresh. Tests are informed by bank error codes and reference gateway patterns, ensuring consistency.
Step 8: Pull Request Creation. Workflow creates feature branch, commits code and tests, pushes to remote, and opens PR with detailed description including gateway name, supported methods, implemented endpoints, bank-specific quirks, and coverage statistics. The PR is ready for human review; tedious work done, critical oversight remains human.
Real-World Impact
Integration time dropped from 2-3 weeks to 4-5 days (75% reduction). We've successfully onboarded Decentro and HDFC Smart Gateway using the agent. Throughput increased 3x; teams now handle three to four gateways monthly versus one. Developer workload shifted from 100% hands-on coding to 25% review and edge case handling. Code consistency improved dramatically; every generated gateway follows identical patterns, conventions, and logging approaches.
Product managers can now initiate integrations through the intuitive UI without deep technical knowledge. This democratization means integrations start immediately after partnerships sign, without waiting for developer availability.
What Makes This Different
Semantic understanding of MDC documentation. The agent parses it as structured API specifications, not just text. Pattern learning from reference implementations beyond simple copying, identifying abstract patterns applied contextually. Conditional orchestration via LangGraph making intelligent routing decisions dynamically. Iterative error resolution analyzing, fixing, and retrying until clean compilation. Infrastructure integration creating branches, running linters/compilers, generating tests, opening PRs. Comprehensive test generation achieving 80%+ coverage informed by error scenarios and reference patterns.
The Bottom Line
The Gateway Integration Agent represents a fundamental shift in how Razorpay approaches payment infrastructure development. We've moved from manual bottlenecks constraining business growth to rapid, consistent integrations with minimal developer overhead.
Results: 75% time reduction, 3x throughput increase, democratized capability. Decentro and HDFC Smart Gateway successfully onboarded, proving production viability. Code quality is high, test coverage comprehensive, architectural patterns consistent.
More importantly, we've built a scalable foundation for continued improvement. Every gateway integrated makes the system smarter. Every edge case enriches pattern libraries. Every workflow improvement benefits all future integrations automatically.
This approach demonstrates that complex technical tasks traditionally requiring significant human expertise can be automated when you combine AI capabilities with systematic orchestration, robust tooling integration, and iterative refinement. The Gateway Integration Agent proves this works in production at scale.
If you're facing similar integration bottlenecks, the lessons apply directly. Build structured documentation formats machines can parse. Create reference implementations encoding your patterns. Use orchestration frameworks supporting conditional logic and state management. Integrate deeply with development infrastructure. Generate comprehensive tests, not just code. Design for continuous improvement rather than one-time automation.
The future of developer productivity isn't replacing engineers; it's empowering them to focus on genuinely complex problems by automating routine work. That's exactly what the Gateway Integration Agent does.
editor: @paaarth96





Top comments (0)