Bug: [REFACTOR] Refactor update and retrieve of fallback api-v2



### Feature Description

 Refactor update and retrieve of fallback api-v2

### Possible Implementation

Refactor update and retrieve of fallback api-v2

### Have you spent some time checking if this feature request has been raised before?

- [X] I checked and didn't find a similar issue

### Have you read the Contributing Guidelines?

- [X] I have read the [Contributing Guidelines](https://github.com/juspay/hyperswitch/blob/main/docs/CONTRIBUTING.md)

### Are you willing to submit a PR?

Yes, I am willing to submit a PR!
diff --git a/crates/diesel_models/src/business_profile.rs b/crates/diesel_models/src/business_profile.rs
index bb4aa21cda6..cf873d4b61f 100644
--- a/crates/diesel_models/src/business_profile.rs
+++ b/crates/diesel_models/src/business_profile.rs
@@ -251,7 +251,7 @@ pub struct BusinessProfile {
     // pub order_fulfillment_time_origin: Option<OrderFulfillmentTimeOrigin>,
     pub frm_routing_algorithm_id: Option<String>,
     pub payout_routing_algorithm_id: Option<String>,
-    // pub default_fallback_routing: Option<pii::SecretSerdeValue>,
+    pub default_fallback_routing: Option<pii::SecretSerdeValue>,
 }
 
 #[cfg(all(feature = "v2", feature = "business_profile_v2"))]
@@ -289,7 +289,7 @@ pub struct BusinessProfileNew {
     // pub order_fulfillment_time_origin: Option<OrderFulfillmentTimeOrigin>,
     pub frm_routing_algorithm_id: Option<String>,
     pub payout_routing_algorithm_id: Option<String>,
-    // pub default_fallback_routing: Option<pii::SecretSerdeValue>,
+    pub default_fallback_routing: Option<pii::SecretSerdeValue>,
 }
 
 #[cfg(all(feature = "v2", feature = "business_profile_v2"))]
@@ -324,7 +324,7 @@ pub struct BusinessProfileUpdateInternal {
     // pub order_fulfillment_time_origin: Option<OrderFulfillmentTimeOrigin>,
     pub frm_routing_algorithm_id: Option<String>,
     pub payout_routing_algorithm_id: Option<String>,
-    // pub default_fallback_routing: Option<pii::SecretSerdeValue>,
+    pub default_fallback_routing: Option<pii::SecretSerdeValue>,
 }
 
 #[cfg(all(feature = "v2", feature = "business_profile_v2"))]
@@ -358,7 +358,7 @@ impl BusinessProfileUpdateInternal {
             // order_fulfillment_time_origin,
             frm_routing_algorithm_id,
             payout_routing_algorithm_id,
-            // default_fallback_routing,
+            default_fallback_routing,
         } = self;
         BusinessProfile {
             profile_id: source.profile_id,
@@ -407,7 +407,7 @@ impl BusinessProfileUpdateInternal {
             frm_routing_algorithm_id: frm_routing_algorithm_id.or(source.frm_routing_algorithm_id),
             payout_routing_algorithm_id: payout_routing_algorithm_id
                 .or(source.payout_routing_algorithm_id),
-            // default_fallback_routing: default_fallback_routing.or(source.default_fallback_routing),
+            default_fallback_routing: default_fallback_routing.or(source.default_fallback_routing),
         }
     }
 }
@@ -451,7 +451,7 @@ impl From<BusinessProfileNew> for BusinessProfile {
             // order_fulfillment_time_origin: new.order_fulfillment_time_origin,
             frm_routing_algorithm_id: new.frm_routing_algorithm_id,
             payout_routing_algorithm_id: new.payout_routing_algorithm_id,
-            // default_fallback_routing: new.default_fallback_routing,
+            default_fallback_routing: new.default_fallback_routing,
         }
     }
 }
diff --git a/crates/diesel_models/src/schema_v2.rs b/crates/diesel_models/src/schema_v2.rs
index b5a4ff384ad..e4ae651f72d 100644
--- a/crates/diesel_models/src/schema_v2.rs
+++ b/crates/diesel_models/src/schema_v2.rs
@@ -208,6 +208,7 @@ diesel::table! {
         frm_routing_algorithm_id -> Nullable<Varchar>,
         #[max_length = 64]
         payout_routing_algorithm_id -> Nullable<Varchar>,
+        default_fallback_routing -> Nullable<Jsonb>,
     }
 }
 
diff --git a/crates/hyperswitch_domain_models/src/business_profile.rs b/crates/hyperswitch_domain_models/src/business_profile.rs
index dcc6a88c824..fa9af562cf3 100644
--- a/crates/hyperswitch_domain_models/src/business_profile.rs
+++ b/crates/hyperswitch_domain_models/src/business_profile.rs
@@ -439,7 +439,7 @@ pub struct BusinessProfile {
     // pub order_fulfillment_time_origin: Option<OrderFulfillmentTimeOrigin>,
     pub frm_routing_algorithm_id: Option<String>,
     pub payout_routing_algorithm_id: Option<String>,
-    // pub default_fallback_routing: Option<pii::SecretSerdeValue>,
+    pub default_fallback_routing: Option<pii::SecretSerdeValue>,
 }
 
 #[cfg(all(feature = "v2", feature = "business_profile_v2"))]
@@ -470,7 +470,7 @@ pub struct BusinessProfileGeneralUpdate {
     // pub order_fulfillment_time_origin: Option<OrderFulfillmentTimeOrigin>,
     pub frm_routing_algorithm_id: Option<String>,
     pub payout_routing_algorithm_id: Option<String>,
-    // pub default_fallback_routing: Option<pii::SecretSerdeValue>,
+    pub default_fallback_routing: Option<pii::SecretSerdeValue>,
 }
 
 #[cfg(all(feature = "v2", feature = "business_profile_v2"))]
@@ -481,6 +481,9 @@ pub enum BusinessProfileUpdate {
         routing_algorithm_id: Option<String>,
         payout_routing_algorithm_id: Option<String>,
     },
+    DefaultRoutingFallbackUpdate {
+        default_fallback_routing: Option<pii::SecretSerdeValue>,
+    },
     ExtendedCardInfoUpdate {
         is_extended_card_info_enabled: Option<bool>,
     },
@@ -522,7 +525,7 @@ impl From<BusinessProfileUpdate> for BusinessProfileUpdateInternal {
                     // order_fulfillment_time_origin,
                     frm_routing_algorithm_id,
                     payout_routing_algorithm_id,
-                    // default_fallback_routing,
+                    default_fallback_routing,
                 } = *update;
                 Self {
                     profile_name,
@@ -553,7 +556,7 @@ impl From<BusinessProfileUpdate> for BusinessProfileUpdateInternal {
                     // order_fulfillment_time_origin,
                     frm_routing_algorithm_id,
                     payout_routing_algorithm_id,
-                    // default_fallback_routing,
+                    default_fallback_routing,
                 }
             }
             BusinessProfileUpdate::RoutingAlgorithmUpdate {
@@ -587,7 +590,7 @@ impl From<BusinessProfileUpdate> for BusinessProfileUpdateInternal {
                 // order_fulfillment_time_origin: None,
                 frm_routing_algorithm_id: None,
                 payout_routing_algorithm_id,
-                // default_fallback_routing: None,
+                default_fallback_routing: None,
             },
             BusinessProfileUpdate::ExtendedCardInfoUpdate {
                 is_extended_card_info_enabled,
@@ -619,7 +622,7 @@ impl From<BusinessProfileUpdate> for BusinessProfileUpdateInternal {
                 // order_fulfillment_time: None,
                 // order_fulfillment_time_origin: None,
                 frm_routing_algorithm_id: None,
-                // default_fallback_routing: None,
+                default_fallback_routing: None,
             },
             BusinessProfileUpdate::ConnectorAgnosticMitUpdate {
                 is_connector_agnostic_mit_enabled,
@@ -651,7 +654,39 @@ impl From<BusinessProfileUpdate> for BusinessProfileUpdateInternal {
                 // order_fulfillment_time: None,
                 // order_fulfillment_time_origin: None,
                 frm_routing_algorithm_id: None,
-                // default_fallback_routing: None,
+                default_fallback_routing: None,
+            },
+            BusinessProfileUpdate::DefaultRoutingFallbackUpdate {
+                default_fallback_routing,
+            } => Self {
+                profile_name: None,
+                modified_at: now,
+                return_url: None,
+                enable_payment_response_hash: None,
+                payment_response_hash_key: None,
+                redirect_to_merchant_with_http_post: None,
+                webhook_details: None,
+                metadata: None,
+                is_recon_enabled: None,
+                applepay_verified_domains: None,
+                payment_link_config: None,
+                session_expiry: None,
+                authentication_connector_details: None,
+                payout_link_config: None,
+                is_extended_card_info_enabled: None,
+                extended_card_info_config: None,
+                is_connector_agnostic_mit_enabled: None,
+                use_billing_as_payment_method_billing: None,
+                collect_shipping_details_from_wallet_connector: None,
+                collect_billing_details_from_wallet_connector: None,
+                outgoing_webhook_custom_http_headers: None,
+                routing_algorithm_id: None,
+                payout_routing_algorithm_id: None,
+                intent_fulfillment_time: None,
+                // order_fulfillment_time: None,
+                // order_fulfillment_time_origin: None,
+                frm_routing_algorithm_id: None,
+                default_fallback_routing,
             },
         }
     }
@@ -699,7 +734,7 @@ impl super::behaviour::Conversion for BusinessProfile {
             // order_fulfillment_time: self.order_fulfillment_time,
             // order_fulfillment_time_origin: self.order_fulfillment_time_origin,
             frm_routing_algorithm_id: self.frm_routing_algorithm_id,
-            // default_fallback_routing: self.default_fallback_routing,
+            default_fallback_routing: self.default_fallback_routing,
         })
     }
 
@@ -760,7 +795,7 @@ impl super::behaviour::Conversion for BusinessProfile {
                 // order_fulfillment_time_origin: item.order_fulfillment_time_origin,
                 frm_routing_algorithm_id: item.frm_routing_algorithm_id,
                 payout_routing_algorithm_id: item.payout_routing_algorithm_id,
-                // default_fallback_routing: item.default_fallback_routing,
+                default_fallback_routing: item.default_fallback_routing,
             })
         }
         .await
@@ -805,7 +840,7 @@ impl super::behaviour::Conversion for BusinessProfile {
             // order_fulfillment_time_origin: self.order_fulfillment_time_origin,
             frm_routing_algorithm_id: self.frm_routing_algorithm_id,
             payout_routing_algorithm_id: self.payout_routing_algorithm_id,
-            // default_fallback_routing: self.default_fallback_routing,
+            default_fallback_routing: self.default_fallback_routing,
         })
     }
 }
diff --git a/crates/router/src/core/admin.rs b/crates/router/src/core/admin.rs
index 2b3360f35da..89cd956c995 100644
--- a/crates/router/src/core/admin.rs
+++ b/crates/router/src/core/admin.rs
@@ -3718,6 +3718,62 @@ impl BusinessProfileWrapper {
             ),
         }
     }
+    pub fn get_default_fallback_list_of_connector_under_profile(
+        &self,
+    ) -> RouterResult<Vec<routing_types::RoutableConnectorChoice>> {
+        use common_utils::ext_traits::OptionExt;
+        use masking::ExposeOptionInterface;
+
+        self.profile
+            .default_fallback_routing
+            .clone()
+            .expose_option()
+            .parse_value::<Vec<routing_types::RoutableConnectorChoice>>(
+                "Vec<RoutableConnectorChoice>",
+            )
+            .change_context(errors::ApiErrorResponse::InternalServerError)
+            .attach_printable("Merchant default config has invalid structure")
+    }
+    pub fn get_default_routing_configs_from_profile(
+        &self,
+    ) -> RouterResult<routing_types::ProfileDefaultRoutingConfig> {
+        let profile_id = self.profile.profile_id.clone();
+        let connectors = self.get_default_fallback_list_of_connector_under_profile()?;
+
+        Ok(routing_types::ProfileDefaultRoutingConfig {
+            profile_id,
+            connectors,
+        })
+    }
+
+    pub async fn update_default_routing_for_profile(
+        self,
+        db: &dyn StorageInterface,
+        updated_config: &Vec<routing_types::RoutableConnectorChoice>,
+        key_manager_state: &KeyManagerState,
+        merchant_key_store: &domain::MerchantKeyStore,
+    ) -> RouterResult<()> {
+        let default_fallback_routing = Secret::from(
+            updated_config
+                .encode_to_value()
+                .change_context(errors::ApiErrorResponse::InternalServerError)
+                .attach_printable("Failed to convert routing ref to value")?,
+        );
+        let business_profile_update = domain::BusinessProfileUpdate::DefaultRoutingFallbackUpdate {
+            default_fallback_routing: Some(default_fallback_routing),
+        };
+
+        db.update_business_profile_by_profile_id(
+            key_manager_state,
+            merchant_key_store,
+            self.profile,
+            business_profile_update,
+        )
+        .await
+        .change_context(errors::ApiErrorResponse::InternalServerError)
+        .attach_printable("Failed to update routing algorithm ref in business profile")?;
+        Ok(())
+    }
 }
 
 pub async fn extended_card_info_toggle(
diff --git a/crates/router/src/core/routing.rs b/crates/router/src/core/routing.rs
index 9d819f8df9f..0c50a01e36d 100644
--- a/crates/router/src/core/routing.rs
+++ b/crates/router/src/core/routing.rs
@@ -640,7 +640,90 @@ pub async fn unlink_routing_config(
     }
 }
 
-//feature update
+#[cfg(all(
+    feature = "v2",
+    feature = "routing_v2",
+    feature = "business_profile_v2"
+))]
+pub async fn update_default_fallback_routing(
+    state: SessionState,
+    merchant_account: domain::MerchantAccount,
+    key_store: domain::MerchantKeyStore,
+    profile_id: String,
+    updated_list_of_connectors: Vec<routing_types::RoutableConnectorChoice>,
+) -> RouterResponse<Vec<routing_types::RoutableConnectorChoice>> {
+    metrics::ROUTING_UPDATE_CONFIG.add(&metrics::CONTEXT, 1, &[]);
+    let db = state.store.as_ref();
+    let key_manager_state = &(&state).into();
+    let profile = core_utils::validate_and_get_business_profile(
+        db,
+        key_manager_state,
+        &key_store,
+        Some(&profile_id),
+        merchant_account.get_id(),
+    )
+    .await?
+    .get_required_value("BusinessProfile")?;
+    let profile_wrapper = admin::BusinessProfileWrapper::new(profile);
+    let default_list_of_connectors =
+        profile_wrapper.get_default_fallback_list_of_connector_under_profile()?;
+
+    utils::when(
+        default_list_of_connectors.len() != updated_list_of_connectors.len(),
+        || {
+            Err(errors::ApiErrorResponse::PreconditionFailed {
+                message: "current config and updated config have different lengths".to_string(),
+            })
+        },
+    )?;
+
+    let existing_set_of_default_connectors: FxHashSet<String> = FxHashSet::from_iter(
+        default_list_of_connectors
+            .iter()
+            .map(|conn_choice| conn_choice.to_string()),
+    );
+    let updated_set_of_default_connectors: FxHashSet<String> = FxHashSet::from_iter(
+        updated_list_of_connectors
+            .iter()
+            .map(|conn_choice| conn_choice.to_string()),
+    );
+
+    let symmetric_diff_between_existing_and_updated_connectors: Vec<String> =
+        existing_set_of_default_connectors
+            .symmetric_difference(&updated_set_of_default_connectors)
+            .cloned()
+            .collect();
+
+    utils::when(
+        !symmetric_diff_between_existing_and_updated_connectors.is_empty(),
+        || {
+            Err(errors::ApiErrorResponse::InvalidRequestData {
+                message: format!(
+                    "connector mismatch between old and new configs ({})",
+                    symmetric_diff_between_existing_and_updated_connectors.join(", ")
+                ),
+            })
+        },
+    )?;
+    profile_wrapper
+        .update_default_routing_for_profile(
+            db,
+            &updated_list_of_connectors,
+            key_manager_state,
+            &key_store,
+        )
+        .await?;
+
+    metrics::ROUTING_UPDATE_CONFIG_SUCCESS_RESPONSE.add(&metrics::CONTEXT, 1, &[]);
+    Ok(service_api::ApplicationResponse::Json(
+        updated_list_of_connectors,
+    ))
+}
+
+#[cfg(all(
+    any(feature = "v1", feature = "v2"),
+    not(any(feature = "routing_v2", feature = "business_profile_v2"))
+))]
 pub async fn update_default_routing_config(
     state: SessionState,
     merchant_account: domain::MerchantAccount,
@@ -693,6 +776,42 @@ pub async fn update_default_routing_config(
     Ok(service_api::ApplicationResponse::Json(updated_config))
 }
 
+#[cfg(all(
+    feature = "v2",
+    feature = "routing_v2",
+    feature = "business_profile_v2"
+))]
+pub async fn retrieve_default_fallback_algorithm_for_profile(
+    state: SessionState,
+    merchant_account: domain::MerchantAccount,
+    key_store: domain::MerchantKeyStore,
+    profile_id: String,
+) -> RouterResponse<Vec<routing_types::RoutableConnectorChoice>> {
+    metrics::ROUTING_RETRIEVE_DEFAULT_CONFIG.add(&metrics::CONTEXT, 1, &[]);
+    let db = state.store.as_ref();
+    let key_manager_state = &(&state).into();
+    let profile = core_utils::validate_and_get_business_profile(
+        db,
+        key_manager_state,
+        &key_store,
+        Some(&profile_id),
+        merchant_account.get_id(),
+    )
+    .await?
+    .get_required_value("BusinessProfile")?;
+
+    let connectors_choice = admin::BusinessProfileWrapper::new(profile)
+        .get_default_fallback_list_of_connector_under_profile()?;
+
+    metrics::ROUTING_RETRIEVE_DEFAULT_CONFIG_SUCCESS_RESPONSE.add(&metrics::CONTEXT, 1, &[]);
+    Ok(service_api::ApplicationResponse::Json(connectors_choice))
+}
+
+#[cfg(all(
+    any(feature = "v1", feature = "v2"),
+    not(any(feature = "routing_v2", feature = "business_profile_v2"))
+))]
+
 pub async fn retrieve_default_routing_config(
     state: SessionState,
     merchant_account: domain::MerchantAccount,
@@ -712,7 +831,6 @@ pub async fn retrieve_default_routing_config(
         service_api::ApplicationResponse::Json(conn_choice)
     })
 }
-
 #[cfg(all(
     feature = "v2",
     feature = "routing_v2",
diff --git a/crates/router/src/routes/app.rs b/crates/router/src/routes/app.rs
index a6ce8c568b1..614774ebb04 100644
--- a/crates/router/src/routes/app.rs
+++ b/crates/router/src/routes/app.rs
@@ -1469,21 +1469,8 @@ impl BusinessProfile {
                 web::scope("/{profile_id}")
                     .service(
                         web::resource("/fallback_routing")
-                            .route(web::get().to(|state, req| {
-                                routing::routing_retrieve_default_config(
-                                    state,
-                                    req,
-                                    &TransactionType::Payment,
-                                )
-                            }))
-                            .route(web::post().to(|state, req, payload| {
-                                routing::routing_update_default_config(
-                                    state,
-                                    req,
-                                    payload,
-                                    &TransactionType::Payment,
-                                )
-                            })),
+                            .route(web::get().to(routing::routing_retrieve_default_config))
+                            .route(web::post().to(routing::routing_update_default_config)),
                     )
                     .service(
                         web::resource("/activate_routing_algorithm").route(web::patch().to(
diff --git a/crates/router/src/routes/routing.rs b/crates/router/src/routes/routing.rs
index 485a55baa50..e6266f148f1 100644
--- a/crates/router/src/routes/routing.rs
+++ b/crates/router/src/routes/routing.rs
@@ -280,7 +280,55 @@ pub async fn routing_unlink_config(
     .await
 }
 
-#[cfg(feature = "olap")]
+#[cfg(all(
+    feature = "olap",
+    feature = "v2",
+    feature = "routing_v2",
+    feature = "business_profile_v2"
+))]
+#[instrument(skip_all)]
+pub async fn routing_update_default_config(
+    state: web::Data<AppState>,
+    req: HttpRequest,
+    path: web::Path<String>,
+    json_payload: web::Json<Vec<routing_types::RoutableConnectorChoice>>,
+) -> impl Responder {
+    let wrapper = routing_types::ProfileDefaultRoutingConfig {
+        profile_id: path.into_inner(),
+        connectors: json_payload.into_inner(),
+    };
+    Box::pin(oss_api::server_wrap(
+        Flow::RoutingUpdateDefaultConfig,
+        state,
+        &req,
+        wrapper,
+        |state, auth: auth::AuthenticationData, wrapper, _| {
+            routing::update_default_fallback_routing(
+                state,
+                auth.merchant_account,
+                auth.key_store,
+                wrapper.profile_id,
+                wrapper.updated_config,
+            )
+        },
+        #[cfg(not(feature = "release"))]
+        auth::auth_type(
+            &auth::HeaderAuth(auth::ApiKeyAuth),
+            &auth::JWTAuth(Permission::RoutingWrite),
+            req.headers(),
+        ),
+        #[cfg(feature = "release")]
+        &auth::JWTAuth(Permission::RoutingWrite),
+        api_locking::LockAction::NotApplicable,
+    ))
+    .await
+}
+
+#[cfg(all(
+    feature = "olap",
+    any(feature = "v1", feature = "v2"),
+    not(any(feature = "routing_v2", feature = "business_profile_v2"))
+))]
 #[instrument(skip_all)]
 pub async fn routing_update_default_config(
     state: web::Data<AppState>,
@@ -314,7 +362,49 @@ pub async fn routing_update_default_config(
     .await
 }
 
-#[cfg(feature = "olap")]
+#[cfg(all(
+    feature = "olap",
+    feature = "v2",
+    feature = "routing_v2",
+    feature = "business_profile_v2"
+))]
+#[instrument(skip_all)]
+pub async fn routing_retrieve_default_config(
+    state: web::Data<AppState>,
+    req: HttpRequest,
+    path: web::Path<String>,
+) -> impl Responder {
+    Box::pin(oss_api::server_wrap(
+        Flow::RoutingRetrieveDefaultConfig,
+        state,
+        &req,
+        path.into_inner(),
+        |state, auth: auth::AuthenticationData, profile_id, _| {
+            routing::retrieve_default_fallback_algorithm_for_profile(
+                state,
+                auth.merchant_account,
+                auth.key_store,
+                profile_id,
+            )
+        },
+        #[cfg(not(feature = "release"))]
+        auth::auth_type(
+            &auth::HeaderAuth(auth::ApiKeyAuth),
+            &auth::JWTAuth(Permission::RoutingRead),
+            req.headers(),
+        ),
+        #[cfg(feature = "release")]
+        &auth::JWTAuth(Permission::RoutingRead),
+        api_locking::LockAction::NotApplicable,
+    ))
+    .await
+}
+
+#[cfg(all(
+    feature = "olap",
+    any(feature = "v1", feature = "v2"),
+    not(any(feature = "routing_v2", feature = "business_profile_v2"))
+))]
 #[instrument(skip_all)]
 pub async fn routing_retrieve_default_config(
     state: web::Data<AppState>,
diff --git a/v2_migrations/2024-07-31-100300_business_profile_add_v2_columns_drop_v1_columns/down.sql b/v2_migrations/2024-07-31-100300_business_profile_add_v2_columns_drop_v1_columns/down.sql
index 3d35becdfab..94c02697c50 100644
--- a/v2_migrations/2024-07-31-100300_business_profile_add_v2_columns_drop_v1_columns/down.sql
+++ b/v2_migrations/2024-07-31-100300_business_profile_add_v2_columns_drop_v1_columns/down.sql
@@ -1,18 +1,22 @@
 -- This adds back dropped columns in `up.sql`.
 -- However, if the old columns were dropped, then we won't have data previously
 -- stored in these columns.
-ALTER TABLE business_profile
-    ADD COLUMN routing_algorithm JSON DEFAULT NULL,
+ALTER TABLE
+    business_profile
+ADD
+    COLUMN routing_algorithm JSON DEFAULT NULL,
     -- ADD COLUMN intent_fulfillment_time BIGINT DEFAULT NULL,
-    ADD COLUMN frm_routing_algorithm JSONB DEFAULT NULL,
-     ADD COLUMN payout_routing_algorithm JSONB DEFAULT NULL;
+ADD
+    COLUMN frm_routing_algorithm JSONB DEFAULT NULL,
+ADD
+    COLUMN payout_routing_algorithm JSONB DEFAULT NULL;
 
-ALTER TABLE business_profile
-    DROP COLUMN routing_algorithm_id,
+ALTER TABLE
+    business_profile DROP COLUMN routing_algorithm_id,
     -- DROP COLUMN order_fulfillment_time,
     -- DROP COLUMN order_fulfillment_time_origin,
     DROP COLUMN frm_routing_algorithm_id,
-    DROP COLUMN payout_routing_algorithm_id;
-    -- DROP COLUMN default_fallback_routing;
+    DROP COLUMN payout_routing_algorithm_id,
+    DROP COLUMN default_fallback_routing;
 
--- DROP TYPE "OrderFulfillmentTimeOrigin";
+-- DROP TYPE "OrderFulfillmentTimeOrigin";
\ No newline at end of file
diff --git a/v2_migrations/2024-07-31-100300_business_profile_add_v2_columns_drop_v1_columns/up.sql b/v2_migrations/2024-07-31-100300_business_profile_add_v2_columns_drop_v1_columns/up.sql
index 2b98bef00d4..d2275ad2362 100644
--- a/v2_migrations/2024-07-31-100300_business_profile_add_v2_columns_drop_v1_columns/up.sql
+++ b/v2_migrations/2024-07-31-100300_business_profile_add_v2_columns_drop_v1_columns/up.sql
@@ -1,17 +1,21 @@
 -- CREATE TYPE "OrderFulfillmentTimeOrigin" AS ENUM ('create', 'confirm');
-
-ALTER TABLE business_profile
-    ADD COLUMN routing_algorithm_id VARCHAR(64) DEFAULT NULL,
-    -- ADD COLUMN order_fulfillment_time BIGINT DEFAULT NULL,
-    -- ADD COLUMN order_fulfillment_time_origin "OrderFulfillmentTimeOrigin" DEFAULT NULL,
-     ADD COLUMN frm_routing_algorithm_id VARCHAR(64) DEFAULT NULL,
-     ADD COLUMN payout_routing_algorithm_id VARCHAR(64) DEFAULT NULL;
-    -- ADD COLUMN default_fallback_routing JSONB DEFAULT NULL;
+ALTER TABLE
+  business_profile
+ADD
+  COLUMN routing_algorithm_id VARCHAR(64) DEFAULT NULL,
+  -- ADD COLUMN order_fulfillment_time BIGINT DEFAULT NULL,
+  -- ADD COLUMN order_fulfillment_time_origin "OrderFulfillmentTimeOrigin" DEFAULT NULL,
+ADD
+  COLUMN frm_routing_algorithm_id VARCHAR(64) DEFAULT NULL,
+ADD
+  COLUMN payout_routing_algorithm_id VARCHAR(64) DEFAULT NULL,
+ADD
+  COLUMN default_fallback_routing JSONB DEFAULT NULL;
 
 -- Note: This query should not be run on higher environments as this leads to data loss.
 -- The application will work fine even without these queries being run.
-ALTER TABLE business_profile
-    DROP COLUMN routing_algorithm,
-    -- DROP COLUMN intent_fulfillment_time,
-     DROP COLUMN frm_routing_algorithm,
-     DROP COLUMN payout_routing_algorithm;
+ALTER TABLE
+  business_profile DROP COLUMN routing_algorithm,
+  -- DROP COLUMN intent_fulfillment_time,
+  DROP COLUMN frm_routing_algorithm,
+  DROP COLUMN payout_routing_algorithm;
\ No newline at end of file

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

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

## Description
Refactor fallback routing apis for v2. Refactor the fallback apis for routing to retrieve and update the fallback routing algorithms.



### 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?
 
 - To retrieve the default fallback config
 ```
 curl --location 'http://localhost:8080/v2/profile/pro_VirB3AxB3qItFTnLsuA2/fallback_routing' \
--header 'Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoiYWQyMTRiZjUtMjgyYS00OWRiLWIzMjEtZGM3ZTExODRlNTliIiwibWVyY2hhbnRfaWQiOiJzZW5kZXJfbmV0Iiwicm9sZV9pZCI6ImludGVybmFsX3ZpZXdfb25seSIsImV4cCI6MTcyMTMxMDI0NCwib3JnX2lkIjoib3JnX2JmQXZqZWZRMG5oTjVJVm95VTZGIn0.hCH_Pd0d2d08ESOUy1PMGfyuh5TzXQLfi0wBIev1O6U' \
--data ''

 ```
 
 - To update the default fallback config
 
 ```
 curl --location 'http://localhost:8080/v2/profile/pro_VirB3AxB3qItFTnLsuA2/fallback_routing' \
--header 'Content-Type: application/json' \
--header 'api-key: dev_jsssWAg0XyxGK0ycPunkFjlItYNs30X1IVOr1MIF7lwrDQgBBk7npwdkZB4t7EQd' \
--data '["checkout", "stripe" ,"adyen", "authorizedotnet"]'
 ```

## 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
