Bug: refactor(routing): update configs on updation of mca




diff --git a/crates/router/src/core/admin.rs b/crates/router/src/core/admin.rs
index 30f70943487..9652bfdd529 100644
--- a/crates/router/src/core/admin.rs
+++ b/crates/router/src/core/admin.rs
@@ -23,7 +23,7 @@ use masking::{ExposeInterface, PeekInterface, Secret};
 use pm_auth::types as pm_auth_types;
 use uuid::Uuid;
 
-use super::routing::helpers::{redact_cgraph_cache, update_default_fallback_on_mca_update};
+use super::routing::helpers::redact_cgraph_cache;
 #[cfg(any(feature = "v1", feature = "v2"))]
 use crate::types::transformers::ForeignFrom;
 use crate::{
@@ -2873,7 +2873,7 @@ pub async fn update_connector(
     let updated_mca = db
         .update_merchant_connector_account(
             key_manager_state,
-            mca,
+            mca.clone(),
             payment_connector.into(),
             &key_store,
         )
@@ -2894,8 +2894,33 @@ pub async fn update_connector(
     // redact cgraph cache on connector updation
     redact_cgraph_cache(&state, merchant_id, &profile_id).await?;
 
-    // update default fallback config
-    update_default_fallback_on_mca_update(&state, merchant_id, &profile_id, &updated_mca).await?;
+    // redact routing cache on connector updation
+    #[cfg(feature = "v1")]
+    let merchant_config = MerchantDefaultConfigUpdate {
+        routable_connector: &Some(
+            common_enums::RoutableConnectors::from_str(&mca.connector_name).map_err(|_| {
+                errors::ApiErrorResponse::InvalidDataValue {
+                    field_name: "connector_name",
+                }
+            })?,
+        ),
+        merchant_connector_id: &mca.get_id(),
+        store: db,
+        merchant_id,
+        profile_id: &mca.profile_id,
+        transaction_type: &mca.connector_type.into(),
+    };
+
+    #[cfg(feature = "v1")]
+    if req.disabled.unwrap_or(false) {
+        merchant_config
+            .retrieve_and_delete_from_default_fallback_routing_algorithm_if_routable_connector_exists()
+            .await?;
+    } else {
+        merchant_config
+            .retrieve_and_update_default_fallback_routing_algorithm_if_routable_connector_exists()
+            .await?;
+    }
 
     let response = updated_mca.foreign_try_into()?;
 
diff --git a/crates/router/src/core/routing/helpers.rs b/crates/router/src/core/routing/helpers.rs
index 03e24ca2bf1..e5671e2edb3 100644
--- a/crates/router/src/core/routing/helpers.rs
+++ b/crates/router/src/core/routing/helpers.rs
@@ -2,9 +2,11 @@
 //!
 //! Functions that are used to perform the retrieval of merchant's
 //! routing dict, configs, defaults
+use std::fmt::Debug;
+#[cfg(all(feature = "dynamic_routing", feature = "v1"))]
+use std::str::FromStr;
 #[cfg(all(feature = "dynamic_routing", feature = "v1"))]
 use std::sync::Arc;
-use std::{fmt::Debug, str::FromStr};
 
 #[cfg(feature = "v1")]
 use api_models::open_router;
@@ -2788,50 +2790,3 @@ pub async fn redact_routing_cache(
 
     Ok(())
 }
-
-pub async fn update_default_fallback_on_mca_update(
-    state: &SessionState,
-    merchant_id: &id_type::MerchantId,
-    profile_id: &id_type::ProfileId,
-    updated_mca: &hyperswitch_domain_models::merchant_connector_account::MerchantConnectorAccount,
-) -> RouterResult<()> {
-    let db = state.store.as_ref();
-    let merchant_id_str = merchant_id.get_string_repr();
-    let profile_id_str = profile_id.get_string_repr();
-    let txn_type = &storage::enums::TransactionType::from(updated_mca.connector_type);
-
-    let mut connectors = get_merchant_default_config(db, merchant_id_str, txn_type).await?;
-
-    let choice = routing_types::RoutableConnectorChoice {
-        choice_kind: routing_types::RoutableChoiceKind::FullStruct,
-        connector: api_models::enums::RoutableConnectors::from_str(
-            &updated_mca.connector_name.to_string(),
-        )
-        .change_context(errors::ApiErrorResponse::IncorrectConnectorNameGiven)
-        .attach_printable(format!(
-            "Unable to parse RoutableConnectors from connector: {}",
-            updated_mca.connector_name
-        ))?,
-        merchant_connector_id: Some(updated_mca.get_id().clone()),
-    };
-
-    if updated_mca.disabled.unwrap_or(false)
-        || updated_mca.status == api_models::enums::ConnectorStatus::Inactive
-    {
-        // remove if disabled
-        connectors.retain(|c| c.merchant_connector_id != Some(updated_mca.get_id().clone()));
-    } else {
-        // ensure it is present if enabled
-        if !connectors.contains(&choice) {
-            connectors.push(choice);
-        }
-    }
-
-    // update merchant config
-    update_merchant_default_config(db, merchant_id_str, connectors.clone(), txn_type).await?;
-
-    // update profile config
-    update_merchant_default_config(db, profile_id_str, connectors, txn_type).await?;
-
-    Ok(())
-}

## Type of Change
<!-- Put an `x` in the boxes that apply -->

- [ ] Bugfix
- [ ] New feature
- [ ] Enhancement
- [ ] Refactoring
- [ ] Dependency updates
- [ ] Documentation
- [ ] CI/CD

## Description
<!-- Describe your changes in detail -->
This pull request refactors how the default fallback routing configuration is updated when a merchant connector account is modified. Instead of calling the old helper function, the logic is now handled through a new `MerchantDefaultConfigUpdate` struct with methods that more explicitly update or remove the connector from the routing algorithm, depending on whether the connector is disabled. The changes also ensure that the connector update uses a clone of the merchant connector account object.

**Routing configuration update refactor:**

* Replaces the old `update_default_fallback_on_mca_update` helper with explicit logic using the `MerchantDefaultConfigUpdate` struct, which updates or deletes the connector from the default fallback routing algorithm based on the connector's status. This makes the update process more modular and easier to maintain. [[1]](diffhunk://#diff-7e1b4a44fadc4de1af2a6abeb318b3ddf044177c44ba00731c33dbf4cdce92b7L2894-R2920) [[2]](diffhunk://#diff-ea48d33e52b2cb7edbbba1d236b55f946fdb2c178f8c76f4226818b3630c4658L2791-L2837)
* Removes the now-unused `update_default_fallback_on_mca_update` function from `routing/helpers.rs`.

**Code quality and correctness:**

* Ensures the `update_merchant_connector_account` call receives a clone of the `mca` object, preventing potential issues with ownership or mutation.
* Cleans up imports by removing the now-unused `update_default_fallback_on_mca_update` import.
<!-- Describe your changes in detail -->

### Additional Changes

- [ ] This PR modifies the API contract
- [ ] This PR modifies the database schema
- [ ] This PR modifies application configuration/environment variables

<!--
Provide links to the files with corresponding changes.

Following are the paths where you can find config files:
1. `config`
2. `crates/router/src/configs`
3. `loadtest/config`
-->


## Motivation and Context
<!--
Why is this change required? What problem does it solve?
If it fixes an open issue, please link to the issue here.

If you don't have an issue, we'd recommend starting with one first so the PR
can focus on the implementation (unless it is an obvious bug or documentation fix
that will have little conversation).
-->


## How did you test it?
<!--
Did you write an integration/unit/API test to verify the code changes?
Or did you test this change manually (provide relevant screenshots)?
-->


## Checklist
<!-- Put an `x` in the boxes that apply -->

- [ ] I formatted the code `cargo +nightly fmt --all`
- [ ] I addressed lints thrown by `cargo clippy`
- [ ] I reviewed the submitted code
- [ ] I added unit tests for my changes where possible
