Bug: [FEATURE] Request fields to be populated on top level



### Feature Description

Few fields of request to be passed on to top level for certain operations

### Possible Implementation

parse the value and then add it to the events

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

None
diff --git a/crates/router/src/configs/secrets_transformers.rs b/crates/router/src/configs/secrets_transformers.rs
index d4eb34838d6..4f53a2ef2df 100644
--- a/crates/router/src/configs/secrets_transformers.rs
+++ b/crates/router/src/configs/secrets_transformers.rs
@@ -547,5 +547,6 @@ pub(crate) async fn fetch_raw_secrets(
         clone_connector_allowlist: conf.clone_connector_allowlist,
         merchant_id_auth: conf.merchant_id_auth,
         infra_values: conf.infra_values,
+        enhancement: conf.enhancement,
     }
 }
diff --git a/crates/router/src/configs/settings.rs b/crates/router/src/configs/settings.rs
index ae4c8a3cda0..6e4454063ce 100644
--- a/crates/router/src/configs/settings.rs
+++ b/crates/router/src/configs/settings.rs
@@ -162,6 +162,8 @@ pub struct Settings<S: SecretState> {
     pub merchant_id_auth: MerchantIdAuthSettings,
     #[serde(default)]
     pub infra_values: Option<HashMap<String, String>>,
+    #[serde(default)]
+    pub enhancement: Option<HashMap<String, String>>,
 }
 
 #[derive(Debug, Deserialize, Clone, Default)]
diff --git a/crates/router/src/routes/app.rs b/crates/router/src/routes/app.rs
index cb731c43717..f52b0d44c80 100644
--- a/crates/router/src/routes/app.rs
+++ b/crates/router/src/routes/app.rs
@@ -132,6 +132,7 @@ pub struct SessionState {
     pub locale: String,
     pub crm_client: Arc<dyn CrmInterface>,
     pub infra_components: Option<serde_json::Value>,
+    pub enhancement: Option<HashMap<String, String>>,
 }
 impl scheduler::SchedulerSessionState for SessionState {
     fn get_db(&self) -> Box<dyn SchedulerInterface> {
@@ -245,6 +246,7 @@ pub struct AppState {
     pub theme_storage_client: Arc<dyn FileStorageInterface>,
     pub crm_client: Arc<dyn CrmInterface>,
     pub infra_components: Option<serde_json::Value>,
+    pub enhancement: Option<HashMap<String, String>>,
 }
 impl scheduler::SchedulerAppState for AppState {
     fn get_tenants(&self) -> Vec<id_type::TenantId> {
@@ -410,6 +412,7 @@ impl AppState {
 
             let grpc_client = conf.grpc_client.get_grpc_client_interface().await;
             let infra_component_values = Self::process_env_mappings(conf.infra_values.clone());
+            let enhancement = conf.enhancement.clone();
             Self {
                 flow_name: String::from("default"),
                 stores,
@@ -431,6 +434,7 @@ impl AppState {
                 theme_storage_client,
                 crm_client,
                 infra_components: infra_component_values,
+                enhancement,
             }
         })
         .await
@@ -526,6 +530,7 @@ impl AppState {
             locale: locale.unwrap_or(common_utils::consts::DEFAULT_LOCALE.to_string()),
             crm_client: self.crm_client.clone(),
             infra_components: self.infra_components.clone(),
+            enhancement: self.enhancement.clone(),
         })
     }
 
diff --git a/crates/router/src/services/api.rs b/crates/router/src/services/api.rs
index 9b6c091a577..792edb71997 100644
--- a/crates/router/src/services/api.rs
+++ b/crates/router/src/services/api.rs
@@ -701,7 +701,11 @@ where
         }
     };
 
-    let infra = state.infra_components.clone();
+    let infra = extract_mapped_fields(
+        &serialized_request,
+        state.enhancement.as_ref(),
+        state.infra_components.as_ref(),
+    );
 
     let api_event = ApiEvent::new(
         tenant_id,
@@ -2065,6 +2069,64 @@ pub fn get_payment_link_status(
     }
 }
 
+pub fn extract_mapped_fields(
+    value: &serde_json::Value,
+    mapping: Option<&HashMap<String, String>>,
+    existing_enhancement: Option<&serde_json::Value>,
+) -> Option<serde_json::Value> {
+    let mapping = mapping?;
+
+    if mapping.is_empty() {
+        return existing_enhancement.cloned();
+    }
+
+    let mut enhancement = match existing_enhancement {
+        Some(existing) if existing.is_object() => existing.clone(),
+        _ => serde_json::json!({}),
+    };
+
+    for (dot_path, output_key) in mapping {
+        if let Some(extracted_value) = extract_field_by_dot_path(value, dot_path) {
+            if let Some(obj) = enhancement.as_object_mut() {
+                obj.insert(output_key.clone(), extracted_value);
+            }
+        }
+    }
+
+    if enhancement.as_object().is_some_and(|obj| !obj.is_empty()) {
+        Some(enhancement)
+    } else {
+        None
+    }
+}
+
+pub fn extract_field_by_dot_path(
+    value: &serde_json::Value,
+    path: &str,
+) -> Option<serde_json::Value> {
+    let parts: Vec<&str> = path.split('.').collect();
+    let mut current = value;
+
+    for part in parts {
+        match current {
+            serde_json::Value::Object(obj) => {
+                current = obj.get(part)?;
+            }
+            serde_json::Value::Array(arr) => {
+                // Try to parse part as array index
+                if let Ok(index) = part.parse::<usize>() {
+                    current = arr.get(index)?;
+                } else {
+                    return None;
+                }
+            }
+            _ => return None,
+        }
+    }
+
+    Some(current.clone())
+}
+
 #[cfg(test)]
 mod tests {
     #[test]

## 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 feature allows based on deployment config , it is able to query Request Body and add as a top level fields in the Kafka events

### Additional Changes

- [ ] This PR modifies the API contract
- [ ] This PR modifies the database schema
- [x] 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).
-->
We wanted a feature where we could add fields from Request Body to top level fields in kafka events irrespective of the flow

## 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)?
-->
Test 1

In ```development.toml```
```bash
[enhancement]
"merchant_reference_id" = "txn_uuid"
```
<img width="540" height="732" alt="Screenshot 2025-07-29 at 11 40 30 AM" src="https://github.com/user-attachments/assets/8eb747d8-7bc7-441f-8cb3-e1d992ee1671" />

```json
{
	"tenant_id": "public",
	"merchant_id": "cloth_seller_kGLq5ZsmKL6hISw8HI9A",
	"api_flow": "PaymentsCreateIntent",
	"created_at_timestamp": 1753767564159,
	"request_id": "019854b1-52c2-7080-ab7f-114e169fc92b",
	"latency": 170,
	"status_code": 200,
	"api_auth_type": "api_key",
	"authentication_data": {
		"merchant_id": "cloth_seller_kGLq5ZsmKL6hISw8HI9A",
		"key_id": "dev_ekHYWGqV5It7fLj62AOa"
	},
	"request": "{\"amount_details\":{\"order_amount\":{\"Value\":100},\"currency\":\"USD\",\"shipping_cost\":null,\"order_tax_amount\":null,\"skip_external_tax_calculation\":\"skip\",\"skip_surcharge_calculation\":\"skip\",\"surcharge_amount\":null,\"tax_on_surcharge\":null},\"merchant_reference_id\":\"NOPA\",\"routing_algorithm_id\":null,\"capture_method\":\"manual\",\"authentication_type\":\"no_three_ds\",\"billing\":{\"address\":{\"city\":\"test\",\"country\":\"NL\",\"line1\":\"*** alloc::string::String ***\",\"line2\":\"*** alloc::string::String ***\",\"line3\":\"*** alloc::string::String ***\",\"zip\":\"*** alloc::string::String ***\",\"state\":\"*** alloc::string::String ***\",\"first_name\":\"*** alloc::string::String ***\",\"last_name\":\"*** alloc::string::String ***\"},\"phone\":{\"number\":\"*** alloc::string::String ***\",\"country_code\":\"+1\"},\"email\":\"*****@example.com\"},\"shipping\":{\"address\":{\"city\":\"Karwar\",\"country\":\"NL\",\"line1\":null,\"line2\":null,\"line3\":null,\"zip\":\"*** alloc::string::String ***\",\"state\":\"*** alloc::string::String ***\",\"first_name\":\"*** alloc::string::String ***\",\"last_name\":\"*** alloc::string::String ***\"},\"phone\":null,\"email\":\"*******@example.com\"},\"customer_id\":\"12345_cus_019841789b727750b33d014ce2fabf10\",\"customer_present\":null,\"description\":null,\"return_url\":null,\"setup_future_usage\":null,\"apply_mit_exemption\":null,\"statement_descriptor\":null,\"order_details\":null,\"allowed_payment_method_types\":null,\"metadata\":null,\"connector_metadata\":null,\"feature_metadata\":null,\"payment_link_enabled\":null,\"payment_link_config\":null,\"request_incremental_authorization\":null,\"session_expiry\":null,\"frm_metadata\":null,\"request_external_three_ds_authentication\":null,\"force_3ds_challenge\":null,\"merchant_connector_details\":null}",
	"user_agent": "PostmanRuntime/7.44.1",
	"ip_addr": "::1",
	"url_path": "/v2/payments/create-intent",
	"response": "{\"id\":\"12345_pay_019854b152cf7bc2b538db792c40bcc6\",\"status\":\"requires_payment_method\",\"amount_details\":{\"order_amount\":100,\"currency\":\"USD\",\"shipping_cost\":null,\"order_tax_amount\":null,\"external_tax_calculation\":\"skip\",\"surcharge_calculation\":\"skip\",\"surcharge_amount\":null,\"tax_on_surcharge\":null},\"client_secret\":\"*** alloc::string::String ***\",\"profile_id\":\"pro_uJBgizwyNrvQmKZVxuUo\",\"merchant_reference_id\":\"NOPA\",\"routing_algorithm_id\":null,\"capture_method\":\"manual\",\"authentication_type\":\"no_three_ds\",\"billing\":{\"address\":{\"city\":\"test\",\"country\":\"NL\",\"line1\":\"*** alloc::string::String ***\",\"line2\":\"*** alloc::string::String ***\",\"line3\":\"*** alloc::string::String ***\",\"zip\":\"*** alloc::string::String ***\",\"state\":\"*** alloc::string::String ***\",\"first_name\":\"*** alloc::string::String ***\",\"last_name\":\"*** alloc::string::String ***\"},\"phone\":{\"number\":\"*** alloc::string::String ***\",\"country_code\":\"+1\"},\"email\":\"*****@example.com\"},\"shipping\":{\"address\":{\"city\":\"Karwar\",\"country\":\"NL\",\"line1\":null,\"line2\":null,\"line3\":null,\"zip\":\"*** alloc::string::String ***\",\"state\":\"*** alloc::string::String ***\",\"first_name\":\"*** alloc::string::String ***\",\"last_name\":\"*** alloc::string::String ***\"},\"phone\":null,\"email\":\"*******@example.com\"},\"customer_id\":\"12345_cus_019841789b727750b33d014ce2fabf10\",\"customer_present\":\"present\",\"description\":null,\"return_url\":null,\"setup_future_usage\":\"on_session\",\"apply_mit_exemption\":\"Skip\",\"statement_descriptor\":null,\"order_details\":null,\"allowed_payment_method_types\":null,\"metadata\":null,\"connector_metadata\":null,\"feature_metadata\":null,\"payment_link_enabled\":\"Skip\",\"payment_link_config\":null,\"request_incremental_authorization\":\"default\",\"expires_on\":\"2025-07-29T05:54:24.111Z\",\"frm_metadata\":null,\"request_external_three_ds_authentication\":\"Skip\"}",
	"error": null,
	"flow_type": "payment",
	"payment_id": "12345_pay_019854b152cf7bc2b538db792c40bcc6",
	"hs_latency": null,
	"http_method": "POST",
	"cluster": "my_own_cluster",
	"txn_uuid": "NOPA"
}
```

Test 2
In ```development.toml```

```bash
[enhancement]
"merchant_reference_id" = "udf_txn_uuid"
"shipping.address.country" = "country"
```

```json
{
	"tenant_id": "public",
	"merchant_id": "cloth_seller_PdFuIUDbxVwvu7kZJ3DC",
	"api_flow": "PaymentsCreateIntent",
	"created_at_timestamp": 1753795822163,
	"request_id": "01985660-8135-7422-afa3-9c4aa8c4ff23",
	"latency": 264,
	"status_code": 200,
	"api_auth_type": "api_key",
	"authentication_data": {
		"merchant_id": "cloth_seller_PdFuIUDbxVwvu7kZJ3DC",
		"key_id": "dev_SImQYDU2oDTEQ9RqnY4R"
	},
	"request": "{\"amount_details\":{\"order_amount\":{\"Value\":100},\"currency\":\"USD\",\"shipping_cost\":null,\"order_tax_amount\":null,\"skip_external_tax_calculation\":\"skip\",\"skip_surcharge_calculation\":\"skip\",\"surcharge_amount\":null,\"tax_on_surcharge\":null},\"merchant_reference_id\":\"NOPA\",\"routing_algorithm_id\":null,\"capture_method\":\"manual\",\"authentication_type\":\"no_three_ds\",\"billing\":{\"address\":{\"city\":\"test\",\"country\":\"NL\",\"line1\":\"*** alloc::string::String ***\",\"line2\":\"*** alloc::string::String ***\",\"line3\":\"*** alloc::string::String ***\",\"zip\":\"*** alloc::string::String ***\",\"state\":\"*** alloc::string::String ***\",\"first_name\":\"*** alloc::string::String ***\",\"last_name\":\"*** alloc::string::String ***\"},\"phone\":{\"number\":\"*** alloc::string::String ***\",\"country_code\":\"+1\"},\"email\":\"*****@example.com\"},\"shipping\":{\"address\":{\"city\":\"Karwar\",\"country\":\"NL\",\"line1\":null,\"line2\":null,\"line3\":null,\"zip\":\"*** alloc::string::String ***\",\"state\":\"*** alloc::string::String ***\",\"first_name\":\"*** alloc::string::String ***\",\"last_name\":\"*** alloc::string::String ***\"},\"phone\":null,\"email\":\"*******@example.com\"},\"customer_id\":\"12345_cus_019854ddfc4179a1b56936f3ef50cf48\",\"customer_present\":null,\"description\":null,\"return_url\":null,\"setup_future_usage\":null,\"apply_mit_exemption\":null,\"statement_descriptor\":null,\"order_details\":null,\"allowed_payment_method_types\":null,\"metadata\":\"*** serde_json::value::Value ***\",\"connector_metadata\":null,\"feature_metadata\":null,\"payment_link_enabled\":null,\"payment_link_config\":null,\"request_incremental_authorization\":null,\"session_expiry\":null,\"frm_metadata\":null,\"request_external_three_ds_authentication\":null,\"force_3ds_challenge\":null,\"merchant_connector_details\":null}",
	"user_agent": "PostmanRuntime/7.44.1",
	"ip_addr": "::1",
	"url_path": "/v2/payments/create-intent",
	"response": "{\"id\":\"12345_pay_0198566081457b12a4925e86e34cbe96\",\"status\":\"requires_payment_method\",\"amount_details\":{\"order_amount\":100,\"currency\":\"USD\",\"shipping_cost\":null,\"order_tax_amount\":null,\"external_tax_calculation\":\"skip\",\"surcharge_calculation\":\"skip\",\"surcharge_amount\":null,\"tax_on_surcharge\":null},\"client_secret\":\"*** alloc::string::String ***\",\"profile_id\":\"pro_LWkFikerdXPyjg0lghL3\",\"merchant_reference_id\":\"NOPA\",\"routing_algorithm_id\":null,\"capture_method\":\"manual\",\"authentication_type\":\"no_three_ds\",\"billing\":{\"address\":{\"city\":\"test\",\"country\":\"NL\",\"line1\":\"*** alloc::string::String ***\",\"line2\":\"*** alloc::string::String ***\",\"line3\":\"*** alloc::string::String ***\",\"zip\":\"*** alloc::string::String ***\",\"state\":\"*** alloc::string::String ***\",\"first_name\":\"*** alloc::string::String ***\",\"last_name\":\"*** alloc::string::String ***\"},\"phone\":{\"number\":\"*** alloc::string::String ***\",\"country_code\":\"+1\"},\"email\":\"*****@example.com\"},\"shipping\":{\"address\":{\"city\":\"Karwar\",\"country\":\"NL\",\"line1\":null,\"line2\":null,\"line3\":null,\"zip\":\"*** alloc::string::String ***\",\"state\":\"*** alloc::string::String ***\",\"first_name\":\"*** alloc::string::String ***\",\"last_name\":\"*** alloc::string::String ***\"},\"phone\":null,\"email\":\"*******@example.com\"},\"customer_id\":\"12345_cus_019854ddfc4179a1b56936f3ef50cf48\",\"customer_present\":\"present\",\"description\":null,\"return_url\":null,\"setup_future_usage\":\"on_session\",\"apply_mit_exemption\":\"Skip\",\"statement_descriptor\":null,\"order_details\":null,\"allowed_payment_method_types\":null,\"metadata\":\"*** serde_json::value::Value ***\",\"connector_metadata\":null,\"feature_metadata\":null,\"payment_link_enabled\":\"Skip\",\"payment_link_config\":null,\"request_incremental_authorization\":\"default\",\"expires_on\":\"2025-07-29T13:45:22.074Z\",\"frm_metadata\":null,\"request_external_three_ds_authentication\":\"Skip\"}",
	"error": null,
	"flow_type": "payment",
	"payment_id": "12345_pay_0198566081457b12a4925e86e34cbe96",
	"hs_latency": null,
	"http_method": "POST",
	"country": "NL",
	"udf_txn_uuid": "NOPA"
}
```
## 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
