Repository: juspay/hyperswitch
File: crates/router/src/core/unified_connector_service.rs (Rust)

Code before:
    proxy_override: &ProxyOverride,
) -> SessionState {
    let mut updated_state = state.clone();

    // Update the proxy configuration with overrides
    let updated_proxy = hyperswitch_interfaces::types::Proxy {
        http_url: proxy_override
            .http_url
            .clone()
            .or(state.conf.proxy.http_url.clone()),
        https_url: proxy_override
            .https_url
            .clone()
            .or(state.conf.proxy.https_url.clone()),
        idle_pool_connection_timeout: state.conf.proxy.idle_pool_connection_timeout,
        bypass_proxy_hosts: state.conf.proxy.bypass_proxy_hosts.clone(),
        mitm_ca_certificate: state.conf.proxy.mitm_ca_certificate.clone(),
        mitm_enabled: state.conf.proxy.mitm_enabled,
    };

    // Create updated configuration
    let mut updated_conf = (*state.conf).clone();
    updated_conf.proxy = updated_proxy;
    updated_state.conf = std::sync::Arc::new(updated_conf);

    updated_state
}

/// Extracts the gateway system from the payment intent's feature metadata
/// Returns None if metadata is missing, corrupted, or doesn't contain gateway_system
fn extract_gateway_system_from_payment_intent<F: Clone, D>(
    payment_data: &D,
) -> Option<GatewaySystem>
where
    D: OperationSessionGetters<F>,
{
    #[cfg(feature = "v1")]
    {
        payment_data
            .get_payment_intent()
            .feature_metadata
            .as_ref()
            .and_then(|metadata| {
                // Try to parse the JSON value as FeatureMetadata
                // Log errors but don't fail the flow for corrupted metadata
                match serde_json::from_value::<FeatureMetadata>(metadata.clone()) {
                    Ok(feature_metadata) => feature_metadata.gateway_system,
                    Err(err) => {
                        router_env::logger::warn!(
                            "Failed to parse feature_metadata for gateway_system extraction: {}",
                            err

Review comment (suggestion):
```suggestion
    // Update the proxy configuration with overrides
    updated_state.conf.proxy.http_url = proxy_override
            .http_url
            .clone()
            .or(state.conf.proxy.http_url.clone());
      updated_state.conf.proxy.https_url = proxy_override
            .https_url
            .clone()
            .or(state.conf.proxy.https_url.clone()),

```

Code after:
            None,
            ShadowRolloutAvailability::IsAvailable,
        ) => Ok((
            GatewaySystem::Direct,
            ExecutionPath::ShadowUnifiedConnectorService,
        )),

        // Case 6: DirectConnector previously used Direct, shadow rollout enabled
        // Continue with Direct as primary, execute UCS in shadow mode for testing
        (
            ConnectorIntegrationType::DirectConnector,
            Some(GatewaySystem::Direct),
            ShadowRolloutAvailability::IsAvailable,
        ) => Ok((
            GatewaySystem::Direct,
            ExecutionPath::ShadowUnifiedConnectorService,
        )),

        // Case 7: DirectConnector previously used UCS, shadow rollout enabled
        // Revert to Direct as primary, but keep UCS in shadow mode for comparison
        (
            ConnectorIntegrationType::DirectConnector,
            Some(GatewaySystem::UnifiedConnectorService),
            ShadowRolloutAvailability::IsAvailable,
        ) => Ok((
            GatewaySystem::Direct,
            ExecutionPath::ShadowUnifiedConnectorService,
        )),

        // Case 8: UcsConnector configuration, previously used Direct, shadow rollout enabled
        // Maintain Direct as primary for transaction consistency, shadow UCS for testing
        (
            ConnectorIntegrationType::UcsConnector,
            Some(GatewaySystem::Direct),
            ShadowRolloutAvailability::IsAvailable,
        ) => Ok((
            GatewaySystem::Direct,
            ExecutionPath::ShadowUnifiedConnectorService,
        )),

        // Case 9a: UcsConnector with no previous gateway and shadow rollout enabled
        // Fresh payment for UCS-enabled connector with shadow mode - use shadow UCS
        (ConnectorIntegrationType::UcsConnector, None, ShadowRolloutAvailability::IsAvailable) => {
            Ok((
                GatewaySystem::UnifiedConnectorService,
                ExecutionPath::ShadowUnifiedConnectorService,
            ))
        }

        // Case 9b: UcsConnector with no previous gateway and no shadow rollout
        // Fresh payment for a UCS-enabled connector - use UCS as primary