How razorpay/razorpay-java works
Project Type and Purpose
• This is a Java SDK (client library) for the Razorpay REST API (“razorpay-java”). It provides a strongly‐typed, high‐level Java interface over HTTP/JSON calls to the Razorpay payment platform.
File Structure Analysis
• Top‐level:
• pom.xml – Maven coordinates and dependencies
• README.md / documents/ – usage docs per resource
• src/main/java/com/razorpay:
• RazorpayClient.java – single entry point for SDK
• *Client.java classes – one per resource (PaymentClient, OrderClient, etc.)
• Domain model classes (Payment, Order, Customer, etc.)
• Core HTTP layer: ApiClient, ApiUtils, Constants, project.properties
• Validation/support: PayloadValidator, Utils, CustomTLSSocketFactory
• src/test: unit tests mocking HTTP to validate each client/resource.
README Insights
• SDK instantiation modes (key/secret or access_token)
• Supported resources listed under “Supported Resources” linking to documents/*.md
• Custom‐request escape hatch via razorpayClient.Payments.post(...)
a. Main Components
• User Application (any Java app using the SDK)
• RazorpayJavaSDK (with sub‐layers)
• Entry Point: RazorpayClient
• Resource Clients: AccountClient, PaymentClient, OrderClient, …
• HTTP Transport Layer: ApiClient (handles base URL, auth, headers), HttpURLConnection or Apache HTTP under the hood
• Domain Models: Payment, Order, Customer, etc.
• Utilities: PayloadValidator, ApiUtils, CustomTLSSocketFactory, ValidationConfig
• External System: Razorpay REST API endpoints
b. Relationships & Data Flow
1. User App invokes methods on RazorpayClient.
2. RazorpayClient dispatches to a ResourceClient (e.g., PaymentClient.create()).
3. ResourceClient builds a JSON payload (using domain models), calls ApiClient.
4. ApiClient serializes payload, adds authentication headers, issues HTTP request to Razorpay API.
5. API responds JSON – ApiClient deserializes into domain model.
6. Response model returns up through ResourceClient to User App.
c. Architectural Patterns & Principles
• Layered architecture:
• API‐Client Layer (HTTP concerns)
• Resource‐specific façade layer (*Client classes)
• Domain model layer (POJOs for JSON mapping)
• Separation of Concerns: validation (PayloadValidator), TLS config, utils isolated
• Extensibility: new resource clients follow the same pattern
• Testability: HTTP layer can be mocked in unit tests
d. Key Technologies/Frameworks
• Java 1.8+
• Maven for build & dependency management
• JSON serialization (org.json.* or cz.json)
• JUnit/TestNG (tests under src/test)
Elements
• Version (1.4.8) and authentication modes (Key/Secret vs Access Token).