Bug: refactor(dynamic_routing): update the authentication for update config to include JWT type



Enable JWT to be used for update config for success based routing route, previously it was only admin api key.


diff --git a/crates/openapi/src/openapi.rs b/crates/openapi/src/openapi.rs
index 7ad5645e75a..fc8668905ca 100644
--- a/crates/openapi/src/openapi.rs
+++ b/crates/openapi/src/openapi.rs
@@ -159,7 +159,9 @@ Never share your secret api keys. Keep them guarded and secure.
         routes::routing::routing_retrieve_linked_config,
         routes::routing::routing_retrieve_default_config_for_profiles,
         routes::routing::routing_update_default_config_for_profile,
+        routes::routing::success_based_routing_update_configs,
         routes::routing::toggle_success_based_routing,
+        routes::routing::toggle_elimination_routing,
 
         // Routes for blocklist
         routes::blocklist::remove_entry_from_blocklist,
@@ -589,6 +591,10 @@ Never share your secret api keys. Keep them guarded and secure.
         api_models::routing::RoutingKind,
         api_models::routing::RoutableConnectorChoice,
         api_models::routing::DynamicRoutingFeatures,
+        api_models::routing::SuccessBasedRoutingConfig,
+        api_models::routing::DynamicRoutingConfigParams,
+        api_models::routing::CurrentBlockThreshold,
+        api_models::routing::SuccessBasedRoutingConfigBody,
         api_models::routing::LinkedRoutingConfigRetrieveResponse,
         api_models::routing::RoutingRetrieveResponse,
         api_models::routing::ProfileDefaultRoutingConfig,
diff --git a/crates/openapi/src/routes/routing.rs b/crates/openapi/src/routes/routing.rs
index b0fcb75fa49..6b968f80172 100644
--- a/crates/openapi/src/routes/routing.rs
+++ b/crates/openapi/src/routes/routing.rs
@@ -260,7 +260,7 @@ pub async fn routing_update_default_config_for_profile() {}
 /// Create a success based dynamic routing algorithm
 #[utoipa::path(
     post,
-    path = "/account/:account_id/business_profile/:profile_id/dynamic_routing/success_based/toggle",
+    path = "/account/{account_id}/business_profile/{profile_id}/dynamic_routing/success_based/toggle",
     params(
         ("account_id" = String, Path, description = "Merchant id"),
         ("profile_id" = String, Path, description = "Profile id under which Dynamic routing needs to be toggled"),
@@ -280,13 +280,40 @@ pub async fn routing_update_default_config_for_profile() {}
 )]
 pub async fn toggle_success_based_routing() {}
 
+#[cfg(feature = "v1")]
+/// Routing - Update success based dynamic routing config for profile
+///
+/// Update success based dynamic routing algorithm
+#[utoipa::path(
+    patch,
+    path = "/account/{account_id}/business_profile/{profile_id}/dynamic_routing/success_based/config/{algorithm_id}",
+    params(
+        ("account_id" = String, Path, description = "Merchant id"),
+        ("profile_id" = String, Path, description = "Profile id under which Dynamic routing needs to be toggled"),
+        ("algorithm_id" = String, Path, description = "Success based routing algorithm id which was last activated to update the config"),
+    ),
+    request_body = DynamicRoutingFeatures,
+    responses(
+        (status = 200, description = "Routing Algorithm updated", body = RoutingDictionaryRecord),
+        (status = 400, description = "Update body is malformed"),
+        (status = 500, description = "Internal server error"),
+        (status = 404, description = "Resource missing"),
+        (status = 422, description = "Unprocessable request"),
+        (status = 403, description = "Forbidden"),
+    ),
+   tag = "Routing",
+   operation_id = "Update success based dynamic routing configs",
+   security(("api_key" = []), ("jwt_key" = []))
+)]
+pub async fn success_based_routing_update_configs() {}
+
 #[cfg(feature = "v1")]
 /// Routing - Toggle elimination routing for profile
 ///
 /// Create a elimination based dynamic routing algorithm
 #[utoipa::path(
     post,
-    path = "/account/:account_id/business_profile/:profile_id/dynamic_routing/elimination/toggle",
+    path = "/account/{account_id}/business_profile/{profile_id}/dynamic_routing/elimination/toggle",
     params(
         ("account_id" = String, Path, description = "Merchant id"),
         ("profile_id" = String, Path, description = "Profile id under which Dynamic routing needs to be toggled"),
diff --git a/crates/router/src/routes/routing.rs b/crates/router/src/routes/routing.rs
index 19b96a9dc84..76852bf12ef 100644
--- a/crates/router/src/routes/routing.rs
+++ b/crates/router/src/routes/routing.rs
@@ -1071,7 +1071,7 @@ pub async fn success_based_routing_update_configs(
         flow,
         state,
         &req,
-        routing_payload_wrapper,
+        routing_payload_wrapper.clone(),
         |state, _, wrapper: routing_types::SuccessBasedRoutingPayloadWrapper, _| async {
             Box::pin(routing::success_based_routing_update_configs(
                 state,
@@ -1081,7 +1081,14 @@ pub async fn success_based_routing_update_configs(
             ))
             .await
         },
-        &auth::AdminApiAuth,
+        auth::auth_type(
+            &auth::HeaderAuth(auth::ApiKeyAuth),
+            &auth::JWTAuthProfileFromRoute {
+                profile_id: routing_payload_wrapper.profile_id,
+                required_permission: Permission::ProfileRoutingWrite,
+            },
+            req.headers(),
+        ),
         api_locking::LockAction::NotApplicable,
     ))
     .await

## 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 PR will enable JWT to be used for update config for success based routing route, previously it was only admin api key.

### Additional Changes

- [x] 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)?
-->
This will be checked with JWT token.
```
curl --location --request PATCH '{base_url}/account/:account_id/business_profile/:profile_id/dynamic_routing/success_based/config/:routing_config_id' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer token' \
--data '{
  "params": [
    "Currency",
    "CardBin",
    "Country",
    "PaymentMethod",
    "PaymentMethodType",
    "AuthenticationType",
    "CardNetwork"
  ]
}
'
```

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

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