File size: 41,532 Bytes
cbf9f7a | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | {
"commit_sha": "8e8aecdf0cb8d9015daa6006be9c2454c3817f5d",
"pr_number": 10076,
"rust_files": [
"crates/router/src/core/unified_connector_service.rs"
],
"diffs": [
{
"id": "crates/router/src/core/unified_connector_service.rs::function::decide_execution_path",
"file": "crates/router/src/core/unified_connector_service.rs",
"kind": "function_item",
"status": "modified",
"code_changed": true,
"imports_changed": false,
"before_code": "fn decide_execution_path(\n connector_type: ConnectorIntegrationType,\n previous_gateway: Option<GatewaySystem>,\n shadow_rollout_enabled: ShadowRolloutAvailability,\n) -> RouterResult<(GatewaySystem, ExecutionPath)> {\n match (connector_type, previous_gateway, shadow_rollout_enabled) {\n // Case 1: DirectConnector with no previous gateway and no shadow rollout\n // This is a fresh payment request for a direct connector - use direct gateway\n (\n ConnectorIntegrationType::DirectConnector,\n None,\n ShadowRolloutAvailability::NotAvailable,\n ) => Ok((GatewaySystem::Direct, ExecutionPath::Direct)),\n\n // Case 2: DirectConnector previously used Direct gateway, no shadow rollout\n // Continue using the same direct gateway for consistency\n (\n ConnectorIntegrationType::DirectConnector,\n Some(GatewaySystem::Direct),\n ShadowRolloutAvailability::NotAvailable,\n ) => Ok((GatewaySystem::Direct, ExecutionPath::Direct)),\n\n // Case 3: DirectConnector previously used UCS, but now switching back to Direct (no shadow)\n // Migration scenario: UCS was used before, but now we're reverting to Direct\n (\n ConnectorIntegrationType::DirectConnector,\n Some(GatewaySystem::UnifiedConnectorService),\n ShadowRolloutAvailability::NotAvailable,\n ) => Ok((GatewaySystem::Direct, ExecutionPath::Direct)),\n\n // Case 4: UcsConnector configuration, but previously used Direct gateway (no shadow)\n // Maintain Direct for backward compatibility - don't switch mid-transaction\n (\n ConnectorIntegrationType::UcsConnector,\n Some(GatewaySystem::Direct),\n ShadowRolloutAvailability::NotAvailable,\n ) => Ok((GatewaySystem::Direct, ExecutionPath::Direct)),\n\n // Case 5: DirectConnector with no previous gateway, shadow rollout enabled\n // Use Direct as primary, but also execute UCS in shadow mode for comparison\n (\n ConnectorIntegrationType::DirectConnector,\n None,\n ShadowRolloutAvailability::IsAvailable,\n ) => Ok((\n GatewaySystem::Direct,\n ExecutionPath::ShadowUnifiedConnectorService,\n )),\n\n // Case 6: DirectConnector previously used Direct, shadow rollout enabled\n // Continue with Direct as primary, execute UCS in shadow mode for testing\n (\n ConnectorIntegrationType::DirectConnector,\n Some(GatewaySystem::Direct),\n ShadowRolloutAvailability::IsAvailable,\n ) => Ok((\n GatewaySystem::Direct,\n ExecutionPath::ShadowUnifiedConnectorService,\n )),\n\n // Case 7: DirectConnector previously used UCS, shadow rollout enabled\n // Revert to Direct as primary, but keep UCS in shadow mode for comparison\n (\n ConnectorIntegrationType::DirectConnector,\n Some(GatewaySystem::UnifiedConnectorService),\n ShadowRolloutAvailability::IsAvailable,\n ) => Ok((\n GatewaySystem::Direct,\n ExecutionPath::ShadowUnifiedConnectorService,\n )),\n\n // Case 8: UcsConnector configuration, previously used Direct, shadow rollout enabled\n // Maintain Direct as primary for transaction consistency, shadow UCS for testing\n (\n ConnectorIntegrationType::UcsConnector,\n Some(GatewaySystem::Direct),\n ShadowRolloutAvailability::IsAvailable,\n ) => Ok((\n GatewaySystem::Direct,\n ExecutionPath::ShadowUnifiedConnectorService,\n )),\n\n // Case 9a: UcsConnector with no previous gateway and shadow rollout enabled\n // Fresh payment for UCS-enabled connector with shadow mode - use shadow UCS\n (ConnectorIntegrationType::UcsConnector, None, ShadowRolloutAvailability::IsAvailable) => {\n Ok((\n GatewaySystem::UnifiedConnectorService,\n ExecutionPath::ShadowUnifiedConnectorService,\n ))\n }\n\n // Case 9b: UcsConnector with no previous gateway and no shadow rollout\n // Fresh payment for a UCS-enabled connector - use UCS as primary\n (ConnectorIntegrationType::UcsConnector, None, ShadowRolloutAvailability::NotAvailable) => {\n Ok((\n GatewaySystem::UnifiedConnectorService,\n ExecutionPath::UnifiedConnectorService,\n ))\n }\n\n // Case 10: UcsConnector previously used UCS (regardless of shadow rollout)\n // Continue using UCS for consistency in the payment flow\n (\n ConnectorIntegrationType::UcsConnector,\n Some(GatewaySystem::UnifiedConnectorService),\n _,\n ) => Ok((\n GatewaySystem::UnifiedConnectorService,\n ExecutionPath::UnifiedConnectorService,\n )),\n }\n}",
"after_code": "fn decide_execution_path(\n connector_type: ConnectorIntegrationType,\n previous_gateway: Option<GatewaySystem>,\n shadow_rollout_enabled: ShadowRolloutAvailability,\n) -> RouterResult<(GatewaySystem, ExecutionPath)> {\n match (connector_type, previous_gateway, shadow_rollout_enabled) {\n // Case 1: DirectConnector with no previous gateway and no shadow rollout\n // This is a fresh payment request for a direct connector - use direct gateway\n (\n ConnectorIntegrationType::DirectConnector,\n None,\n ShadowRolloutAvailability::NotAvailable,\n ) => Ok((GatewaySystem::Direct, ExecutionPath::Direct)),\n\n // Case 2: DirectConnector previously used Direct gateway, no shadow rollout\n // Continue using the same direct gateway for consistency\n (\n ConnectorIntegrationType::DirectConnector,\n Some(GatewaySystem::Direct),\n ShadowRolloutAvailability::NotAvailable,\n ) => Ok((GatewaySystem::Direct, ExecutionPath::Direct)),\n\n // Case 3: DirectConnector previously used UCS, but now switching back to Direct (no shadow)\n // Migration scenario: UCS was used before, but now we're reverting to Direct\n (\n ConnectorIntegrationType::DirectConnector,\n Some(GatewaySystem::UnifiedConnectorService),\n ShadowRolloutAvailability::NotAvailable,\n ) => Ok((GatewaySystem::Direct, ExecutionPath::Direct)),\n\n // Case 4: UcsConnector configuration, but previously used Direct gateway (no shadow)\n // Maintain Direct for backward compatibility - don't switch mid-transaction\n (\n ConnectorIntegrationType::UcsConnector,\n Some(GatewaySystem::Direct),\n ShadowRolloutAvailability::NotAvailable,\n ) => Ok((GatewaySystem::Direct, ExecutionPath::Direct)),\n\n // Case 5: DirectConnector with no previous gateway, shadow rollout enabled\n // Use Direct as primary, but also execute UCS in shadow mode for comparison\n (\n ConnectorIntegrationType::DirectConnector,\n None,\n ShadowRolloutAvailability::IsAvailable,\n ) => Ok((\n GatewaySystem::Direct,\n ExecutionPath::ShadowUnifiedConnectorService,\n )),\n\n // Case 6: DirectConnector previously used Direct, shadow rollout enabled\n // Continue with Direct as primary, execute UCS in shadow mode for testing\n (\n ConnectorIntegrationType::DirectConnector,\n Some(GatewaySystem::Direct),\n ShadowRolloutAvailability::IsAvailable,\n ) => Ok((\n GatewaySystem::Direct,\n ExecutionPath::ShadowUnifiedConnectorService,\n )),\n\n // Case 7: DirectConnector previously used UCS, shadow rollout enabled\n // Revert to Direct as primary, but keep UCS in shadow mode for comparison\n (\n ConnectorIntegrationType::DirectConnector,\n Some(GatewaySystem::UnifiedConnectorService),\n ShadowRolloutAvailability::IsAvailable,\n ) => Ok((\n GatewaySystem::Direct,\n ExecutionPath::ShadowUnifiedConnectorService,\n )),\n\n // Case 8: UcsConnector configuration, previously used Direct, shadow rollout enabled\n // Maintain Direct as primary for transaction consistency, shadow UCS for testing\n (\n ConnectorIntegrationType::UcsConnector,\n Some(GatewaySystem::Direct),\n ShadowRolloutAvailability::IsAvailable,\n ) => Ok((\n GatewaySystem::Direct,\n ExecutionPath::ShadowUnifiedConnectorService,\n )),\n\n // Case 9a: UcsConnector with no previous gateway and shadow rollout enabled\n // Fresh payment for UCS-enabled connector with shadow mode - use shadow UCS\n (ConnectorIntegrationType::UcsConnector, None, ShadowRolloutAvailability::IsAvailable) => {\n Ok((\n GatewaySystem::Direct,\n ExecutionPath::ShadowUnifiedConnectorService,\n ))\n }\n\n // Case 9b: UcsConnector with no previous gateway and no shadow rollout\n // Fresh payment for a UCS-enabled connector - use UCS as primary\n (ConnectorIntegrationType::UcsConnector, None, ShadowRolloutAvailability::NotAvailable) => {\n Ok((\n GatewaySystem::UnifiedConnectorService,\n ExecutionPath::UnifiedConnectorService,\n ))\n }\n\n // Case 10: UcsConnector previously used UCS (regardless of shadow rollout)\n // Continue using UCS for consistency in the payment flow\n (\n ConnectorIntegrationType::UcsConnector,\n Some(GatewaySystem::UnifiedConnectorService),\n _,\n ) => Ok((\n GatewaySystem::UnifiedConnectorService,\n ExecutionPath::UnifiedConnectorService,\n )),\n }\n}",
"diff_span": {
"before": " (ConnectorIntegrationType::UcsConnector, None, ShadowRolloutAvailability::IsAvailable) => {\n Ok((\n GatewaySystem::UnifiedConnectorService,\n ExecutionPath::ShadowUnifiedConnectorService,\n ))",
"after": " (ConnectorIntegrationType::UcsConnector, None, ShadowRolloutAvailability::IsAvailable) => {\n Ok((\n GatewaySystem::Direct,\n ExecutionPath::ShadowUnifiedConnectorService,\n ))"
},
"commit_sha": "8e8aecdf0cb8d9015daa6006be9c2454c3817f5d"
},
{
"id": "crates/router/src/core/unified_connector_service.rs::function::should_call_unified_connector_service_for_webhooks",
"file": "crates/router/src/core/unified_connector_service.rs",
"kind": "function_item",
"status": "modified",
"code_changed": true,
"imports_changed": false,
"before_code": "pub async fn should_call_unified_connector_service_for_webhooks(\n state: &SessionState,\n merchant_context: &MerchantContext,\n connector_name: &str,\n) -> RouterResult<ExecutionPath> {\n // Extract context information\n let merchant_id = merchant_context\n .get_merchant_account()\n .get_id()\n .get_string_repr();\n\n let connector_enum = Connector::from_str(connector_name)\n .change_context(errors::ApiErrorResponse::IncorrectConnectorNameGiven)\n .attach_printable_lazy(|| format!(\"Failed to parse connector name: {}\", connector_name))?;\n\n let flow_name = \"Webhooks\";\n\n // Check UCS availability using idiomatic helper\n let ucs_availability = check_ucs_availability(state).await;\n\n // Build rollout keys - webhooks don't use payment method, so use a simplified key format\n let rollout_key = format!(\n \"{}_{}_{}_{}\",\n consts::UCS_ROLLOUT_PERCENT_CONFIG_PREFIX,\n merchant_id,\n connector_name,\n flow_name\n );\n let shadow_rollout_key = format!(\"{rollout_key}_shadow\");\n\n // Determine connector integration type\n let connector_integration_type =\n determine_connector_integration_type(state, connector_enum, &rollout_key).await?;\n\n // For webhooks, there is no previous gateway system to consider (webhooks are stateless)\n let previous_gateway = None;\n\n // Check both rollout keys to determine priority based on shadow percentage\n let rollout_result = should_execute_based_on_rollout(state, &rollout_key).await?;\n let shadow_rollout_result = should_execute_based_on_rollout(state, &shadow_rollout_key).await?;\n\n // Get shadow percentage to determine priority\n let shadow_percentage = get_rollout_percentage(state, &shadow_rollout_key)\n .await\n .unwrap_or(0.0);\n\n let shadow_rollout_availability =\n if shadow_rollout_result.should_execute && shadow_percentage != 0.0 {\n // Shadow is present and percentage is non-zero, use shadow\n router_env::logger::debug!(\n shadow_percentage = shadow_percentage,\n \"Shadow rollout is present with non-zero percentage for webhooks, using shadow\"\n );\n ShadowRolloutAvailability::IsAvailable\n } else if rollout_result.should_execute {\n // Either shadow is 0.0 or not present, use rollout if available\n router_env::logger::debug!(\n shadow_percentage = shadow_percentage,\n \"Shadow rollout is 0.0 or not present for webhooks, using rollout\"\n );\n ShadowRolloutAvailability::IsAvailable\n } else {\n ShadowRolloutAvailability::NotAvailable\n };\n\n // Use the same decision logic as payments, with no call_connector_action to consider\n let (gateway_system, execution_path) = if ucs_availability == UcsAvailability::Disabled {\n router_env::logger::debug!(\"UCS is disabled for webhooks, using Direct gateway\");\n (GatewaySystem::Direct, ExecutionPath::Direct)\n } else {\n // UCS is enabled, use decide function with no previous gateway for webhooks\n decide_execution_path(\n connector_integration_type,\n previous_gateway,\n shadow_rollout_availability,\n )?\n };\n\n router_env::logger::info!(\n \"Webhook gateway decision: gateway={:?}, execution_path={:?} - merchant_id={}, connector={}, flow={}\",\n gateway_system,\n execution_path,\n merchant_id,\n connector_name,\n flow_name\n );\n\n Ok(execution_path)\n}",
"after_code": "pub async fn should_call_unified_connector_service_for_webhooks(\n state: &SessionState,\n merchant_context: &MerchantContext,\n connector_name: &str,\n) -> RouterResult<ExecutionPath> {\n // Extract context information\n let merchant_id = merchant_context\n .get_merchant_account()\n .get_id()\n .get_string_repr();\n\n let connector_enum = Connector::from_str(connector_name)\n .change_context(errors::ApiErrorResponse::IncorrectConnectorNameGiven)\n .attach_printable_lazy(|| format!(\"Failed to parse connector name: {}\", connector_name))?;\n\n let flow_name = \"Webhooks\";\n\n // Check UCS availability using idiomatic helper\n let ucs_availability = check_ucs_availability(state).await;\n\n // Build rollout keys - webhooks don't use payment method, so use a simplified key format\n let rollout_key = format!(\n \"{}_{}_{}_{}\",\n consts::UCS_ROLLOUT_PERCENT_CONFIG_PREFIX,\n merchant_id,\n connector_name,\n flow_name\n );\n let shadow_rollout_key = format!(\"{rollout_key}_shadow\");\n\n // Determine connector integration type\n let connector_integration_type =\n determine_connector_integration_type(state, connector_enum, &rollout_key).await?;\n\n // For webhooks, there is no previous gateway system to consider (webhooks are stateless)\n let previous_gateway = None;\n\n // Check both rollout keys to determine priority based on shadow percentage\n let rollout_result = should_execute_based_on_rollout(state, &rollout_key).await?;\n let shadow_rollout_result = should_execute_based_on_rollout(state, &shadow_rollout_key).await?;\n\n // Get shadow percentage to determine priority\n let (_shadow_key_exists, shadow_percentage) =\n get_rollout_config_info(state, &shadow_rollout_key).await;\n\n let shadow_rollout_availability =\n if shadow_rollout_result.should_execute && shadow_percentage.unwrap_or(0.0) != 0.0 {\n // Shadow is present and percentage is non-zero, use shadow\n router_env::logger::debug!(\n shadow_percentage = shadow_percentage.unwrap_or(0.0),\n \"Shadow rollout is present with non-zero percentage for webhooks, using shadow\"\n );\n ShadowRolloutAvailability::IsAvailable\n } else if rollout_result.should_execute {\n // Either shadow is 0.0 or not present, use rollout if available\n router_env::logger::debug!(\n shadow_percentage = shadow_percentage.unwrap_or(0.0),\n \"Shadow rollout is 0.0 or not present for webhooks, using rollout\"\n );\n ShadowRolloutAvailability::IsAvailable\n } else {\n ShadowRolloutAvailability::NotAvailable\n };\n\n // Use the same decision logic as payments, with no call_connector_action to consider\n let (gateway_system, execution_path) = if ucs_availability == UcsAvailability::Disabled {\n router_env::logger::debug!(\"UCS is disabled for webhooks, using Direct gateway\");\n (GatewaySystem::Direct, ExecutionPath::Direct)\n } else {\n // UCS is enabled, use decide function with no previous gateway for webhooks\n decide_execution_path(\n connector_integration_type,\n previous_gateway,\n shadow_rollout_availability,\n )?\n };\n\n router_env::logger::info!(\n \"Webhook gateway decision: gateway={:?}, execution_path={:?} - merchant_id={}, connector={}, flow={}\",\n gateway_system,\n execution_path,\n merchant_id,\n connector_name,\n flow_name\n );\n\n Ok(execution_path)\n}",
"diff_span": {
"before": "\n // Get shadow percentage to determine priority\n let shadow_percentage = get_rollout_percentage(state, &shadow_rollout_key)\n .await\n .unwrap_or(0.0);\n\n let shadow_rollout_availability =\n if shadow_rollout_result.should_execute && shadow_percentage != 0.0 {\n // Shadow is present and percentage is non-zero, use shadow\n router_env::logger::debug!(\n shadow_percentage = shadow_percentage,\n \"Shadow rollout is present with non-zero percentage for webhooks, using shadow\"\n );\n ShadowRolloutAvailability::IsAvailable\n } else if rollout_result.should_execute {\n // Either shadow is 0.0 or not present, use rollout if available\n router_env::logger::debug!(\n shadow_percentage = shadow_percentage,\n \"Shadow rollout is 0.0 or not present for webhooks, using rollout\"\n );",
"after": "\n // Get shadow percentage to determine priority\n let (_shadow_key_exists, shadow_percentage) =\n get_rollout_config_info(state, &shadow_rollout_key).await;\n\n let shadow_rollout_availability =\n if shadow_rollout_result.should_execute && shadow_percentage.unwrap_or(0.0) != 0.0 {\n // Shadow is present and percentage is non-zero, use shadow\n router_env::logger::debug!(\n shadow_percentage = shadow_percentage.unwrap_or(0.0),\n \"Shadow rollout is present with non-zero percentage for webhooks, using shadow\"\n );\n ShadowRolloutAvailability::IsAvailable\n } else if rollout_result.should_execute {\n // Either shadow is 0.0 or not present, use rollout if available\n router_env::logger::debug!(\n shadow_percentage = shadow_percentage.unwrap_or(0.0),\n \"Shadow rollout is 0.0 or not present for webhooks, using rollout\"\n );"
},
"commit_sha": "8e8aecdf0cb8d9015daa6006be9c2454c3817f5d"
},
{
"id": "crates/router/src/core/unified_connector_service.rs::function::should_call_unified_connector_service",
"file": "crates/router/src/core/unified_connector_service.rs",
"kind": "function_item",
"status": "modified",
"code_changed": true,
"imports_changed": false,
"before_code": "pub async fn should_call_unified_connector_service<F: Clone, T, R, D>(\n state: &SessionState,\n merchant_context: &MerchantContext,\n router_data: &RouterData<F, T, R>,\n payment_data: Option<&D>,\n call_connector_action: CallConnectorAction,\n shadow_ucs_call_connector_action: Option<CallConnectorAction>,\n) -> RouterResult<(ExecutionPath, SessionState)>\nwhere\n D: OperationSessionGetters<F>,\n R: Send + Sync + Clone,\n{\n // Extract context information\n let merchant_id = merchant_context\n .get_merchant_account()\n .get_id()\n .get_string_repr();\n\n let connector_name = &router_data.connector;\n let connector_enum = Connector::from_str(connector_name)\n .change_context(errors::ApiErrorResponse::IncorrectConnectorNameGiven)\n .attach_printable_lazy(|| format!(\"Failed to parse connector name: {connector_name}\"))?;\n\n let flow_name = get_flow_name::<F>()?;\n\n // Check UCS availability using idiomatic helper\n let ucs_availability = check_ucs_availability(state).await;\n\n let (rollout_key, shadow_rollout_key) = build_rollout_keys(\n merchant_id,\n connector_name,\n &flow_name,\n router_data.payment_method,\n );\n\n // Determine connector integration type\n let connector_integration_type =\n determine_connector_integration_type(state, connector_enum, &rollout_key).await?;\n\n // Extract previous gateway from payment data\n let previous_gateway = payment_data.and_then(extract_gateway_system_from_payment_intent);\n\n // Check both rollout keys to determine priority based on shadow percentage\n let rollout_result = should_execute_based_on_rollout(state, &rollout_key).await?;\n let shadow_rollout_result = should_execute_based_on_rollout(state, &shadow_rollout_key).await?;\n\n // Get shadow percentage to determine priority\n let shadow_percentage = get_rollout_percentage(state, &shadow_rollout_key)\n .await\n .unwrap_or(0.0);\n\n let shadow_rollout_availability =\n if shadow_rollout_result.should_execute && shadow_percentage != 0.0 {\n // Shadow is present and percentage is non-zero, use shadow\n router_env::logger::debug!(\n shadow_percentage = shadow_percentage,\n \"Shadow rollout is present with non-zero percentage, using shadow\"\n );\n ShadowRolloutAvailability::IsAvailable\n } else if rollout_result.should_execute {\n // Either shadow is 0.0 or not present, use rollout if available\n router_env::logger::debug!(\n shadow_percentage = shadow_percentage,\n \"Shadow rollout is 0.0 or not present, using rollout\"\n );\n ShadowRolloutAvailability::IsAvailable\n } else {\n ShadowRolloutAvailability::NotAvailable\n };\n\n // Single decision point using pattern matching\n let (gateway_system, execution_path) = if ucs_availability == UcsAvailability::Disabled {\n match call_connector_action {\n CallConnectorAction::UCSConsumeResponse(_)\n | CallConnectorAction::UCSHandleResponse(_) => {\n Err(errors::ApiErrorResponse::InternalServerError)\n .attach_printable(\"CallConnectorAction UCSHandleResponse/UCSConsumeResponse received but UCS is disabled. These actions are only valid in UCS gateway\")?\n }\n CallConnectorAction::Avoid\n | CallConnectorAction::Trigger\n | CallConnectorAction::HandleResponse(_)\n | CallConnectorAction::StatusUpdate { .. } => {\n router_env::logger::debug!(\"UCS is disabled, using Direct gateway\");\n (GatewaySystem::Direct, ExecutionPath::Direct)\n }\n }\n } else {\n match call_connector_action {\n CallConnectorAction::UCSConsumeResponse(_)\n | CallConnectorAction::UCSHandleResponse(_) => {\n router_env::logger::info!(\"CallConnectorAction UCSHandleResponse/UCSConsumeResponse received, using UCS gateway\");\n (\n GatewaySystem::UnifiedConnectorService,\n ExecutionPath::UnifiedConnectorService,\n )\n }\n CallConnectorAction::HandleResponse(_) => {\n router_env::logger::info!(\n \"CallConnectorAction HandleResponse received, using Direct gateway\"\n );\n if shadow_ucs_call_connector_action.is_some() {\n (\n GatewaySystem::Direct,\n ExecutionPath::ShadowUnifiedConnectorService,\n )\n } else {\n (GatewaySystem::Direct, ExecutionPath::Direct)\n }\n }\n CallConnectorAction::Trigger\n | CallConnectorAction::Avoid\n | CallConnectorAction::StatusUpdate { .. } => {\n // UCS is enabled, call decide function\n decide_execution_path(\n connector_integration_type,\n previous_gateway,\n shadow_rollout_availability,\n )?\n }\n }\n };\n\n router_env::logger::info!(\n \"Payment gateway decision: gateway={:?}, execution_path={:?} - merchant_id={}, connector={}, flow={}\",\n gateway_system,\n execution_path,\n merchant_id,\n connector_name,\n flow_name\n );\n\n // Handle proxy configuration for Shadow UCS flows\n let session_state = match execution_path {\n ExecutionPath::ShadowUnifiedConnectorService => {\n // For shadow UCS, use rollout_result for proxy configuration since it takes priority\n match &rollout_result.proxy_override {\n Some(proxy_override) => {\n router_env::logger::debug!(\n proxy_override = ?proxy_override,\n \"Creating updated session state with proxy configuration for Shadow UCS\"\n );\n create_updated_session_state_with_proxy(state.clone(), proxy_override)\n }\n None => {\n router_env::logger::debug!(\n \"No proxy override available for Shadow UCS, using original state\"\n );\n state.clone()\n }\n }\n }\n _ => {\n // For Direct and UCS flows, use original state\n state.clone()\n }\n };\n\n Ok((execution_path, session_state))\n}",
"after_code": "pub async fn should_call_unified_connector_service<F: Clone, T, R, D>(\n state: &SessionState,\n merchant_context: &MerchantContext,\n router_data: &RouterData<F, T, R>,\n payment_data: Option<&D>,\n call_connector_action: CallConnectorAction,\n shadow_ucs_call_connector_action: Option<CallConnectorAction>,\n) -> RouterResult<(ExecutionPath, SessionState)>\nwhere\n D: OperationSessionGetters<F>,\n R: Send + Sync + Clone,\n{\n // Extract context information\n let merchant_id = merchant_context\n .get_merchant_account()\n .get_id()\n .get_string_repr();\n\n let connector_name = &router_data.connector;\n let connector_enum = Connector::from_str(connector_name)\n .change_context(errors::ApiErrorResponse::IncorrectConnectorNameGiven)\n .attach_printable_lazy(|| format!(\"Failed to parse connector name: {connector_name}\"))?;\n\n let flow_name = get_flow_name::<F>()?;\n\n // Check UCS availability using idiomatic helper\n let ucs_availability = check_ucs_availability(state).await;\n\n let (rollout_key, shadow_rollout_key) = build_rollout_keys(\n merchant_id,\n connector_name,\n &flow_name,\n router_data.payment_method,\n );\n\n // Determine connector integration type\n let connector_integration_type =\n determine_connector_integration_type(state, connector_enum, &rollout_key).await?;\n\n // Extract previous gateway from payment data\n let previous_gateway = payment_data.and_then(extract_gateway_system_from_payment_intent);\n\n // Check rollout key availability and shadow key presence (optimized to reduce DB calls)\n let rollout_result = should_execute_based_on_rollout(state, &rollout_key).await?;\n let (shadow_key_exists, _shadow_percentage) =\n get_rollout_config_info(state, &shadow_rollout_key).await;\n\n // Simplified decision logic: Shadow takes priority, then rollout, then direct\n let shadow_rollout_availability = if shadow_key_exists {\n // Block 1: Shadow key exists - check if it's enabled\n let shadow_percentage = _shadow_percentage.unwrap_or(0.0);\n\n if shadow_percentage != 0.0 {\n router_env::logger::debug!( shadow_key = %shadow_rollout_key, shadow_percentage = shadow_percentage, \"Shadow key enabled, using shadow mode for comparison\" );\n ShadowRolloutAvailability::IsAvailable\n } else {\n router_env::logger::debug!(\n shadow_key = %shadow_rollout_key,\n shadow_percentage = shadow_percentage,\n rollout_enabled = rollout_result.should_execute,\n \"Shadow key exists but disabled (0.0%), falling back to rollout or direct\"\n );\n // Shadow disabled, result is the same regardless of rollout status\n ShadowRolloutAvailability::NotAvailable\n }\n } else if rollout_result.should_execute {\n // Block 2: No shadow key, but rollout is enabled - use primary UCS\n router_env::logger::debug!( rollout_key = %rollout_key, \"No shadow key, rollout enabled, using primary UCS mode\" );\n ShadowRolloutAvailability::NotAvailable\n } else {\n // Block 3: Neither shadow nor rollout enabled - use direct\n router_env::logger::debug!( rollout_key = %rollout_key, shadow_key = %shadow_rollout_key, \"Neither shadow nor rollout enabled, using Direct mode\" );\n ShadowRolloutAvailability::NotAvailable\n };\n\n // Single decision point using pattern matching\n let (gateway_system, execution_path) = if ucs_availability == UcsAvailability::Disabled {\n match call_connector_action {\n CallConnectorAction::UCSConsumeResponse(_)\n | CallConnectorAction::UCSHandleResponse(_) => {\n Err(errors::ApiErrorResponse::InternalServerError)\n .attach_printable(\"CallConnectorAction UCSHandleResponse/UCSConsumeResponse received but UCS is disabled. These actions are only valid in UCS gateway\")?\n }\n CallConnectorAction::Avoid\n | CallConnectorAction::Trigger\n | CallConnectorAction::HandleResponse(_)\n | CallConnectorAction::StatusUpdate { .. } => {\n router_env::logger::debug!(\"UCS is disabled, using Direct gateway\");\n (GatewaySystem::Direct, ExecutionPath::Direct)\n }\n }\n } else {\n match call_connector_action {\n CallConnectorAction::UCSConsumeResponse(_)\n | CallConnectorAction::UCSHandleResponse(_) => {\n router_env::logger::info!(\"CallConnectorAction UCSHandleResponse/UCSConsumeResponse received, using UCS gateway\");\n (\n GatewaySystem::UnifiedConnectorService,\n ExecutionPath::UnifiedConnectorService,\n )\n }\n CallConnectorAction::HandleResponse(_) => {\n router_env::logger::info!(\n \"CallConnectorAction HandleResponse received, using Direct gateway\"\n );\n if shadow_ucs_call_connector_action.is_some() {\n (\n GatewaySystem::Direct,\n ExecutionPath::ShadowUnifiedConnectorService,\n )\n } else {\n (GatewaySystem::Direct, ExecutionPath::Direct)\n }\n }\n CallConnectorAction::Trigger\n | CallConnectorAction::Avoid\n | CallConnectorAction::StatusUpdate { .. } => {\n // UCS is enabled, call decide function\n decide_execution_path(\n connector_integration_type,\n previous_gateway,\n shadow_rollout_availability,\n )?\n }\n }\n };\n\n router_env::logger::info!(\n \"Payment gateway decision: gateway={:?}, execution_path={:?} - merchant_id={}, connector={}, flow={}\",\n gateway_system,\n execution_path,\n merchant_id,\n connector_name,\n flow_name\n );\n\n // Handle proxy configuration for Shadow UCS flows\n let session_state = match execution_path {\n ExecutionPath::ShadowUnifiedConnectorService => {\n // For shadow UCS, use rollout_result for proxy configuration since it takes priority\n match &rollout_result.proxy_override {\n Some(proxy_override) => {\n router_env::logger::debug!(\n proxy_override = ?proxy_override,\n \"Creating updated session state with proxy configuration for Shadow UCS\"\n );\n create_updated_session_state_with_proxy(state.clone(), proxy_override)\n }\n None => {\n router_env::logger::debug!(\n \"No proxy override available for Shadow UCS, using original state\"\n );\n state.clone()\n }\n }\n }\n _ => {\n // For Direct and UCS flows, use original state\n state.clone()\n }\n };\n\n Ok((execution_path, session_state))\n}",
"diff_span": {
"before": " let previous_gateway = payment_data.and_then(extract_gateway_system_from_payment_intent);\n\n // Check both rollout keys to determine priority based on shadow percentage\n let rollout_result = should_execute_based_on_rollout(state, &rollout_key).await?;\n let shadow_rollout_result = should_execute_based_on_rollout(state, &shadow_rollout_key).await?;\n\n // Get shadow percentage to determine priority\n let shadow_percentage = get_rollout_percentage(state, &shadow_rollout_key)\n .await\n .unwrap_or(0.0);\n\n let shadow_rollout_availability =\n if shadow_rollout_result.should_execute && shadow_percentage != 0.0 {\n // Shadow is present and percentage is non-zero, use shadow\n router_env::logger::debug!(\n shadow_percentage = shadow_percentage,\n \"Shadow rollout is present with non-zero percentage, using shadow\"\n );\n ShadowRolloutAvailability::IsAvailable\n } else if rollout_result.should_execute {\n // Either shadow is 0.0 or not present, use rollout if available\n router_env::logger::debug!(\n shadow_percentage = shadow_percentage,\n \"Shadow rollout is 0.0 or not present, using rollout\"\n );\n ShadowRolloutAvailability::IsAvailable\n } else {\n ShadowRolloutAvailability::NotAvailable\n };\n\n // Single decision point using pattern matching",
"after": " let previous_gateway = payment_data.and_then(extract_gateway_system_from_payment_intent);\n\n // Check rollout key availability and shadow key presence (optimized to reduce DB calls)\n let rollout_result = should_execute_based_on_rollout(state, &rollout_key).await?;\n let (shadow_key_exists, _shadow_percentage) =\n get_rollout_config_info(state, &shadow_rollout_key).await;\n\n // Simplified decision logic: Shadow takes priority, then rollout, then direct\n let shadow_rollout_availability = if shadow_key_exists {\n // Block 1: Shadow key exists - check if it's enabled\n let shadow_percentage = _shadow_percentage.unwrap_or(0.0);\n\n if shadow_percentage != 0.0 {\n router_env::logger::debug!( shadow_key = %shadow_rollout_key, shadow_percentage = shadow_percentage, \"Shadow key enabled, using shadow mode for comparison\" );\n ShadowRolloutAvailability::IsAvailable\n } else {\n router_env::logger::debug!(\n shadow_key = %shadow_rollout_key,\n shadow_percentage = shadow_percentage,\n rollout_enabled = rollout_result.should_execute,\n \"Shadow key exists but disabled (0.0%), falling back to rollout or direct\"\n );\n // Shadow disabled, result is the same regardless of rollout status\n ShadowRolloutAvailability::NotAvailable\n }\n } else if rollout_result.should_execute {\n // Block 2: No shadow key, but rollout is enabled - use primary UCS\n router_env::logger::debug!( rollout_key = %rollout_key, \"No shadow key, rollout enabled, using primary UCS mode\" );\n ShadowRolloutAvailability::NotAvailable\n } else {\n // Block 3: Neither shadow nor rollout enabled - use direct\n router_env::logger::debug!( rollout_key = %rollout_key, shadow_key = %shadow_rollout_key, \"Neither shadow nor rollout enabled, using Direct mode\" );\n ShadowRolloutAvailability::NotAvailable\n };\n\n // Single decision point using pattern matching"
},
"commit_sha": "8e8aecdf0cb8d9015daa6006be9c2454c3817f5d"
},
{
"id": "crates/router/src/core/unified_connector_service.rs::function::get_rollout_config_info",
"file": "crates/router/src/core/unified_connector_service.rs",
"kind": "function_item",
"status": "added",
"before_code": null,
"after_code": "async fn get_rollout_config_info(state: &SessionState, config_key: &str) -> (bool, Option<f64>) {\n let db = state.store.as_ref();\n\n match db.find_config_by_key(config_key).await {\n Ok(rollout_config) => {\n // Key exists, try to parse percentage\n let percentage =\n match serde_json::from_str::<helpers::RolloutConfig>(&rollout_config.config) {\n Ok(config) => Some(config.rollout_percent),\n Err(_) => {\n // Fallback to legacy format (simple float)\n rollout_config.config.parse::<f64>().ok()\n }\n };\n (true, percentage)\n }\n Err(_) => (false, None), // Key doesn't exist\n }\n}",
"diff_span": null,
"commit_sha": "8e8aecdf0cb8d9015daa6006be9c2454c3817f5d"
},
{
"id": "crates/router/src/core/unified_connector_service.rs::function::get_rollout_percentage",
"file": "crates/router/src/core/unified_connector_service.rs",
"kind": "function_item",
"status": "removed",
"before_code": "async fn get_rollout_percentage(state: &SessionState, config_key: &str) -> Option<f64> {\n let db = state.store.as_ref();\n\n match db.find_config_by_key(config_key).await {\n Ok(rollout_config) => {\n // Try to parse as JSON first (new format), fallback to float (legacy format)\n match serde_json::from_str::<helpers::RolloutConfig>(&rollout_config.config) {\n Ok(config) => Some(config.rollout_percent),\n Err(_) => {\n // Fallback to legacy format (simple float)\n rollout_config.config.parse::<f64>().ok()\n }\n }\n }\n Err(_) => None,\n }\n}",
"after_code": null,
"diff_span": null,
"commit_sha": "8e8aecdf0cb8d9015daa6006be9c2454c3817f5d"
}
]
} |