Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation
Rust adyenbeginner-friendlyfeaturedfinancefintechhacktoberfesthigh-performanceopen-sourceorchestrationpaymentpayment-gatewaypayment-integrationpayment-processingpaymentspayments-platformrestful-apirustsdkstripeworks-with-react
refactor(success_based): add support for exploration (#8158)
Chethan Rao3eb94d9a3dcb
diff --git a/api-reference-v2/openapi_spec.json b/api-reference-v2/openapi_spec.jsonindex 039981f661..fbabc86467 100644--- a/api-reference-v2/openapi_spec.json+++ b/api-reference-v2/openapi_spec.json@@ -23374,9 +23374,13 @@},"specificity_level": {"$ref": "#/components/schemas/SuccessRateSpecificityLevel"+ },+ "exploration_percent": {+ "type": "number",+ "format": "double",+ "nullable": true}- },- "additionalProperties": false+ }},"SuccessRateSpecificityLevel": {"type": "string",diff --git a/api-reference/hyperswitch_intelligent_router_open_api_spec.yml b/api-reference/hyperswitch_intelligent_router_open_api_spec.ymlindex 58bff737f3..7372a083b8 100644--- a/api-reference/hyperswitch_intelligent_router_open_api_spec.yml+++ b/api-reference/hyperswitch_intelligent_router_open_api_spec.yml@@ -44,6 +44,7 @@ paths:min_aggregates_size: 5default_success_rate: 0.95specificity_level: ENTITY+ exploration_percent: 20.0responses:"200":description: Success rate calculated successfully@@ -758,6 +759,17 @@ components:items:$ref: "#/components/schemas/LabelWithScore"description: List of labels with their calculated success rates+ routing_approach:+ $ref: "#/components/schemas/RoutingApproach"++ RoutingApproach:+ type: string+ description: >+ Defines the routing approach based on the success rate calculation.+ enum:+ - EXPLORATION+ - EXPLOITATION+ example: EXPLOITATIONUpdateSuccessRateWindowRequest:type: objectdiff --git a/api-reference/openapi_spec.json b/api-reference/openapi_spec.jsonindex 99d172f7b3..d9d48bf522 100644--- a/api-reference/openapi_spec.json+++ b/api-reference/openapi_spec.json@@ -27396,9 +27396,13 @@},"specificity_level": {"$ref": "#/components/schemas/SuccessRateSpecificityLevel"+ },+ "exploration_percent": {+ "type": "number",+ "format": "double",+ "nullable": true}- },- "additionalProperties": false+ }},"SuccessRateSpecificityLevel": {"type": "string",diff --git a/crates/api_models/src/open_router.rs b/crates/api_models/src/open_router.rsindex f15d9cbcfe..cfcb45ef97 100644--- a/crates/api_models/src/open_router.rs+++ b/crates/api_models/src/open_router.rs@@ -62,6 +62,7 @@ pub struct PaymentInfo {pub struct DecidedGateway {pub gateway_priority_map: Option<HashMap<String, f64>>,pub debit_routing_output: Option<DebitRoutingOutput>,+ pub routing_approach: String,}#[derive(Debug, Serialize, Deserialize, PartialEq)]diff --git a/crates/api_models/src/routing.rs b/crates/api_models/src/routing.rsindex 527e8353b8..9e5fad91ac 100644--- a/crates/api_models/src/routing.rs+++ b/crates/api_models/src/routing.rs@@ -965,6 +965,7 @@ impl Default for SuccessBasedRoutingConfig {max_total_count: Some(5),}),specificity_level: SuccessRateSpecificityLevel::default(),+ exploration_percent: Some(20.0),}),decision_engine_configs: None,}@@ -985,7 +986,6 @@ pub enum DynamicRoutingConfigParams {}#[derive(serde::Serialize, serde::Deserialize, Debug, Clone, ToSchema)]-#[serde(deny_unknown_fields)]pub struct SuccessBasedRoutingConfigBody {pub min_aggregates_size: Option<u32>,pub default_success_rate: Option<f64>,@@ -993,6 +993,7 @@ pub struct SuccessBasedRoutingConfigBody {pub current_block_threshold: Option<CurrentBlockThreshold>,#[serde(default)]pub specificity_level: SuccessRateSpecificityLevel,+ pub exploration_percent: Option<f64>,}#[derive(serde::Serialize, serde::Deserialize, Debug, Clone, ToSchema)]@@ -1118,7 +1119,10 @@ impl SuccessBasedRoutingConfigBody {.as_mut().map(|threshold| threshold.update(current_block_threshold));}- self.specificity_level = new.specificity_level+ self.specificity_level = new.specificity_level;+ if let Some(exploration_percent) = new.exploration_percent {+ self.exploration_percent = Some(exploration_percent);+ }}}diff --git a/crates/external_services/src/grpc_client/dynamic_routing/success_rate_client.rs b/crates/external_services/src/grpc_client/dynamic_routing/success_rate_client.rsindex 278a2b50d1..b63f435327 100644--- a/crates/external_services/src/grpc_client/dynamic_routing/success_rate_client.rs+++ b/crates/external_services/src/grpc_client/dynamic_routing/success_rate_client.rs@@ -290,6 +290,7 @@ impl ForeignTryFrom<SuccessBasedRoutingConfigBody> for CalSuccessRateConfig {SuccessRateSpecificityLevel::Merchant => Some(ProtoSpecificityLevel::Entity.into()),SuccessRateSpecificityLevel::Global => Some(ProtoSpecificityLevel::Global.into()),},+ exploration_percent: config.exploration_percent,})}}diff --git a/crates/router/src/core/payments/routing.rs b/crates/router/src/core/payments/routing.rsindex b4ac7d4421..86925cff09 100644--- a/crates/router/src/core/payments/routing.rs+++ b/crates/router/src/core/payments/routing.rs@@ -1776,10 +1776,7 @@ pub async fn perform_decide_gateway_call_with_open_router())?;if let Some(gateway_priority_map) = decided_gateway.gateway_priority_map {- logger::debug!(- "open_router decide_gateway call response: {:?}",- gateway_priority_map- );+ logger::debug!(gateway_priority_map=?gateway_priority_map, routing_approach=decided_gateway.routing_approach, "open_router decide_gateway call response");routable_connectors.sort_by(|connector_choice_a, connector_choice_b| {let connector_choice_a_score = gateway_priority_map.get(&connector_choice_a.to_string())diff --git a/proto/success_rate.proto b/proto/success_rate.protoindex 17d566af35..efdd439cac 100644--- a/proto/success_rate.proto+++ b/proto/success_rate.proto@@ -23,6 +23,7 @@ message CalSuccessRateConfig {uint32 min_aggregates_size = 1;double default_success_rate = 2;optional SuccessRateSpecificityLevel specificity_level = 3;+ optional double exploration_percent = 4;}enum SuccessRateSpecificityLevel {@@ -32,6 +33,12 @@ enum SuccessRateSpecificityLevel {message CalSuccessRateResponse {repeated LabelWithScore labels_with_score = 1;+ RoutingApproach routing_approach = 2;+}++enum RoutingApproach {+ EXPLORATION = 0;+ EXPLOITATION = 1;}message LabelWithScore {