Hyperswitch Payments Infrastructure
repository·main·Indexed 12 days ago
https://github.com/juspay/hyperswitchAn open-source, composable payments infrastructure built in Rust. Hyperswitch enables developers to build modular payment stacks with intelligent routing, vaulting, and revenue recovery, or connect to over 100+ payment processors. The ecosystem includes components such as the Router, Scheduler, Drainer, and an analytics pipeline utilizing Kafka, Clickhouse, and OpenSearch.
What's inside Hyperswitch
- The Drainer is a specialized application within the Hyperswitch ecosystem designed to process data from Redis streams. Its primary function is to read incoming stream data and execute corresponding queries against the database, acting as a bridge between real-time event streams in Redis and persistent storage.
Overview of Payment Method Auth Services
mainThepm_authcrate provides open banking services specifically designed for the validation of payment method authentication. It is used within the Hyperswitch ecosystem to handle authentication flows required by various payment methods.Understand Dashboard routes and availability
mainThe Hyperswitch dashboard provides several management routes.
Local Development Access:
- Docker Compose: The dashboard is served by Nginx from
website/distathttp://localhost:8081/dashboard/. - Vite (Source-run): If running via Vite, routes are mounted at
http://localhost:5173/.
Production Hosting:
- The preferred route for external production hosting is
/decision-engine/. - API traffic should be proxied through
/decision-engine-api/*.
Available Dashboard Routes:
/dashboard/(Home)/dashboard/login/dashboard/signup/dashboard/onboarding/dashboard/routing/dashboard/routing/sr/dashboard/routing/rules/dashboard/routing/volume/dashboard/routing/debit/dashboard/decisions/dashboard/analytics/dashboard/audit
- Docker Compose: The dashboard is served by Nginx from
Use the Cards crate for card masking and validation
mainThecardscrate provides specialized types designed to handle sensitive card data. It is primarily used for implementing card masking (obfuscating sensitive digits) and performing card validation logic within the Hyperswitch ecosystem.Use API Models for router crate requests and responses
mainTheapi_modelscrate provides the standardized request and response data structures used by theroutercrate. Developers building integrations or extending the router should use these models to ensure compatibility with the Hyperswitch API surface.What is the Decision Engine?
mainThe Decision Engine is a standalone Rust service that acts as an intelligent layer between your orchestrator and payment gateways. It evaluates eligible gateways for every payment and selects the optimal one based on rules, live success rates, or cost. Because it runs independently over HTTP, it does not require a mandatory orchestrator, preventing vendor lock-in.What is Multi-Objective Routing?
mainMulti-objective routing is a cost-aware post-step layered on top of Success-Rate (SR) scoring. While standard SR routing optimizes for the highest authorization rate, multi-objective routing balances authorization rate and processing cost to maximize the merchant's economic outcome (Expected Value).
How it works:
- The SR scorer runs first to produce a ranking based on authorization probability.
- A post-step attaches per-gateway fee estimates to these candidates.
- The engine re-ranks candidates based on Expected Value (EV):
Economic value (EV) = auth rate × settlement valuewheresettlement value = txn amount − cost of payment processing.
This approach preserves all standard SR features (dimension-level buckets, elimination, hedging) but applies cost as an additional lens at the end of the decision process.
Overview of Hyperswitch Payment Modules
mainHyperswitch is a modular payments infrastructure. Instead of a monolithic integration, you can pick and integrate specific modules based on your needs:
- Cost Observability: Tools to audit and optimize payment costs, detecting hidden fees and penalties.
- Revenue Recovery: Intelligent retry strategies (tuned by card bin, region, etc.) to combat passive churn.
- Vault: A PCI-compliant service for storing cards, tokens, and wallets. Supports 'bring-your-own-vault' (e.g., VGS, TokenEx).
- Intelligent Routing: Routes transactions to the PSP (e.g., Stripe, Adyen, Braintree) with the highest predicted authorization rate.
- Reconciliation: Automates 2-way and 3-way reconciliation with customizable outputs.
- Alternate Payment Methods: Drop-in widgets for PayPal, Apple Pay, Google Pay, Samsung Pay, Pay by Bank, and BNPL (e.g., Klarna).
Understand the Decision Engine API access classes
mainThe Decision Engine API is organized into different access classes based on the required permissions and authentication methods. Use the following guide to determine how to authenticate your requests:
- Public: No authentication required. Used for health checks and initial onboarding.
- Routes:
GET /health,GET /health/ready,GET /health/diagnostics,POST /auth/signup,POST /auth/login.
- Routes:
- Admin bootstrap: Requires an
Admin secret.- Routes:
POST /merchant-account/create.
- Routes:
- Protected: Requires either a JWT token via
Authorization: Bearer <jwt_token>or an API key viax-api-key: <api_key>. This covers most operational routes including routing, decisions, rule configuration, and analytics. - Sandbox: Any route served through
https://sandbox.hyperswitch.io. Follows the same authentication rules as Protected routes, but requires the additional headerx-feature: decision_engine.
- Public: No authentication required. Used for health checks and initial onboarding.
Use Ephemeral Keys for temporary access
mainAn Ephemeral Key is a short-lived key used for limited operations, such as accessing a specific customer object. The validity period is configurable via the[eph_key] validitysetting indevelopment.toml.Understand the Router crate architecture
mainThe
routercrate is the main orchestrator of the Hyperswitch project. It is structured into several key functional areas:core: Contains the central orchestration logic and common payment flows (e. ext{g.}$, customers, payment methods, payments, and refunds). Connector-specific implementations should remain minimal and reside in theconnectormodule.connector: Houses gateway-specific transformation implementations (e.g.,adyen,stripe).routes: Defines the API endpoints exposed by the router, currently implemented usingactix_web.types: Contains object and API type definitions, split intoapi(for the router API) andstorage(for database interactions via Diesel).configs: Handles configuration loading.services: Manages external service integrations, such asredis.scheduler: Manages scheduled tasks and related types.utils: General utility functions.
Use the Mock Server for payment processor APIs
mainThe
cypress-testsdirectory includes a router-based mock server (Express) to simulate payment processor APIs.Architecture:
mockserver.js: Entry point.router.js: Central router.- Connector implementations (e.g.,
Silverflow.js): Individual router implementations.
Running the Mock Server:
- Start the server:
npm run mockserver(Default port: 3010). - Custom port:
MOCKSERVER_PORT=3010 npm run mockserver.
Integrating with Hyperswitch: To redirect a specific connector's traffic to the mock server, set the corresponding environment variable in Hyperswitch. For example, to redirect Silverflow:
ROUTER__CONNECTORS__SILVERFLOW__BASE_URL=http://localhost:3010/silverflow cargo r# Start mock server npm run mockserver # Run Hyperswitch with Silverflow redirected to mock server ROUTER__CONNECTORS__SILVERFLOW__BASE_URL=http://localhost:3010/silverflow cargo r