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

Code before:
    network_tokenization_supported_connectors: &HashSet<api_enums::Connector>,
    should_retry_with_pan: bool,
    network_token_requestor_ref_id: Option<String>,
) -> VaultFetchAction {
    let standard_flow = || {
        determine_standard_vault_action(
            is_network_tokenization_enabled,
            mandate_id,
            connector,
            network_tokenization_supported_connectors,
            network_token_requestor_ref_id,
        )
    };

    if should_retry_with_pan {
        VaultFetchAction::FetchCardDetailsFromLocker
    } else {
        standard_flow()
    }
}

pub async fn is_ucs_enabled(state: &SessionState, config_key: &str) -> bool {
    let db = state.store.as_ref();
    let is_enabled = db
        .find_config_by_key_unwrap_or(config_key, Some("false".to_string()))
        .await
        .map_err(|error| {
            logger::error!(
                ?error,
                "Failed to fetch `{config_key}` UCS enabled config from DB"
            );
        })
        .and_then(|config| {
            config.config.parse::<bool>().map_err(|error| {
                logger::error!(?error, "Failed to parse `{config_key}` UCS enabled config");
            })
        })
        .unwrap_or(false);

    is_enabled
}

pub async fn should_execute_based_on_rollout(
    state: &SessionState,
    config_key: &str,
) -> RouterResult<bool> {
    let db = state.store.as_ref();

    match db.find_config_by_key(config_key).await {
        Ok(rollout_config) => match rollout_config.config.parse::<f64>() {
            Ok(rollout_percent) => {

Review comment (suggestion):
use inspect if not mapping errors.
https://doc.rust-lang.org/std/result/enum.Result.html#method.inspect_err

Code after:
    network_tokenization_supported_connectors: &HashSet<api_enums::Connector>,
    should_retry_with_pan: bool,
    network_token_requestor_ref_id: Option<String>,
) -> VaultFetchAction {
    let standard_flow = || {
        determine_standard_vault_action(
            is_network_tokenization_enabled,
            mandate_id,
            connector,
            network_tokenization_supported_connectors,
            network_token_requestor_ref_id,
        )
    };

    if should_retry_with_pan {
        VaultFetchAction::FetchCardDetailsFromLocker
    } else {
        standard_flow()
    }
}

pub async fn is_ucs_enabled(state: &SessionState, config_key: &str) -> bool {
    let db = state.store.as_ref();
    db.find_config_by_key_unwrap_or(config_key, Some("false".to_string()))
        .await
        .map_err(|error| {
            logger::error!(
                ?error,
                "Failed to fetch `{config_key}` UCS enabled config from DB"
            );
        })
        .and_then(|config| {
            config.config.parse::<bool>().map_err(|error| {
                logger::error!(?error, "Failed to parse `{config_key}` UCS enabled config");
            })
        })
        .unwrap_or(false)
}

pub async fn should_execute_based_on_rollout(
    state: &SessionState,
    config_key: &str,
) -> RouterResult<bool> {
    let db = state.store.as_ref();

    match db.find_config_by_key(config_key).await {
        Ok(rollout_config) => match rollout_config.config.parse::<f64>() {
            Ok(rollout_percent) => {
                if !(0.0..=1.0).contains(&rollout_percent) {
                    logger::warn!(
                        rollout_percent,