Explore the hyperswitch repository to understand how connectors are structured and…
- User
Explore the hyperswitch repository to understand how connectors are structured and implemented, particularly looking for existing connector examples to understand the pattern for adding new connectors.
Assistant
I'll explore the hyperswitch repository to understand how connectors are structured and implemented. Let me start by examining the repository structure to identify where connector code is located.
Assistant
Now let me look for connector-specific directories to understand the structure better:
Assistant
Let me focus on the main connectors directory to understand the structure better:
Assistant
Let me try a different approach to look at the connectors structure:
Assistant
Let me examine a few concrete connector implementations to understand the pattern:
Assistant
Let me check what connector modules actually exist:
Assistant
Great! Now let me examine a couple of connector implementations to understand the pattern. Let me start with a simpler one like
checkout:Assistant
Let me check the structure of a connector directory:
Assistant
Let me examine the checkout connector's main module file:
Assistant
Now let me look at the transformers.rs file for the checkout connector to understand the structure better:
Assistant
Let me now look at another connector to get a better sense of the pattern. Let me check the worldpay connector which seems to be another implementation:
Assistant
Let me also examine how the connectors are registered and organized in the main module:
Assistant
Let me also examine how connectors are accessed in the router to understand the integration patterns better:
Assistant
(no content)
Assistant
(no content)
Assistant
Now let me look at some connector-specific test files to understand how they're tested:
Assistant
(no content)
Assistant
Based on my exploration of the hyperswitch repository, I can now provide a comprehensive overview of how connectors are structured and implemented.
Connector Architecture in Hyperswitch
Overall Structure
Connectors in hyperswitch are organized in a modular fashion under
crates/hyperswitch_connectors/src/connectors/. Each connector has its own subdirectory containing:- A main module file (
<connector_name>.rs) that defines the core connector logic - A
transformers.rsfile for data transformation between hyperswitch and the payment processor
Key Files and Components
-
Main Connector Module: Each connector has a main module file (e.g.,
checkout.rs) that implements:- The connector struct with amount converters
- Authentication handling
- Base URL configuration
- Error response building
- API endpoint implementations for various payment flows (authorize, capture, sync, void, refund, etc.)
-
Transformers Module: Contains data structures and transformations for:
- Request/response objects
- Authentication types
- Payment methods handling
-
Registration: Connectors are registered in
crates/hyperswitch_connectors/src/connectors.rswhere they're exposed for use.
Implementation Pattern
Looking at examples like
checkout.rsandworldpay.rs, the pattern is consistent:- Struct Definition: Each connector implements a struct with appropriate amount converters
- Trait Implementations: Implement various traits like:
ConnectorCommon- Basic connector functionality (ID, base URL, auth handling)ConnectorValidation- Validation rules for the connectorapi::Paymenttraits - Payment-related functionalities (authorize, capture, sync, void, refund)
- Integration Implementations: Specific implementations for different payment flows using
ConnectorIntegrationtrait - Error Handling: Standardized error response construction
- Webhook Support: Implementation of
IncomingWebhookfor webhook processing - Feature Matrix: Supported payment methods definition
Connector Flow Example
Each connector implements specific flows like:
PaymentsAuthorize- Payment authorizationPaymentsCapture- Payment capturePaymentsSync- Payment synchronizationPaymentsVoid- Payment cancellation/voidRefundExecute- Refund executionRefundSync- Refund synchronizationPaymentToken- Tokenization of payment methodsMandateSetup- Setup for recurring payments
Testing Approach
Tests are structured in
crates/router/tests/connectors/where:- Each connector has its own test file
- Tests follow patterns for positive test cases (authorize, capture, sync)
- They utilize helper functions for connector setup and authentication
Key Design Principles
- Modularity: Each connector is contained in its own module
- Consistent Interface: All connectors implement the same set of traits for predictable behavior
- Generic Transformations: Common transformations are handled through utility functions
- Extensible: Easy to add new connectors by following the established pattern
- Comprehensive Coverage: Supports all major payment flows and features
Example Implementation Details
In the
checkout.rsexample, I can see:- Structured implementation for different payment flows (Authorize, Capture, Sync, Void, Refund)
- Clear separation of concerns between connector logic and data transformations
- Comprehensive error handling with specific error mappings
- Webhook support with verification mechanisms
- Feature matrix defining supported payment methods and configurations
This modular architecture makes it easy to add new payment processors by following the established patterns, ensuring consistency across all integrations in the system.
- A main module file (
Assistant
Based on my exploration of the hyperswitch repository, I've identified the key structural elements and patterns used for connector implementation. Let me now examine some additional connector implementations to provide more comprehensive insights:
Assistant
Let me examine the structure of how the connectors are referenced and used in the main application:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Identical first prompt
claude-haiku-4-5-20251001Compare side by side →
claude-haiku-4-5-20251001Compare side by side →
claude-haiku-4-5-20251001Compare side by side →
claude-haiku-4-5-20251001Compare side by side →
claude-haiku-4-5-20251001Compare side by side →
claude-haiku-4-5-20251001Compare side by side →
claude-haiku-4-5-20251001Compare side by side →
claude-haiku-4-5-20251001Compare side by side →
claude-haiku-4-5-20251001Compare side by side →
claude-haiku-4-5-20251001Compare side by side →
claude-haiku-4-5-20251001Compare side by side →