Bug: [FEATURE] Add additional parameters in AppState and refactor accordingly



### Feature Description

Some additional parameters : `request_id`, `merchant_id` and `flow_name` are needed in AppState.

### 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/router/src/compatibility/stripe/customers.rs b/crates/router/src/compatibility/stripe/customers.rs
index f3f55418d3b..5e9a1899364 100644
--- a/crates/router/src/compatibility/stripe/customers.rs
+++ b/crates/router/src/compatibility/stripe/customers.rs
@@ -42,11 +42,11 @@ pub async fn customer_create(
         _,
     >(
         flow,
-        state.get_ref(),
+        state.into_inner(),
         &req,
         create_cust_req,
         |state, auth, req| {
-            customers::create_customer(&*state.store, auth.merchant_account, auth.key_store, req)
+            customers::create_customer(state, auth.merchant_account, auth.key_store, req)
         },
         &auth::ApiKeyAuth,
     ))
@@ -77,11 +77,11 @@ pub async fn customer_retrieve(
         _,
     >(
         flow,
-        state.get_ref(),
+        state.into_inner(),
         &req,
         payload,
         |state, auth, req| {
-            customers::retrieve_customer(&*state.store, auth.merchant_account, auth.key_store, req)
+            customers::retrieve_customer(state, auth.merchant_account, auth.key_store, req)
         },
         &auth::ApiKeyAuth,
     ))
@@ -121,11 +121,11 @@ pub async fn customer_update(
         _,
     >(
         flow,
-        state.get_ref(),
+        state.into_inner(),
         &req,
         cust_update_req,
         |state, auth, req| {
-            customers::update_customer(&*state.store, auth.merchant_account, req, auth.key_store)
+            customers::update_customer(state, auth.merchant_account, req, auth.key_store)
         },
         &auth::ApiKeyAuth,
     ))
@@ -156,7 +156,7 @@ pub async fn customer_delete(
         _,
     >(
         flow,
-        state.get_ref(),
+        state.into_inner(),
         &req,
         payload,
         |state, auth, req| {
@@ -190,7 +190,7 @@ pub async fn list_customer_payment_method_api(
         _,
     >(
         flow,
-        state.get_ref(),
+        state.into_inner(),
         &req,
         payload,
         |state, auth, req| {
diff --git a/crates/router/src/compatibility/stripe/payment_intents.rs b/crates/router/src/compatibility/stripe/payment_intents.rs
index 322710ffd19..01e5e3857bc 100644
--- a/crates/router/src/compatibility/stripe/payment_intents.rs
+++ b/crates/router/src/compatibility/stripe/payment_intents.rs
@@ -47,7 +47,7 @@ pub async fn payment_intents_create(
         _,
     >(
         flow,
-        state.get_ref(),
+        state.into_inner(),
         &req,
         create_payment_req,
         |state, auth, req| {
@@ -106,7 +106,7 @@ pub async fn payment_intents_retrieve(
         _,
     >(
         flow,
-        state.get_ref(),
+        state.into_inner(),
         &req,
         payload,
         |state, auth, payload| {
@@ -169,7 +169,7 @@ pub async fn payment_intents_retrieve_with_gateway_creds(
         _,
     >(
         flow,
-        state.get_ref(),
+        state.into_inner(),
         &req,
         payload,
         |state, auth, req| {
@@ -233,7 +233,7 @@ pub async fn payment_intents_update(
         _,
     >(
         flow,
-        state.get_ref(),
+        state.into_inner(),
         &req,
         payload,
         |state, auth, req| {
@@ -299,7 +299,7 @@ pub async fn payment_intents_confirm(
         _,
     >(
         flow,
-        state.get_ref(),
+        state.into_inner(),
         &req,
         payload,
         |state, auth, req| {
@@ -355,7 +355,7 @@ pub async fn payment_intents_capture(
         _,
     >(
         flow,
-        state.get_ref(),
+        state.into_inner(),
         &req,
         capture_payload,
         |state, auth, payload| {
@@ -415,7 +415,7 @@ pub async fn payment_intents_cancel(
         _,
     >(
         flow,
-        state.get_ref(),
+        state.into_inner(),
         &req,
         payload,
         |state, auth, req| {
@@ -461,10 +461,10 @@ pub async fn payment_intent_list(
         _,
     >(
         flow,
-        state.get_ref(),
+        state.into_inner(),
         &req,
         payload,
-        |state, auth, req| payments::list_payments(&*state.store, auth.merchant_account, req),
+        |state, auth, req| payments::list_payments(state, auth.merchant_account, req),
         &auth::ApiKeyAuth,
     ))
     .await
diff --git a/crates/router/src/compatibility/stripe/refunds.rs b/crates/router/src/compatibility/stripe/refunds.rs
index 62d79c32ad1..697a7faa8ab 100644
--- a/crates/router/src/compatibility/stripe/refunds.rs
+++ b/crates/router/src/compatibility/stripe/refunds.rs
@@ -43,7 +43,7 @@ pub async fn refund_create(
         _,
     >(
         flow,
-        state.get_ref(),
+        state.into_inner(),
         &req,
         create_refund_req,
         |state, auth, req| {
@@ -83,7 +83,7 @@ pub async fn refund_retrieve_with_gateway_creds(
         _,
     >(
         flow,
-        state.get_ref(),
+        state.into_inner(),
         &req,
         refund_request,
         |state, auth, refund_request| {
@@ -126,7 +126,7 @@ pub async fn refund_retrieve(
         _,
     >(
         flow,
-        state.get_ref(),
+        state.into_inner(),
         &req,
         refund_request,
         |state, auth, refund_request| {
@@ -167,11 +167,11 @@ pub async fn refund_update(
         _,
     >(
         flow,
-        state.get_ref(),
+        state.into_inner(),
         &req,
         create_refund_update_req,
         |state, auth, req| {
-            refunds::refund_update_core(&*state.store, auth.merchant_account, &refund_id, req)
+            refunds::refund_update_core(state, auth.merchant_account, &refund_id, req)
         },
         &auth::ApiKeyAuth,
     ))
diff --git a/crates/router/src/compatibility/stripe/setup_intents.rs b/crates/router/src/compatibility/stripe/setup_intents.rs
index e4deb6f8ef1..849bbc60274 100644
--- a/crates/router/src/compatibility/stripe/setup_intents.rs
+++ b/crates/router/src/compatibility/stripe/setup_intents.rs
@@ -51,7 +51,7 @@ pub async fn setup_intents_create(
         _,
     >(
         flow,
-        state.get_ref(),
+        state.into_inner(),
         &req,
         create_payment_req,
         |state, auth, req| {
@@ -110,7 +110,7 @@ pub async fn setup_intents_retrieve(
         _,
     >(
         flow,
-        state.get_ref(),
+        state.into_inner(),
         &req,
         payload,
         |state, auth, payload| {
@@ -175,7 +175,7 @@ pub async fn setup_intents_update(
         _,
     >(
         flow,
-        state.get_ref(),
+        state.into_inner(),
         &req,
         payload,
         |state, auth, req| {
@@ -241,7 +241,7 @@ pub async fn setup_intents_confirm(
         _,
     >(
         flow,
-        state.get_ref(),
+        state.into_inner(),
         &req,
         payload,
         |state, auth, req| {
diff --git a/crates/router/src/compatibility/wrap.rs b/crates/router/src/compatibility/wrap.rs
index c86f105276e..24218e0b398 100644
--- a/crates/router/src/compatibility/wrap.rs
+++ b/crates/router/src/compatibility/wrap.rs
@@ -1,4 +1,4 @@
-use std::{future::Future, time::Instant};
+use std::{future::Future, sync::Arc, time::Instant};
 
 use actix_web::{HttpRequest, HttpResponse, Responder};
 use common_utils::errors::{CustomResult, ErrorSwitch};
@@ -14,14 +14,14 @@ use crate::{
 #[instrument(skip(request, payload, state, func, api_authentication))]
 pub async fn compatibility_api_wrap<'a, 'b, A, U, T, Q, F, Fut, S, E, E2>(
     flow: impl router_env::types::FlowMetric,
-    state: &'b A,
+    state: Arc<A>,
     request: &'a HttpRequest,
     payload: T,
     func: F,
     api_authentication: &dyn auth::AuthenticateAndFetch<U, A>,
 ) -> HttpResponse
 where
-    F: Fn(&'b A, U, T) -> Fut,
+    F: Fn(A, U, T) -> Fut,
     Fut: Future<Output = CustomResult<api::ApplicationResponse<Q>, E2>>,
     E2: ErrorSwitch<E> + std::error::Error + Send + Sync + 'static,
     Q: Serialize + std::fmt::Debug + 'a,
@@ -31,7 +31,7 @@ where
     error_stack::Report<E>: services::EmbedError,
     errors::ApiErrorResponse: ErrorSwitch<E>,
     T: std::fmt::Debug,
-    A: AppStateInfo,
+    A: AppStateInfo + Clone,
 {
     let request_method = request.method().as_str();
     let url_path = request.path();
@@ -42,7 +42,14 @@ where
     logger::info!(tag = ?Tag::BeginRequest, payload = ?payload);
 
     let res = match metrics::request::record_request_time_metric(
-        api::server_wrap_util(&flow, state, request, payload, func, api_authentication),
+        api::server_wrap_util(
+            &flow,
+            state.clone().into(),
+            request,
+            payload,
+            func,
+            api_authentication,
+        ),
         &flow,
     )
     .await
diff --git a/crates/router/src/core/admin.rs b/crates/router/src/core/admin.rs
index c3d4932ad5f..ffcbd3b21e5 100644
--- a/crates/router/src/core/admin.rs
+++ b/crates/router/src/core/admin.rs
@@ -41,9 +41,10 @@ pub fn create_merchant_publishable_key() -> String {
 }
 
 pub async fn create_merchant_account(
-    db: &dyn StorageInterface,
+    state: AppState,
     req: api::MerchantAccountCreate,
 ) -> RouterResponse<api::MerchantAccountResponse> {
+    let db = state.store.as_ref();
     let master_key = db.get_master_key();
 
     let key = services::generate_aes256_key()
@@ -227,9 +228,10 @@ pub async fn create_merchant_account(
 }
 
 pub async fn get_merchant_account(
-    db: &dyn StorageInterface,
+    state: AppState,
     req: api::MerchantId,
 ) -> RouterResponse<api::MerchantAccountResponse> {
+    let db = state.store.as_ref();
     let key_store = db
         .get_merchant_key_store_by_merchant_id(
             &req.merchant_id,
@@ -312,10 +314,11 @@ pub async fn create_business_profile_from_business_labels(
     Ok(())
 }
 pub async fn merchant_account_update(
-    db: &dyn StorageInterface,
+    state: AppState,
     merchant_id: &String,
     req: api::MerchantAccountUpdate,
 ) -> RouterResponse<api::MerchantAccountResponse> {
+    let db = state.store.as_ref();
     let key_store = db
         .get_merchant_key_store_by_merchant_id(
             &req.merchant_id,
@@ -459,9 +462,10 @@ pub async fn merchant_account_update(
 }
 
 pub async fn merchant_account_delete(
-    db: &dyn StorageInterface,
+    state: AppState,
     merchant_id: String,
 ) -> RouterResponse<api::MerchantAccountDeleteResponse> {
+    let db = state.store.as_ref();
     let is_deleted = db
         .delete_merchant_account_by_merchant_id(&merchant_id)
         .await
@@ -547,14 +551,14 @@ fn validate_certificate_in_mca_metadata(
 }
 
 pub async fn create_payment_connector(
-    state: &AppState,
+    state: AppState,
     req: api::MerchantConnectorCreate,
     merchant_id: &String,
 ) -> RouterResponse<api_models::admin::MerchantConnectorResponse> {
+    let store = state.store.as_ref();
     #[cfg(feature = "dummy_connector")]
-    validate_dummy_connector_enabled(state, &req.connector_name).await?;
-    let key_store = state
-        .store
+    validate_dummy_connector_enabled(&state, &req.connector_name).await?;
+    let key_store = store
         .get_merchant_key_store_by_merchant_id(
             merchant_id,
             &state.store.get_master_key().to_vec().into(),
@@ -704,10 +708,11 @@ pub async fn create_payment_connector(
 }
 
 pub async fn retrieve_payment_connector(
-    store: &dyn StorageInterface,
+    state: AppState,
     merchant_id: String,
     merchant_connector_id: String,
 ) -> RouterResponse<api_models::admin::MerchantConnectorResponse> {
+    let store = state.store.as_ref();
     let key_store = store
         .get_merchant_key_store_by_merchant_id(
             &merchant_id,
@@ -736,9 +741,10 @@ pub async fn retrieve_payment_connector(
 }
 
 pub async fn list_payment_connectors(
-    store: &dyn StorageInterface,
+    state: AppState,
     merchant_id: String,
 ) -> RouterResponse<Vec<api_models::admin::MerchantConnectorResponse>> {
+    let store = state.store.as_ref();
     let key_store = store
         .get_merchant_key_store_by_merchant_id(
             &merchant_id,
@@ -772,11 +778,12 @@ pub async fn list_payment_connectors(
 }
 
 pub async fn update_payment_connector(
-    db: &dyn StorageInterface,
+    state: AppState,
     merchant_id: &str,
     merchant_connector_id: &str,
     req: api_models::admin::MerchantConnectorUpdate,
 ) -> RouterResponse<api_models::admin::MerchantConnectorResponse> {
+    let db = state.store.as_ref();
     let key_store = db
         .get_merchant_key_store_by_merchant_id(merchant_id, &db.get_master_key().to_vec().into())
         .await
@@ -855,10 +862,11 @@ pub async fn update_payment_connector(
 }
 
 pub async fn delete_payment_connector(
-    db: &dyn StorageInterface,
+    state: AppState,
     merchant_id: String,
     merchant_connector_id: String,
 ) -> RouterResponse<api::MerchantConnectorDeleteResponse> {
+    let db = state.store.as_ref();
     let key_store = db
         .get_merchant_key_store_by_merchant_id(&merchant_id, &db.get_master_key().to_vec().into())
         .await
@@ -899,10 +907,11 @@ pub async fn delete_payment_connector(
 }
 
 pub async fn kv_for_merchant(
-    db: &dyn StorageInterface,
+    state: AppState,
     merchant_id: String,
     enable: bool,
 ) -> RouterResponse<api_models::admin::ToggleKVResponse> {
+    let db = state.store.as_ref();
     let key_store = db
         .get_merchant_key_store_by_merchant_id(&merchant_id, &db.get_master_key().to_vec().into())
         .await
@@ -958,9 +967,10 @@ pub async fn kv_for_merchant(
 }
 
 pub async fn check_merchant_account_kv_status(
-    db: &dyn StorageInterface,
+    state: AppState,
     merchant_id: String,
 ) -> RouterResponse<api_models::admin::ToggleKVResponse> {
+    let db = state.store.as_ref();
     let key_store = db
         .get_merchant_key_store_by_merchant_id(&merchant_id, &db.get_master_key().to_vec().into())
         .await
@@ -1028,10 +1038,11 @@ pub async fn create_and_insert_business_profile(
 }
 
 pub async fn create_business_profile(
-    db: &dyn StorageInterface,
+    state: AppState,
     request: api::BusinessProfileCreate,
     merchant_id: &str,
 ) -> RouterResponse<api_models::admin::BusinessProfileResponse> {
+    let db = state.store.as_ref();
     let key_store = db
         .get_merchant_key_store_by_merchant_id(merchant_id, &db.get_master_key().to_vec().into())
         .await
@@ -1071,9 +1082,10 @@ pub async fn create_business_profile(
 }
 
 pub async fn list_business_profile(
-    db: &dyn StorageInterface,
+    state: AppState,
     merchant_id: String,
 ) -> RouterResponse<Vec<api_models::admin::BusinessProfileResponse>> {
+    let db = state.store.as_ref();
     let business_profiles = db
         .list_business_profile_by_merchant_id(&merchant_id)
         .await
@@ -1090,9 +1102,10 @@ pub async fn list_business_profile(
 }
 
 pub async fn retrieve_business_profile(
-    db: &dyn StorageInterface,
+    state: AppState,
     profile_id: String,
 ) -> RouterResponse<api_models::admin::BusinessProfileResponse> {
+    let db = state.store.as_ref();
     let business_profile = db
         .find_business_profile_by_profile_id(&profile_id)
         .await
@@ -1107,10 +1120,11 @@ pub async fn retrieve_business_profile(
 }
 
 pub async fn delete_business_profile(
-    db: &dyn StorageInterface,
+    state: AppState,
     profile_id: String,
     merchant_id: &str,
 ) -> RouterResponse<bool> {
+    let db = state.store.as_ref();
     let delete_result = db
         .delete_business_profile_by_profile_id_merchant_id(&profile_id, merchant_id)
         .await
@@ -1122,11 +1136,12 @@ pub async fn delete_business_profile(
 }
 
 pub async fn update_business_profile(
-    db: &dyn StorageInterface,
+    state: AppState,
     profile_id: &str,
     merchant_id: &str,
     request: api::BusinessProfileUpdate,
 ) -> RouterResponse<api::BusinessProfileResponse> {
+    let db = state.store.as_ref();
     let business_profile = db
         .find_business_profile_by_profile_id(profile_id)
         .await
diff --git a/crates/router/src/core/api_keys.rs b/crates/router/src/core/api_keys.rs
index bd34dee38bd..7bda894826a 100644
--- a/crates/router/src/core/api_keys.rs
+++ b/crates/router/src/core/api_keys.rs
@@ -13,7 +13,6 @@ use crate::{
     configs::settings,
     consts,
     core::errors::{self, RouterResponse, StorageErrorExt},
-    db::StorageInterface,
     routes::{metrics, AppState},
     services::ApplicationResponse,
     types::{api, storage, transformers::ForeignInto},
@@ -131,13 +130,13 @@ impl PlaintextApiKey {
 
 #[instrument(skip_all)]
 pub async fn create_api_key(
-    state: &AppState,
-    api_key_config: &settings::ApiKeys,
+    state: AppState,
     #[cfg(feature = "kms")] kms_client: &kms::KmsClient,
     api_key: api::CreateApiKeyRequest,
     merchant_id: String,
 ) -> RouterResponse<api::CreateApiKeyResponse> {
-    let store = &*state.store;
+    let api_key_config = &state.conf.api_keys;
+    let store = state.store.as_ref();
     // We are not fetching merchant account as the merchant key store is needed to search for a
     // merchant account.
     // Instead, we're only fetching merchant key store, as it is sufficient to identify
@@ -208,7 +207,7 @@ pub async fn create_api_key(
 #[cfg(feature = "email")]
 #[instrument(skip_all)]
 pub async fn add_api_key_expiry_task(
-    store: &dyn StorageInterface,
+    store: &dyn crate::db::StorageInterface,
     api_key: &ApiKey,
     expiry_reminder_days: Vec<u8>,
 ) -> Result<(), errors::ProcessTrackerError> {
@@ -277,10 +276,11 @@ pub async fn add_api_key_expiry_task(
 
 #[instrument(skip_all)]
 pub async fn retrieve_api_key(
-    store: &dyn StorageInterface,
+    state: AppState,
     merchant_id: &str,
     key_id: &str,
 ) -> RouterResponse<api::RetrieveApiKeyResponse> {
+    let store = state.store.as_ref();
     let api_key = store
         .find_api_key_by_merchant_id_key_id_optional(merchant_id, key_id)
         .await
@@ -293,12 +293,12 @@ pub async fn retrieve_api_key(
 
 #[instrument(skip_all)]
 pub async fn update_api_key(
-    state: &AppState,
+    state: AppState,
     merchant_id: &str,
     key_id: &str,
     api_key: api::UpdateApiKeyRequest,
 ) -> RouterResponse<api::RetrieveApiKeyResponse> {
-    let store = &*state.store;
+    let store = state.store.as_ref();
 
     let api_key = store
         .update_api_key(
@@ -372,7 +372,7 @@ pub async fn update_api_key(
 #[cfg(feature = "email")]
 #[instrument(skip_all)]
 pub async fn update_api_key_expiry_task(
-    store: &dyn StorageInterface,
+    store: &dyn crate::db::StorageInterface,
     api_key: &ApiKey,
     expiry_reminder_days: Vec<u8>,
 ) -> Result<(), errors::ProcessTrackerError> {
@@ -429,11 +429,11 @@ pub async fn update_api_key_expiry_task(
 
 #[instrument(skip_all)]
 pub async fn revoke_api_key(
-    state: &AppState,
+    state: AppState,
     merchant_id: &str,
     key_id: &str,
 ) -> RouterResponse<api::RevokeApiKeyResponse> {
-    let store = &*state.store;
+    let store = state.store.as_ref();
     let revoked = store
         .revoke_api_key(merchant_id, key_id)
         .await
@@ -478,7 +478,7 @@ pub async fn revoke_api_key(
 #[cfg(feature = "email")]
 #[instrument(skip_all)]
 pub async fn revoke_api_key_expiry_task(
-    store: &dyn StorageInterface,
+    store: &dyn crate::db::StorageInterface,
     key_id: &str,
 ) -> Result<(), errors::ProcessTrackerError> {
     let task_id = generate_task_id_for_api_key_expiry_workflow(key_id);
@@ -498,11 +498,12 @@ pub async fn revoke_api_key_expiry_task(
 
 #[instrument(skip_all)]
 pub async fn list_api_keys(
-    store: &dyn StorageInterface,
+    state: AppState,
     merchant_id: String,
     limit: Option<i64>,
     offset: Option<i64>,
 ) -> RouterResponse<Vec<api::RetrieveApiKeyResponse>> {
+    let store = state.store.as_ref();
     let api_keys = store
         .list_api_keys_by_merchant_id(&merchant_id, limit, offset)
         .await
diff --git a/crates/router/src/core/cache.rs b/crates/router/src/core/cache.rs
index 124a09e1bd7..cba9a5ec303 100644
--- a/crates/router/src/core/cache.rs
+++ b/crates/router/src/core/cache.rs
@@ -3,15 +3,13 @@ use error_stack::{report, ResultExt};
 use storage_impl::redis::cache::CacheKind;
 
 use super::errors;
-use crate::{
-    db::{cache::publish_into_redact_channel, StorageInterface},
-    services,
-};
+use crate::{db::cache::publish_into_redact_channel, routes::AppState, services};
 
 pub async fn invalidate(
-    store: &dyn StorageInterface,
+    state: AppState,
     key: &str,
 ) -> CustomResult<services::api::ApplicationResponse<serde_json::Value>, errors::ApiErrorResponse> {
+    let store = state.store.as_ref();
     let result = publish_into_redact_channel(store, CacheKind::All(key.into()))
         .await
         .change_context(errors::ApiErrorResponse::InternalServerError)?;
diff --git a/crates/router/src/core/cards_info.rs b/crates/router/src/core/cards_info.rs
index 827bec8333d..4352e1808c7 100644
--- a/crates/router/src/core/cards_info.rs
+++ b/crates/router/src/core/cards_info.rs
@@ -21,11 +21,11 @@ fn verify_iin_length(card_iin: &str) -> Result<(), errors::ApiErrorResponse> {
 
 #[instrument(skip_all)]
 pub async fn retrieve_card_info(
-    state: &routes::AppState,
+    state: routes::AppState,
     merchant_account: domain::MerchantAccount,
     request: api_models::cards_info::CardsInfoRequest,
 ) -> RouterResponse<api_models::cards_info::CardInfoResponse> {
-    let db = &*state.store;
+    let db = state.store.as_ref();
 
     verify_iin_length(&request.card_iin)?;
     helpers::verify_payment_intent_time_and_client_secret(
diff --git a/crates/router/src/core/configs.rs b/crates/router/src/core/configs.rs
index 3c29a81c472..8aa2310416e 100644
--- a/crates/router/src/core/configs.rs
+++ b/crates/router/src/core/configs.rs
@@ -2,15 +2,13 @@ use error_stack::ResultExt;
 
 use crate::{
     core::errors::{self, utils::StorageErrorExt, RouterResponse},
-    db::StorageInterface,
+    routes::AppState,
     services::ApplicationResponse,
     types::{api, transformers::ForeignInto},
 };
 
-pub async fn set_config(
-    store: &dyn StorageInterface,
-    config: api::Config,
-) -> RouterResponse<api::Config> {
+pub async fn set_config(state: AppState, config: api::Config) -> RouterResponse<api::Config> {
+    let store = state.store.as_ref();
     let config = store
         .insert_config(diesel_models::configs::ConfigNew {
             key: config.key,
@@ -23,7 +21,8 @@ pub async fn set_config(
     Ok(ApplicationResponse::Json(config.foreign_into()))
 }
 
-pub async fn read_config(store: &dyn StorageInterface, key: &str) -> RouterResponse<api::Config> {
+pub async fn read_config(state: AppState, key: &str) -> RouterResponse<api::Config> {
+    let store = state.store.as_ref();
     let config = store
         .find_config_by_key(key)
         .await
@@ -32,9 +31,10 @@ pub async fn read_config(store: &dyn StorageInterface, key: &str) -> RouterRespo
 }
 
 pub async fn update_config(
-    store: &dyn StorageInterface,
+    state: AppState,
     config_update: &api::ConfigUpdate,
 ) -> RouterResponse<api::Config> {
+    let store = state.store.as_ref();
     let config = store
         .update_config_by_key(&config_update.key, config_update.foreign_into())
         .await
diff --git a/crates/router/src/core/customers.rs b/crates/router/src/core/customers.rs
index 2397e5fdf93..00cfd3acede 100644
--- a/crates/router/src/core/customers.rs
+++ b/crates/router/src/core/customers.rs
@@ -12,7 +12,6 @@ use crate::{
         errors::{self},
         payment_methods::cards,
     },
-    db::StorageInterface,
     pii::PeekInterface,
     routes::{metrics, AppState},
     services,
@@ -29,13 +28,14 @@ use crate::{
 
 pub const REDACTED: &str = "Redacted";
 
-#[instrument(skip(db))]
+#[instrument(skip(state))]
 pub async fn create_customer(
-    db: &dyn StorageInterface,
+    state: AppState,
     merchant_account: domain::MerchantAccount,
     key_store: domain::MerchantKeyStore,
     mut customer_data: customers::CustomerRequest,
 ) -> errors::CustomerResponse<customers::CustomerResponse> {
+    let db = state.store.as_ref();
     let customer_id = &customer_data.customer_id;
     let merchant_id = &merchant_account.merchant_id;
     customer_data.merchant_id = merchant_id.to_owned();
@@ -152,13 +152,14 @@ pub async fn create_customer(
     Ok(services::ApplicationResponse::Json(customer_response))
 }
 
-#[instrument(skip(db))]
+#[instrument(skip(state))]
 pub async fn retrieve_customer(
-    db: &dyn StorageInterface,
+    state: AppState,
     merchant_account: domain::MerchantAccount,
     key_store: domain::MerchantKeyStore,
     req: customers::CustomerId,
 ) -> errors::CustomerResponse<customers::CustomerResponse> {
+    let db = state.store.as_ref();
     let response = db
         .find_customer_by_customer_id_merchant_id(
             &req.customer_id,
@@ -173,7 +174,7 @@ pub async fn retrieve_customer(
 
 #[instrument(skip_all)]
 pub async fn delete_customer(
-    state: &AppState,
+    state: AppState,
     merchant_account: domain::MerchantAccount,
     req: customers::CustomerId,
     key_store: domain::MerchantKeyStore,
@@ -210,7 +211,7 @@ pub async fn delete_customer(
             for pm in customer_payment_methods.into_iter() {
                 if pm.payment_method == enums::PaymentMethod::Card {
                     cards::delete_card_from_locker(
-                        state,
+                        &state,
                         &req.customer_id,
                         &merchant_account.merchant_id,
                         &pm.payment_method_id,
@@ -311,13 +312,14 @@ pub async fn delete_customer(
     Ok(services::ApplicationResponse::Json(response))
 }
 
-#[instrument(skip(db))]
+#[instrument(skip(state))]
 pub async fn update_customer(
-    db: &dyn StorageInterface,
+    state: AppState,
     merchant_account: domain::MerchantAccount,
     update_customer: customers::CustomerRequest,
     key_store: domain::MerchantKeyStore,
 ) -> errors::CustomerResponse<customers::CustomerResponse> {
+    let db = state.store.as_ref();
     //Add this in update call if customer can be updated anywhere else
     db.find_customer_by_customer_id_merchant_id(
         &update_customer.customer_id,
diff --git a/crates/router/src/core/disputes.rs b/crates/router/src/core/disputes.rs
index f83701ae80e..aaf12acd0a0 100644
--- a/crates/router/src/core/disputes.rs
+++ b/crates/router/src/core/disputes.rs
@@ -25,7 +25,7 @@ use crate::{
 
 #[instrument(skip(state))]
 pub async fn retrieve_dispute(
-    state: &AppState,
+    state: AppState,
     merchant_account: domain::MerchantAccount,
     req: disputes::DisputeId,
 ) -> RouterResponse<api_models::disputes::DisputeResponse> {
@@ -42,7 +42,7 @@ pub async fn retrieve_dispute(
 
 #[instrument(skip(state))]
 pub async fn retrieve_disputes_list(
-    state: &AppState,
+    state: AppState,
     merchant_account: domain::MerchantAccount,
     constraints: api_models::disputes::DisputeListConstraints,
 ) -> RouterResponse<Vec<api_models::disputes::DisputeResponse>> {
@@ -61,7 +61,7 @@ pub async fn retrieve_disputes_list(
 
 #[instrument(skip(state))]
 pub async fn accept_dispute(
-    state: &AppState,
+    state: AppState,
     merchant_account: domain::MerchantAccount,
     key_store: domain::MerchantKeyStore,
     req: disputes::DisputeId,
@@ -116,7 +116,7 @@ pub async fn accept_dispute(
         AcceptDisputeResponse,
     > = connector_data.connector.get_connector_integration();
     let router_data = core_utils::construct_accept_dispute_router_data(
-        state,
+        &state,
         &payment_intent,
         &payment_attempt,
         &merchant_account,
@@ -125,7 +125,7 @@ pub async fn accept_dispute(
     )
     .await?;
     let response = services::execute_connector_processing_step(
-        state,
+        &state,
         connector_integration,
         &router_data,
         payments::CallConnectorAction::Trigger,
@@ -161,7 +161,7 @@ pub async fn accept_dispute(
 
 #[instrument(skip(state))]
 pub async fn submit_evidence(
-    state: &AppState,
+    state: AppState,
     merchant_account: domain::MerchantAccount,
     key_store: domain::MerchantKeyStore,
     req: dispute_models::SubmitEvidenceRequest,
@@ -193,7 +193,7 @@ pub async fn submit_evidence(
         },
     )?;
     let submit_evidence_request_data = transformers::get_evidence_request_data(
-        state,
+        &state,
         &merchant_account,
         &key_store,
         req,
@@ -228,7 +228,7 @@ pub async fn submit_evidence(
         SubmitEvidenceResponse,
     > = connector_data.connector.get_connector_integration();
     let router_data = core_utils::construct_submit_evidence_router_data(
-        state,
+        &state,
         &payment_intent,
         &payment_attempt,
         &merchant_account,
@@ -238,7 +238,7 @@ pub async fn submit_evidence(
     )
     .await?;
     let response = services::execute_connector_processing_step(
-        state,
+        &state,
         connector_integration,
         &router_data,
         payments::CallConnectorAction::Trigger,
@@ -267,7 +267,7 @@ pub async fn submit_evidence(
                 DefendDisputeResponse,
             > = connector_data.connector.get_connector_integration();
             let defend_dispute_router_data = core_utils::construct_defend_dispute_router_data(
-                state,
+                &state,
                 &payment_intent,
                 &payment_attempt,
                 &merchant_account,
@@ -276,7 +276,7 @@ pub async fn submit_evidence(
             )
             .await?;
             let defend_response = services::execute_connector_processing_step(
-                state,
+                &state,
                 connector_integration_defend_dispute,
                 &defend_dispute_router_data,
                 payments::CallConnectorAction::Trigger,
@@ -322,7 +322,7 @@ pub async fn submit_evidence(
 }
 
 pub async fn attach_evidence(
-    state: &AppState,
+    state: AppState,
     merchant_account: domain::MerchantAccount,
     key_store: domain::MerchantKeyStore,
     attach_evidence_request: api::AttachEvidenceRequest,
@@ -357,7 +357,7 @@ pub async fn attach_evidence(
         },
     )?;
     let create_file_response = files::files_create_core(
-        state,
+        state.clone(),
         merchant_account,
         key_store,
         attach_evidence_request.create_file_request,
@@ -399,7 +399,7 @@ pub async fn attach_evidence(
 
 #[instrument(skip(state))]
 pub async fn retrieve_dispute_evidence(
-    state: &AppState,
+    state: AppState,
     merchant_account: domain::MerchantAccount,
     req: disputes::DisputeId,
 ) -> RouterResponse<Vec<api_models::disputes::DisputeEvidenceBlock>> {
@@ -417,6 +417,6 @@ pub async fn retrieve_dispute_evidence(
         .change_context(errors::ApiErrorResponse::InternalServerError)
         .attach_printable("Error while parsing dispute evidence record")?;
     let dispute_evidence_vec =
-        transformers::get_dispute_evidence_vec(state, merchant_account, dispute_evidence).await?;
+        transformers::get_dispute_evidence_vec(&state, merchant_account, dispute_evidence).await?;
     Ok(services::ApplicationResponse::Json(dispute_evidence_vec))
 }
diff --git a/crates/router/src/core/files.rs b/crates/router/src/core/files.rs
index e6a0d3122da..83bfef69e5f 100644
--- a/crates/router/src/core/files.rs
+++ b/crates/router/src/core/files.rs
@@ -17,13 +17,17 @@ use crate::{
 };
 
 pub async fn files_create_core(
-    state: &AppState,
+    state: AppState,
     merchant_account: domain::MerchantAccount,
     key_store: domain::MerchantKeyStore,
     create_file_request: api::CreateFileRequest,
 ) -> RouterResponse<files::CreateFileResponse> {
-    helpers::validate_file_upload(state, merchant_account.clone(), create_file_request.clone())
-        .await?;
+    helpers::validate_file_upload(
+        &state,
+        merchant_account.clone(),
+        create_file_request.clone(),
+    )
+    .await?;
     let file_id = common_utils::generate_id(consts::ID_LENGTH, "file");
     #[cfg(feature = "s3")]
     let file_key = format!("{}/{}", merchant_account.merchant_id, file_id);
@@ -49,7 +53,7 @@ pub async fn files_create_core(
         .attach_printable("Unable to insert file_metadata")?;
     let (provider_file_id, file_upload_provider, connector_label) =
         helpers::upload_and_get_provider_provider_file_id_profile_id(
-            state,
+            &state,
             &merchant_account,
             &key_store,
             &create_file_request,
@@ -65,6 +69,7 @@ pub async fn files_create_core(
     };
     state
         .store
+        .as_ref()
         .update_file_metadata(file_metadata_object, update_file_metadata)
         .await
         .change_context(errors::ApiErrorResponse::InternalServerError)
@@ -77,13 +82,14 @@ pub async fn files_create_core(
 }
 
 pub async fn files_delete_core(
-    state: &AppState,
+    state: AppState,
     merchant_account: domain::MerchantAccount,
     req: api::FileId,
 ) -> RouterResponse<serde_json::Value> {
-    helpers::delete_file_using_file_id(state, req.file_id.clone(), &merchant_account).await?;
+    helpers::delete_file_using_file_id(&state, req.file_id.clone(), &merchant_account).await?;
     state
         .store
+        .as_ref()
         .delete_file_metadata_by_merchant_id_file_id(&merchant_account.merchant_id, &req.file_id)
         .await
         .change_context(errors::ApiErrorResponse::InternalServerError)
@@ -92,20 +98,21 @@ pub async fn files_delete_core(
 }
 
 pub async fn files_retrieve_core(
-    state: &AppState,
+    state: AppState,
     merchant_account: domain::MerchantAccount,
     key_store: domain::MerchantKeyStore,
     req: api::FileId,
 ) -> RouterResponse<serde_json::Value> {
     let file_metadata_object = state
         .store
+        .as_ref()
         .find_file_metadata_by_merchant_id_file_id(&merchant_account.merchant_id, &req.file_id)
         .await
         .change_context(errors::ApiErrorResponse::FileNotFound)
         .attach_printable("Unable to retrieve file_metadata")?;
     let (received_data, _provider_file_id) =
         helpers::retrieve_file_and_provider_file_id_from_file_id(
-            state,
+            &state,
             Some(req.file_id),
             &merchant_account,
             &key_store,
diff --git a/crates/router/src/core/mandate.rs b/crates/router/src/core/mandate.rs
index 34268870fb3..a98ac38e498 100644
--- a/crates/router/src/core/mandate.rs
+++ b/crates/router/src/core/mandate.rs
@@ -25,26 +25,28 @@ use crate::{
 
 #[instrument(skip(state))]
 pub async fn get_mandate(
-    state: &AppState,
+    state: AppState,
     merchant_account: domain::MerchantAccount,
     req: mandates::MandateId,
 ) -> RouterResponse<mandates::MandateResponse> {
     let mandate = state
         .store
+        .as_ref()
         .find_mandate_by_merchant_id_mandate_id(&merchant_account.merchant_id, &req.mandate_id)
         .await
         .to_not_found_response(errors::ApiErrorResponse::MandateNotFound)?;
     Ok(services::ApplicationResponse::Json(
-        mandates::MandateResponse::from_db_mandate(state, mandate).await?,
+        mandates::MandateResponse::from_db_mandate(&state, mandate).await?,
     ))
 }
 
-#[instrument(skip(db))]
+#[instrument(skip(state))]
 pub async fn revoke_mandate(
-    db: &dyn StorageInterface,
+    state: AppState,
     merchant_account: domain::MerchantAccount,
     req: mandates::MandateId,
 ) -> RouterResponse<mandates::MandateRevokedResponse> {
+    let db = state.store.as_ref();
     let mandate = db
         .update_mandate_by_merchant_id_mandate_id(
             &merchant_account.merchant_id,
@@ -97,7 +99,7 @@ pub async fn update_connector_mandate_id(
 
 #[instrument(skip(state))]
 pub async fn get_customer_mandates(
-    state: &AppState,
+    state: AppState,
     merchant_account: domain::MerchantAccount,
     req: customers::CustomerId,
 ) -> RouterResponse<Vec<mandates::MandateResponse>> {
@@ -118,7 +120,7 @@ pub async fn get_customer_mandates(
     } else {
         let mut response_vec = Vec::with_capacity(mandates.len());
         for mandate in mandates {
-            response_vec.push(mandates::MandateResponse::from_db_mandate(state, mandate).await?);
+            response_vec.push(mandates::MandateResponse::from_db_mandate(&state, mandate).await?);
         }
         Ok(services::ApplicationResponse::Json(response_vec))
     }
@@ -273,12 +275,13 @@ where
 
 #[instrument(skip(state))]
 pub async fn retrieve_mandates_list(
-    state: &AppState,
+    state: AppState,
     merchant_account: domain::MerchantAccount,
     constraints: api_models::mandates::MandateListConstraints,
 ) -> RouterResponse<Vec<api_models::mandates::MandateResponse>> {
     let mandates = state
         .store
+        .as_ref()
         .find_mandates_by_merchant_id(&merchant_account.merchant_id, constraints)
         .await
         .change_context(errors::ApiErrorResponse::InternalServerError)
@@ -286,7 +289,7 @@ pub async fn retrieve_mandates_list(
     let mandates_list = future::try_join_all(
         mandates
             .into_iter()
-            .map(|mandate| mandates::MandateResponse::from_db_mandate(state, mandate)),
+            .map(|mandate| mandates::MandateResponse::from_db_mandate(&state, mandate)),
     )
     .await?;
     Ok(services::ApplicationResponse::Json(mandates_list))
diff --git a/crates/router/src/core/payment_methods/cards.rs b/crates/router/src/core/payment_methods/cards.rs
index 12494702105..d74a3320568 100644
--- a/crates/router/src/core/payment_methods/cards.rs
+++ b/crates/router/src/core/payment_methods/cards.rs
@@ -83,7 +83,7 @@ pub async fn create_payment_method(
 
 #[instrument(skip_all)]
 pub async fn add_payment_method(
-    state: &routes::AppState,
+    state: routes::AppState,
     req: api::PaymentMethodCreate,
     merchant_account: &domain::MerchantAccount,
     key_store: &domain::MerchantKeyStore,
@@ -93,7 +93,7 @@ pub async fn add_payment_method(
     let customer_id = req.customer_id.clone().get_required_value("customer_id")?;
     let response = match req.card.clone() {
         Some(card) => add_card_to_locker(
-            state,
+            &state,
             req.clone(),
             card,
             customer_id.clone(),
@@ -152,13 +152,13 @@ pub async fn add_payment_method(
 
 #[instrument(skip_all)]
 pub async fn update_customer_payment_method(
-    state: &routes::AppState,
+    state: routes::AppState,
     merchant_account: domain::MerchantAccount,
     req: api::PaymentMethodUpdate,
     payment_method_id: &str,
     key_store: domain::MerchantKeyStore,
 ) -> errors::RouterResponse<api::PaymentMethodResponse> {
-    let db = &*state.store;
+    let db = state.store.as_ref();
     let pm = db
         .delete_payment_method_by_merchant_id_payment_method_id(
             &merchant_account.merchant_id,
@@ -168,7 +168,7 @@ pub async fn update_customer_payment_method(
         .to_not_found_response(errors::ApiErrorResponse::PaymentMethodNotFound)?;
     if pm.payment_method == enums::PaymentMethod::Card {
         delete_card_from_locker(
-            state,
+            &state,
             &pm.customer_id,
             &pm.merchant_id,
             &pm.payment_method_id,
@@ -251,7 +251,7 @@ pub async fn delete_card_from_locker(
     metrics::DELETE_FROM_LOCKER.add(&metrics::CONTEXT, 1, &[]);
 
     request::record_operation_time(
-        async {
+        async move {
             delete_card_from_hs_locker(state, customer_id, merchant_id, card_reference)
                 .await
                 .map_err(|error| {
@@ -490,7 +490,7 @@ pub async fn get_card_from_hs_locker<'a>(
 
 #[instrument(skip_all)]
 pub async fn delete_card_from_hs_locker<'a>(
-    state: &'a routes::AppState,
+    state: &routes::AppState,
     customer_id: &str,
     merchant_id: &str,
     card_reference: &'a str,
@@ -778,7 +778,7 @@ fn get_val(str: String, val: &serde_json::Value) -> Option<String> {
 }
 
 pub async fn list_payment_methods(
-    state: &routes::AppState,
+    state: routes::AppState,
     merchant_account: domain::MerchantAccount,
     key_store: domain::MerchantKeyStore,
     mut req: api::PaymentMethodListRequest,
@@ -1172,7 +1172,7 @@ pub async fn list_payment_methods(
     for key in banks_consolidated_hm.iter() {
         let payment_method_type = *key.0;
         let connectors = key.1.clone();
-        let bank_names = get_banks(state, payment_method_type, connectors)?;
+        let bank_names = get_banks(&state, payment_method_type, connectors)?;
         bank_redirect_payment_method_types.push({
             ResponsePaymentMethodTypes {
                 payment_method_type,
@@ -1757,15 +1757,15 @@ async fn filter_payment_mandate_based(
 }
 
 pub async fn do_list_customer_pm_fetch_customer_if_not_passed(
-    state: &routes::AppState,
+    state: routes::AppState,
     merchant_account: domain::MerchantAccount,
     key_store: domain::MerchantKeyStore,
     req: Option<api::PaymentMethodListRequest>,
     customer_id: Option<&str>,
 ) -> errors::RouterResponse<api::CustomerPaymentMethodsListResponse> {
-    let db = &*state.store;
+    let db = state.store.as_ref();
     if let Some(customer_id) = customer_id {
-        list_customer_payment_method(state, merchant_account, key_store, None, customer_id).await
+        list_customer_payment_method(&state, merchant_account, key_store, None, customer_id).await
     } else {
         let cloned_secret = req.and_then(|r| r.client_secret.as_ref().cloned());
         let payment_intent = helpers::verify_payment_intent_time_and_client_secret(
@@ -1779,7 +1779,7 @@ pub async fn do_list_customer_pm_fetch_customer_if_not_passed(
             .and_then(|intent| intent.customer_id.to_owned())
             .ok_or(errors::ApiErrorResponse::CustomerNotFound)?;
         list_customer_payment_method(
-            state,
+            &state,
             merchant_account,
             key_store,
             payment_intent,
@@ -2188,17 +2188,17 @@ impl BasiliskCardSupport {
 
 #[instrument(skip_all)]
 pub async fn retrieve_payment_method(
-    state: &routes::AppState,
+    state: routes::AppState,
     pm: api::PaymentMethodId,
 ) -> errors::RouterResponse<api::PaymentMethodResponse> {
-    let db = &*state.store;
+    let db = state.store.as_ref();
     let pm = db
         .find_payment_method(&pm.payment_method_id)
         .await
         .to_not_found_response(errors::ApiErrorResponse::PaymentMethodNotFound)?;
     let card = if pm.payment_method == enums::PaymentMethod::Card {
         let card = get_card_from_locker(
-            state,
+            &state,
             &pm.customer_id,
             &pm.merchant_id,
             &pm.payment_method_id,
@@ -2232,11 +2232,11 @@ pub async fn retrieve_payment_method(
 
 #[instrument(skip_all)]
 pub async fn delete_payment_method(
-    state: &routes::AppState,
+    state: routes::AppState,
     merchant_account: domain::MerchantAccount,
     pm_id: api::PaymentMethodId,
 ) -> errors::RouterResponse<api::PaymentMethodDeleteResponse> {
-    let db = &*state.store;
+    let db = state.store.as_ref();
     let key = db
         .find_payment_method(pm_id.payment_method_id.as_str())
         .await
@@ -2244,7 +2244,7 @@ pub async fn delete_payment_method(
 
     if key.payment_method == enums::PaymentMethod::Card {
         let response = delete_card_from_locker(
-            state,
+            &state,
             &key.customer_id,
             &key.merchant_id,
             pm_id.payment_method_id.as_str(),
diff --git a/crates/router/src/core/payments.rs b/crates/router/src/core/payments.rs
index 03e56306342..9b7d0b3eec5 100644
--- a/crates/router/src/core/payments.rs
+++ b/crates/router/src/core/payments.rs
@@ -237,7 +237,7 @@ where
 
 #[allow(clippy::too_many_arguments)]
 pub async fn payments_core<F, Res, Req, Op, FData>(
-    state: &AppState,
+    state: AppState,
     merchant_account: domain::MerchantAccount,
     key_store: domain::MerchantKeyStore,
     operation: Op,
@@ -264,7 +264,7 @@ where
     PaymentResponse: Operation<F, FData>,
 {
     let (payment_data, req, customer, connector_http_status_code) = payments_operation_core(
-        state,
+        &state,
         merchant_account,
         key_store,
         operation.clone(),
@@ -326,7 +326,7 @@ pub trait PaymentRedirectFlow: Sync {
     #[allow(clippy::too_many_arguments)]
     async fn handle_payments_redirect_response(
         &self,
-        state: &AppState,
+        state: AppState,
         merchant_account: domain::MerchantAccount,
         key_store: domain::MerchantKeyStore,
         req: PaymentsRedirectResponseData,
@@ -372,7 +372,7 @@ pub trait PaymentRedirectFlow: Sync {
 
         let response = self
             .call_payment_flow(
-                state,
+                &state,
                 merchant_account.clone(),
                 key_store,
                 req.clone(),
@@ -420,7 +420,7 @@ impl PaymentRedirectFlow for PaymentRedirectCompleteAuthorize {
             ..Default::default()
         };
         payments_core::<api::CompleteAuthorize, api::PaymentsResponse, _, _, _>(
-            state,
+            state.clone(),
             merchant_account,
             merchant_key_store,
             payment_complete_authorize::CompleteAuthorize,
@@ -515,7 +515,7 @@ impl PaymentRedirectFlow for PaymentRedirectSync {
             expand_captures: None,
         };
         payments_core::<api::PSync, api::PaymentsResponse, _, _, _>(
-            state,
+            state.clone(),
             merchant_account,
             merchant_key_store,
             PaymentStatus,
@@ -1509,14 +1509,14 @@ pub fn is_operation_confirm<Op: Debug>(operation: &Op) -> bool {
 
 #[cfg(feature = "olap")]
 pub async fn list_payments(
-    db: &dyn StorageInterface,
+    state: AppState,
     merchant: domain::MerchantAccount,
     constraints: api::PaymentListConstraints,
 ) -> RouterResponse<api::PaymentListResponse> {
     use data_models::errors::StorageError;
-
     helpers::validate_payment_list_request(&constraints)?;
     let merchant_id = &merchant.merchant_id;
+    let db = state.store.as_ref();
     let payment_intents =
         helpers::filter_by_constraints(db, &constraints, merchant_id, merchant.storage_scheme)
             .await
@@ -1575,13 +1575,13 @@ pub async fn list_payments(
 }
 #[cfg(feature = "olap")]
 pub async fn apply_filters_on_payments(
-    db: &dyn StorageInterface,
+    state: AppState,
     merchant: domain::MerchantAccount,
     constraints: api::PaymentListFilterConstraints,
 ) -> RouterResponse<api::PaymentListResponseV2> {
     let limit = &constraints.limit;
-
     helpers::validate_payment_list_request_for_joins(*limit)?;
+    let db = state.store.as_ref();
     let list: Vec<(storage::PaymentIntent, storage::PaymentAttempt)> = db
         .get_filtered_payment_intents_attempt(
             &merchant.merchant_id,
@@ -1628,10 +1628,11 @@ pub async fn apply_filters_on_payments(
 
 #[cfg(feature = "olap")]
 pub async fn get_filters_for_payments(
-    db: &dyn StorageInterface,
+    state: AppState,
     merchant: domain::MerchantAccount,
     time_range: api::TimeRange,
 ) -> RouterResponse<api::PaymentListFilters> {
+    let db = state.store.as_ref();
     let pi = db
         .filter_payment_intents_by_time_range_constraints(
             &merchant.merchant_id,
diff --git a/crates/router/src/core/payments/helpers.rs b/crates/router/src/core/payments/helpers.rs
index ef6bdc9f79b..7970d4d15b7 100644
--- a/crates/router/src/core/payments/helpers.rs
+++ b/crates/router/src/core/payments/helpers.rs
@@ -1865,7 +1865,7 @@ pub fn make_merchant_url_with_response(
 }
 
 pub async fn make_ephemeral_key(
-    state: &AppState,
+    state: AppState,
     customer_id: String,
     merchant_id: String,
 ) -> errors::RouterResponse<ephemeral_key::EphemeralKey> {
@@ -1887,10 +1887,11 @@ pub async fn make_ephemeral_key(
 }
 
 pub async fn delete_ephemeral_key(
-    store: &dyn StorageInterface,
+    state: AppState,
     ek_id: String,
 ) -> errors::RouterResponse<ephemeral_key::EphemeralKey> {
-    let ek = store
+    let db = state.store.as_ref();
+    let ek = db
         .delete_ephemeral_key(&ek_id)
         .await
         .change_context(errors::ApiErrorResponse::InternalServerError)
diff --git a/crates/router/src/core/payments/operations/payment_create.rs b/crates/router/src/core/payments/operations/payment_create.rs
index b279941097f..32ab96c3597 100644
--- a/crates/router/src/core/payments/operations/payment_create.rs
+++ b/crates/router/src/core/payments/operations/payment_create.rs
@@ -690,7 +690,7 @@ impl PaymentCreate {
     ) -> Option<ephemeral_key::EphemeralKey> {
         match request.customer_id.clone() {
             Some(customer_id) => helpers::make_ephemeral_key(
-                state,
+                state.clone(),
                 customer_id,
                 merchant_account.merchant_id.clone(),
             )
diff --git a/crates/router/src/core/payouts.rs b/crates/router/src/core/payouts.rs
index 60fa889dc48..ed293383f3d 100644
--- a/crates/router/src/core/payouts.rs
+++ b/crates/router/src/core/payouts.rs
@@ -92,7 +92,7 @@ pub async fn get_connector_data(
 #[cfg(feature = "payouts")]
 #[instrument(skip_all)]
 pub async fn payouts_create_core(
-    state: &AppState,
+    state: AppState,
     merchant_account: domain::MerchantAccount,
     key_store: domain::MerchantKeyStore,
     req: payouts::PayoutCreateRequest,
@@ -101,7 +101,7 @@ where
 {
     // Form connector data
     let connector_data = get_connector_data(
-        state,
+        &state,
         &merchant_account,
         req.connector
             .clone()
@@ -112,11 +112,11 @@ where
 
     // Validate create request
     let (payout_id, payout_method_data) =
-        validator::validate_create_request(state, &merchant_account, &req).await?;
+        validator::validate_create_request(&state, &merchant_account, &req).await?;
 
     // Create DB entries
     let mut payout_data = payout_create_db_entries(
-        state,
+        &state,
         &merchant_account,
         &key_store,
         &req,
@@ -127,7 +127,7 @@ where
     .await?;
 
     call_connector_payout(
-        state,
+        &state,
         &merchant_account,
         &key_store,
         &req,
@@ -139,13 +139,13 @@ where
 
 #[cfg(feature = "payouts")]
 pub async fn payouts_update_core(
-    state: &AppState,
+    state: AppState,
     merchant_account: domain::MerchantAccount,
     key_store: domain::MerchantKeyStore,
     req: payouts::PayoutCreateRequest,
 ) -> RouterResponse<payouts::PayoutCreateResponse> {
     let mut payout_data = make_payout_data(
-        state,
+        &state,
         &merchant_account,
         &key_store,
         &payouts::PayoutRequest::PayoutCreateRequest(req.to_owned()),
@@ -236,7 +236,7 @@ pub async fn payouts_update_core(
     .attach_printable("Failed to get the connector data")?;
 
     call_connector_payout(
-        state,
+        &state,
         &merchant_account,
         &key_store,
         &req,
@@ -249,13 +249,13 @@ pub async fn payouts_update_core(
 #[cfg(feature = "payouts")]
 #[instrument(skip_all)]
 pub async fn payouts_retrieve_core(
-    state: &AppState,
+    state: AppState,
     merchant_account: domain::MerchantAccount,
     key_store: domain::MerchantKeyStore,
     req: payouts::PayoutRetrieveRequest,
 ) -> RouterResponse<payouts::PayoutCreateResponse> {
     let payout_data = make_payout_data(
-        state,
+        &state,
         &merchant_account,
         &key_store,
         &payouts::PayoutRequest::PayoutRetrieveRequest(req.to_owned()),
@@ -263,7 +263,7 @@ pub async fn payouts_retrieve_core(
     .await?;
 
     response_handler(
-        state,
+        &state,
         &merchant_account,
         &payouts::PayoutRequest::PayoutRetrieveRequest(req.to_owned()),
         &payout_data,
@@ -274,13 +274,13 @@ pub async fn payouts_retrieve_core(
 #[cfg(feature = "payouts")]
 #[instrument(skip_all)]
 pub async fn payouts_cancel_core(
-    state: &AppState,
+    state: AppState,
     merchant_account: domain::MerchantAccount,
     key_store: domain::MerchantKeyStore,
     req: payouts::PayoutActionRequest,
 ) -> RouterResponse<payouts::PayoutCreateResponse> {
     let mut payout_data = make_payout_data(
-        state,
+        &state,
         &merchant_account,
         &key_store,
         &payouts::PayoutRequest::PayoutActionRequest(req.to_owned()),
@@ -325,7 +325,7 @@ pub async fn payouts_cancel_core(
     } else {
         // Form connector data
         let connector_data = get_connector_data(
-            state,
+            &state,
             &merchant_account,
             Some(payout_attempt.connector),
             None,
@@ -333,7 +333,7 @@ pub async fn payouts_cancel_core(
         .await?;
 
         payout_data = cancel_payout(
-            state,
+            &state,
             &merchant_account,
             &key_store,
             &payouts::PayoutRequest::PayoutActionRequest(req.to_owned()),
@@ -345,7 +345,7 @@ pub async fn payouts_cancel_core(
     }
 
     response_handler(
-        state,
+        &state,
         &merchant_account,
         &payouts::PayoutRequest::PayoutActionRequest(req.to_owned()),
         &payout_data,
@@ -356,13 +356,13 @@ pub async fn payouts_cancel_core(
 #[cfg(feature = "payouts")]
 #[instrument(skip_all)]
 pub async fn payouts_fulfill_core(
-    state: &AppState,
+    state: AppState,
     merchant_account: domain::MerchantAccount,
     key_store: domain::MerchantKeyStore,
     req: payouts::PayoutActionRequest,
 ) -> RouterResponse<payouts::PayoutCreateResponse> {
     let mut payout_data = make_payout_data(
-        state,
+        &state,
         &merchant_account,
         &key_store,
         &payouts::PayoutRequest::PayoutActionRequest(req.to_owned()),
@@ -386,7 +386,7 @@ pub async fn payouts_fulfill_core(
 
     // Form connector data
     let connector_data = get_connector_data(
-        state,
+        &state,
         &merchant_account,
         Some(payout_attempt.connector.clone()),
         None,
@@ -396,7 +396,7 @@ pub async fn payouts_fulfill_core(
     // Trigger fulfillment
     payout_data.payout_method_data = Some(
         helpers::make_payout_method_data(
-            state,
+            &state,
             None,
             payout_attempt.payout_token.as_deref(),
             &payout_attempt.customer_id,
@@ -408,7 +408,7 @@ pub async fn payouts_fulfill_core(
         .get_required_value("payout_method_data")?,
     );
     payout_data = fulfill_payout(
-        state,
+        &state,
         &merchant_account,
         &key_store,
         &payouts::PayoutRequest::PayoutActionRequest(req.to_owned()),
@@ -427,7 +427,7 @@ pub async fn payouts_fulfill_core(
     }
 
     response_handler(
-        state,
+        &state,
         &merchant_account,
         &payouts::PayoutRequest::PayoutActionRequest(req.to_owned()),
         &payout_data,
diff --git a/crates/router/src/core/refunds.rs b/crates/router/src/core/refunds.rs
index 11ed8faa6fb..4ad8344501c 100644
--- a/crates/router/src/core/refunds.rs
+++ b/crates/router/src/core/refunds.rs
@@ -30,7 +30,7 @@ use crate::{
 
 #[instrument(skip_all)]
 pub async fn refund_create_core(
-    state: &AppState,
+    state: AppState,
     merchant_account: domain::MerchantAccount,
     key_store: domain::MerchantKeyStore,
     req: refunds::RefundRequest,
@@ -102,7 +102,7 @@ pub async fn refund_create_core(
         .transpose()?;
 
     validate_and_create_refund(
-        state,
+        &state,
         &merchant_account,
         &key_store,
         &payment_attempt,
@@ -249,14 +249,14 @@ pub async fn trigger_refund_to_gateway(
 // ********************************************** REFUND SYNC **********************************************
 
 pub async fn refund_response_wrapper<'a, F, Fut, T, Req>(
-    state: &'a AppState,
+    state: AppState,
     merchant_account: domain::MerchantAccount,
     key_store: domain::MerchantKeyStore,
     request: Req,
     f: F,
 ) -> RouterResponse<refunds::RefundResponse>
 where
-    F: Fn(&'a AppState, domain::MerchantAccount, domain::MerchantKeyStore, Req) -> Fut,
+    F: Fn(AppState, domain::MerchantAccount, domain::MerchantKeyStore, Req) -> Fut,
     Fut: futures::Future<Output = RouterResult<T>>,
     T: ForeignInto<refunds::RefundResponse>,
 {
@@ -269,7 +269,7 @@ where
 
 #[instrument(skip_all)]
 pub async fn refund_retrieve_core(
-    state: &AppState,
+    state: AppState,
     merchant_account: domain::MerchantAccount,
     key_store: domain::MerchantKeyStore,
     request: refunds::RefundsRetrieveRequest,
@@ -329,7 +329,7 @@ pub async fn refund_retrieve_core(
 
     response = if should_call_refund(&refund, request.force_sync.unwrap_or(false)) {
         sync_refund_with_gateway(
-            state,
+            &state,
             &merchant_account,
             &key_store,
             &payment_attempt,
@@ -465,11 +465,12 @@ pub async fn sync_refund_with_gateway(
 // ********************************************** REFUND UPDATE **********************************************
 
 pub async fn refund_update_core(
-    db: &dyn db::StorageInterface,
+    state: AppState,
     merchant_account: domain::MerchantAccount,
     refund_id: &str,
     req: refunds::RefundUpdateRequest,
 ) -> RouterResponse<refunds::RefundResponse> {
+    let db = state.store.as_ref();
     let refund = db
         .find_refund_by_merchant_id_refund_id(
             &merchant_account.merchant_id,
@@ -644,10 +645,11 @@ pub async fn validate_and_create_refund(
 #[instrument(skip_all)]
 #[cfg(feature = "olap")]
 pub async fn refund_list(
-    db: &dyn db::StorageInterface,
+    state: AppState,
     merchant_account: domain::MerchantAccount,
     req: api_models::refunds::RefundListRequest,
 ) -> RouterResponse<api_models::refunds::RefundListResponse> {
+    let db = state.store;
     let limit = validator::validate_refund_list(req.limit)?;
     let offset = req.offset.unwrap_or_default();
 
@@ -688,10 +690,11 @@ pub async fn refund_list(
 #[instrument(skip_all)]
 #[cfg(feature = "olap")]
 pub async fn refund_filter_list(
-    db: &dyn db::StorageInterface,
+    state: AppState,
     merchant_account: domain::MerchantAccount,
     req: api_models::refunds::TimeRange,
 ) -> RouterResponse<api_models::refunds::RefundListMetaData> {
+    let db = state.store;
     let filter_list = db
         .filter_refund_by_meta_constraints(
             &merchant_account.merchant_id,
@@ -834,7 +837,7 @@ pub async fn sync_refund_with_gateway_workflow(
         .await?;
 
     let response = refund_retrieve_core(
-        state,
+        state.clone(),
         merchant_account,
         key_store,
         refunds::RefundsRetrieveRequest {
diff --git a/crates/router/src/core/verification.rs b/crates/router/src/core/verification.rs
index cc2162908a8..a9dd234ac6c 100644
--- a/crates/router/src/core/verification.rs
+++ b/crates/router/src/core/verification.rs
@@ -8,7 +8,6 @@ use external_services::kms;
 
 use crate::{
     core::errors::{self, api_error_response, utils::StorageErrorExt},
-    db::StorageInterface,
     headers, logger,
     routes::AppState,
     services, types,
@@ -17,7 +16,7 @@ use crate::{
 const APPLEPAY_INTERNAL_MERCHANT_NAME: &str = "Applepay_merchant";
 
 pub async fn verify_merchant_creds_for_applepay(
-    state: &AppState,
+    state: AppState,
     _req: &actix_web::HttpRequest,
     body: web::Json<verifications::ApplepayMerchantVerificationRequest>,
     kms_config: &kms::KmsConfig,
@@ -79,7 +78,7 @@ pub async fn verify_merchant_creds_for_applepay(
         .add_certificate_key(Some(key_data))
         .build();
 
-    let response = services::call_connector_api(state, apple_pay_merch_verification_req).await;
+    let response = services::call_connector_api(&state, apple_pay_merch_verification_req).await;
     utils::log_applepay_verification_response_if_error(&response);
 
     let applepay_response =
@@ -89,7 +88,7 @@ pub async fn verify_merchant_creds_for_applepay(
     Ok(match applepay_response {
         Ok(_) => {
             utils::check_existence_and_add_domain_to_db(
-                state,
+                &state,
                 merchant_id,
                 body.merchant_connector_account_id.clone(),
                 body.domain_names.clone(),
@@ -110,13 +109,14 @@ pub async fn verify_merchant_creds_for_applepay(
 }
 
 pub async fn get_verified_apple_domains_with_mid_mca_id(
-    db: &dyn StorageInterface,
+    state: AppState,
     merchant_id: String,
     merchant_connector_id: String,
 ) -> CustomResult<
     services::ApplicationResponse<api_models::verifications::ApplepayVerifiedDomainsResponse>,
     api_error_response::ApiErrorResponse,
 > {
+    let db = state.store.as_ref();
     let key_store = db
         .get_merchant_key_store_by_merchant_id(&merchant_id, &db.get_master_key().to_vec().into())
         .await
diff --git a/crates/router/src/core/webhooks.rs b/crates/router/src/core/webhooks.rs
index 97f2161285d..3be7e928cb7 100644
--- a/crates/router/src/core/webhooks.rs
+++ b/crates/router/src/core/webhooks.rs
@@ -46,7 +46,7 @@ pub async fn payments_incoming_webhook_flow<W: types::OutgoingWebhookType>(
     let payments_response = match webhook_details.object_reference_id {
         api_models::webhooks::ObjectReferenceId::PaymentId(id) => {
             let response = payments::payments_core::<api::PSync, api::PaymentsResponse, _, _, _>(
-                &state,
+                state.clone(),
                 merchant_account.clone(),
                 key_store,
                 payments::operations::PaymentStatus,
@@ -197,7 +197,7 @@ pub async fn refunds_incoming_webhook_flow<W: types::OutgoingWebhookType>(
         })?
     } else {
         refunds::refund_retrieve_core(
-            &state,
+            state.clone(),
             merchant_account.clone(),
             key_store,
             api_models::refunds::RefundsRetrieveRequest {
@@ -432,7 +432,7 @@ async fn bank_transfer_webhook_flow<W: types::OutgoingWebhookType>(
             ..Default::default()
         };
         payments::payments_core::<api::Authorize, api::PaymentsResponse, _, _, _>(
-            &state,
+            state.clone(),
             merchant_account.to_owned(),
             key_store,
             payments::PaymentConfirm,
@@ -645,8 +645,10 @@ pub async fn trigger_webhook_to_merchant<W: types::OutgoingWebhookType>(
         .body(Some(transformed_outgoing_webhook_string))
         .build();
 
-    let response =
-        services::api::send_request(state, request, Some(OUTGOING_WEBHOOK_TIMEOUT_SECS)).await;
+    let response = state
+        .api_client
+        .send_request(state, request, Some(OUTGOING_WEBHOOK_TIMEOUT_SECS), false)
+        .await;
 
     metrics::WEBHOOK_OUTGOING_COUNT.add(
         &metrics::CONTEXT,
@@ -701,7 +703,7 @@ pub async fn trigger_webhook_to_merchant<W: types::OutgoingWebhookType>(
 
 #[instrument(skip_all)]
 pub async fn webhooks_core<W: types::OutgoingWebhookType>(
-    state: &AppState,
+    state: AppState,
     req: &actix_web::HttpRequest,
     merchant_account: domain::MerchantAccount,
     key_store: domain::MerchantKeyStore,
@@ -725,7 +727,7 @@ pub async fn webhooks_core<W: types::OutgoingWebhookType>(
     };
 
     let (merchant_connector_account, connector) = fetch_mca_and_connector(
-        state,
+        state.clone(),
         &merchant_account,
         connector_name_or_mca_id,
         &key_store,
@@ -739,7 +741,7 @@ pub async fn webhooks_core<W: types::OutgoingWebhookType>(
 
     let decoded_body = connector
         .decode_webhook_body(
-            &*state.store,
+            &*state.clone().store,
             &request_details,
             &merchant_account.merchant_id,
         )
@@ -752,7 +754,13 @@ pub async fn webhooks_core<W: types::OutgoingWebhookType>(
     let event_type = match connector
         .get_webhook_event_type(&request_details)
         .allow_webhook_event_type_not_found(
-            state.conf.webhooks.ignore_error.event_type.unwrap_or(true),
+            state
+                .clone()
+                .conf
+                .webhooks
+                .ignore_error
+                .event_type
+                .unwrap_or(true),
         )
         .switch()
         .attach_printable("Could not find event type in incoming webhook body")?
@@ -782,7 +790,7 @@ pub async fn webhooks_core<W: types::OutgoingWebhookType>(
     };
 
     let process_webhook_further = utils::lookup_webhook_event(
-        &*state.store,
+        &*state.clone().store,
         connector_name.as_str(),
         &merchant_account.merchant_id,
         &event_type,
@@ -915,7 +923,7 @@ pub async fn webhooks_core<W: types::OutgoingWebhookType>(
 }
 
 async fn fetch_mca_and_connector(
-    state: &AppState,
+    state: AppState,
     merchant_account: &domain::MerchantAccount,
     connector_name_or_mca_id: &str,
     key_store: &domain::MerchantKeyStore,
diff --git a/crates/router/src/lib.rs b/crates/router/src/lib.rs
index f96d0efb5c5..738646b2964 100644
--- a/crates/router/src/lib.rs
+++ b/crates/router/src/lib.rs
@@ -64,7 +64,7 @@ pub mod headers {
     pub const X_ACCEPT_VERSION: &str = "X-Accept-Version";
     pub const X_DATE: &str = "X-Date";
     pub const X_WEBHOOK_SIGNATURE: &str = "X-Webhook-Signature-512";
-
+    pub const X_REQUEST_ID: &str = "X-Request-Id";
     pub const STRIPE_COMPATIBLE_WEBHOOK_SIGNATURE: &str = "Stripe-Signature";
 }
 
diff --git a/crates/router/src/routes/admin.rs b/crates/router/src/routes/admin.rs
index bfafb8fd19f..f36094f2d4a 100644
--- a/crates/router/src/routes/admin.rs
+++ b/crates/router/src/routes/admin.rs
@@ -32,10 +32,10 @@ pub async fn merchant_account_create(
     let flow = Flow::MerchantsAccountCreate;
     api::server_wrap(
         flow,
-        state.get_ref(),
+        state,
         &req,
         json_payload.into_inner(),
-        |state, _, req| create_merchant_account(&*state.store, req),
+        |state, _, req| create_merchant_account(state, req),
         &auth::AdminApiAuth,
     )
     .await
@@ -68,10 +68,10 @@ pub async fn retrieve_merchant_account(
 
     api::server_wrap(
         flow,
-        state.get_ref(),
+        state,
         &req,
         payload,
-        |state, _, req| get_merchant_account(&*state.store, req),
+        |state, _, req| get_merchant_account(state, req),
         &auth::AdminApiAuth,
     )
     .await
@@ -104,10 +104,10 @@ pub async fn update_merchant_account(
     let merchant_id = mid.into_inner();
     api::server_wrap(
         flow,
-        state.get_ref(),
+        state,
         &req,
         json_payload.into_inner(),
-        |state, _, req| merchant_account_update(&*state.store, &merchant_id, req),
+        |state, _, req| merchant_account_update(state, &merchant_id, req),
         &auth::AdminApiAuth,
     )
     .await
@@ -137,7 +137,6 @@ pub async fn delete_merchant_account(
 ) -> HttpResponse {
     let flow = Flow::MerchantsAccountDelete;
     let mid = mid.into_inner();
-    let state = state.get_ref();
 
     let payload = web::Json(admin::MerchantId { merchant_id: mid }).into_inner();
     api::server_wrap(
@@ -145,7 +144,7 @@ pub async fn delete_merchant_account(
         state,
         &req,
         payload,
-        |state, _, req| merchant_account_delete(&*state.store, req.merchant_id),
+        |state, _, req| merchant_account_delete(state, req.merchant_id),
         &auth::AdminApiAuth,
     )
     .await
@@ -177,7 +176,7 @@ pub async fn payment_connector_create(
     let merchant_id = path.into_inner();
     api::server_wrap(
         flow,
-        state.get_ref(),
+        state,
         &req,
         json_payload.into_inner(),
         |state, _, req| create_payment_connector(state, req, &merchant_id),
@@ -221,11 +220,11 @@ pub async fn payment_connector_retrieve(
 
     api::server_wrap(
         flow,
-        state.get_ref(),
+        state,
         &req,
         payload,
         |state, _, req| {
-            retrieve_payment_connector(&*state.store, req.merchant_id, req.merchant_connector_id)
+            retrieve_payment_connector(state, req.merchant_id, req.merchant_connector_id)
         },
         &auth::AdminApiAuth,
     )
@@ -261,10 +260,10 @@ pub async fn payment_connector_list(
 
     api::server_wrap(
         flow,
-        state.get_ref(),
+        state,
         &req,
         merchant_id,
-        |state, _, merchant_id| list_payment_connectors(&*state.store, merchant_id),
+        |state, _, merchant_id| list_payment_connectors(state, merchant_id),
         &auth::AdminApiAuth,
     )
     .await
@@ -302,12 +301,10 @@ pub async fn payment_connector_update(
 
     api::server_wrap(
         flow,
-        state.get_ref(),
+        state,
         &req,
         json_payload.into_inner(),
-        |state, _, req| {
-            update_payment_connector(&*state.store, &merchant_id, &merchant_connector_id, req)
-        },
+        |state, _, req| update_payment_connector(state, &merchant_id, &merchant_connector_id, req),
         &auth::AdminApiAuth,
     )
     .await
@@ -348,12 +345,10 @@ pub async fn payment_connector_delete(
     .into_inner();
     api::server_wrap(
         flow,
-        state.get_ref(),
+        state,
         &req,
         payload,
-        |state, _, req| {
-            delete_payment_connector(&*state.store, req.merchant_id, req.merchant_connector_id)
-        },
+        |state, _, req| delete_payment_connector(state, req.merchant_id, req.merchant_connector_id),
         &auth::AdminApiAuth,
     )
     .await
@@ -375,12 +370,10 @@ pub async fn merchant_account_toggle_kv(
 
     api::server_wrap(
         flow,
-        state.get_ref(),
+        state,
         &req,
         (merchant_id, payload),
-        |state, _, (merchant_id, payload)| {
-            kv_for_merchant(&*state.store, merchant_id, payload.kv_enabled)
-        },
+        |state, _, (merchant_id, payload)| kv_for_merchant(state, merchant_id, payload.kv_enabled),
         &auth::AdminApiAuth,
     )
     .await
@@ -399,10 +392,10 @@ pub async fn business_profile_create(
 
     api::server_wrap(
         flow,
-        state.get_ref(),
+        state,
         &req,
         payload,
-        |state, _, req| create_business_profile(&*state.store, req, &merchant_id),
+        |state, _, req| create_business_profile(state, req, &merchant_id),
         &auth::AdminApiAuth,
     )
     .await
@@ -419,10 +412,10 @@ pub async fn business_profile_retrieve(
 
     api::server_wrap(
         flow,
-        state.get_ref(),
+        state,
         &req,
         profile_id,
-        |state, _, profile_id| retrieve_business_profile(&*state.store, profile_id),
+        |state, _, profile_id| retrieve_business_profile(state, profile_id),
         &auth::AdminApiAuth,
     )
     .await
@@ -440,10 +433,10 @@ pub async fn business_profile_update(
 
     api::server_wrap(
         flow,
-        state.get_ref(),
+        state,
         &req,
         json_payload.into_inner(),
-        |state, _, req| update_business_profile(&*state.store, &profile_id, &merchant_id, req),
+        |state, _, req| update_business_profile(state, &profile_id, &merchant_id, req),
         &auth::AdminApiAuth,
     )
     .await
@@ -460,10 +453,10 @@ pub async fn business_profile_delete(
 
     api::server_wrap(
         flow,
-        state.get_ref(),
+        state,
         &req,
         profile_id,
-        |state, _, profile_id| delete_business_profile(&*state.store, profile_id, &merchant_id),
+        |state, _, profile_id| delete_business_profile(state, profile_id, &merchant_id),
         &auth::AdminApiAuth,
     )
     .await
@@ -480,10 +473,10 @@ pub async fn business_profiles_list(
 
     api::server_wrap(
         flow,
-        state.get_ref(),
+        state,
         &req,
         merchant_id,
-        |state, _, merchant_id| list_business_profile(&*state.store, merchant_id),
+        |state, _, merchant_id| list_business_profile(state, merchant_id),
         &auth::AdminApiAuth,
     )
     .await
@@ -503,10 +496,10 @@ pub async fn merchant_account_kv_status(
 
     api::server_wrap(
         flow,
-        state.get_ref(),
+        state,
         &req,
         merchant_id,
-        |state, _, req| check_merchant_account_kv_status(&*state.store, req),
+        |state, _, req| check_merchant_account_kv_status(state, req),
         &auth::AdminApiAuth,
     )
     .await
diff --git a/crates/router/src/routes/api_keys.rs b/crates/router/src/routes/api_keys.rs
index 9d5ca08e634..28f5e928704 100644
--- a/crates/router/src/routes/api_keys.rs
+++ b/crates/router/src/routes/api_keys.rs
@@ -38,15 +38,16 @@ pub async fn api_key_create(
 
     api::server_wrap(
         flow,
-        state.get_ref(),
+        state,
         &req,
         payload,
         |state, _, payload| async {
+            #[cfg(feature = "kms")]
+            let kms_client = external_services::kms::get_kms_client(&state.clone().conf.kms).await;
             api_keys::create_api_key(
                 state,
-                &state.conf.api_keys,
                 #[cfg(feature = "kms")]
-                external_services::kms::get_kms_client(&state.conf.kms).await,
+                kms_client,
                 payload,
                 merchant_id.clone(),
             )
@@ -86,12 +87,10 @@ pub async fn api_key_retrieve(
 
     api::server_wrap(
         flow,
-        state.get_ref(),
+        state,
         &req,
         (&merchant_id, &key_id),
-        |state, _, (merchant_id, key_id)| {
-            api_keys::retrieve_api_key(&*state.store, merchant_id, key_id)
-        },
+        |state, _, (merchant_id, key_id)| api_keys::retrieve_api_key(state, merchant_id, key_id),
         &auth::AdminApiAuth,
     )
     .await
@@ -129,7 +128,7 @@ pub async fn api_key_update(
 
     api::server_wrap(
         flow,
-        state.get_ref(),
+        state,
         &req,
         (&merchant_id, &key_id, payload),
         |state, _, (merchant_id, key_id, payload)| {
@@ -170,7 +169,7 @@ pub async fn api_key_revoke(
 
     api::server_wrap(
         flow,
-        state.get_ref(),
+        state,
         &req,
         (&merchant_id, &key_id),
         |state, _, (merchant_id, key_id)| api_keys::revoke_api_key(state, merchant_id, key_id),
@@ -212,11 +211,11 @@ pub async fn api_key_list(
 
     api::server_wrap(
         flow,
-        state.get_ref(),
+        state,
         &req,
         (limit, offset, merchant_id),
         |state, _, (limit, offset, merchant_id)| async move {
-            api_keys::list_api_keys(&*state.store, merchant_id, limit, offset).await
+            api_keys::list_api_keys(state, merchant_id, limit, offset).await
         },
         &auth::AdminApiAuth,
     )
diff --git a/crates/router/src/routes/app.rs b/crates/router/src/routes/app.rs
index d5691279bc3..dca1fd3e402 100644
--- a/crates/router/src/routes/app.rs
+++ b/crates/router/src/routes/app.rs
@@ -1,3 +1,5 @@
+use std::sync::Arc;
+
 use actix_web::{web, Scope};
 #[cfg(feature = "email")]
 use external_services::email::{AwsSes, EmailClient};
@@ -31,11 +33,11 @@ use crate::{
 pub struct AppState {
     pub flow_name: String,
     pub store: Box<dyn StorageInterface>,
-    pub conf: settings::Settings,
+    pub conf: Arc<settings::Settings>,
     #[cfg(feature = "email")]
-    pub email_client: Box<dyn EmailClient>,
+    pub email_client: Arc<dyn EmailClient>,
     #[cfg(feature = "kms")]
-    pub kms_secrets: settings::ActiveKmsSecrets,
+    pub kms_secrets: Arc<settings::ActiveKmsSecrets>,
     pub api_client: Box<dyn crate::services::ApiClient>,
 }
 
@@ -47,26 +49,40 @@ impl scheduler::SchedulerAppState for AppState {
 
 pub trait AppStateInfo {
     fn conf(&self) -> settings::Settings;
-    fn flow_name(&self) -> String;
     fn store(&self) -> Box<dyn StorageInterface>;
     #[cfg(feature = "email")]
-    fn email_client(&self) -> Box<dyn EmailClient>;
+    fn email_client(&self) -> Arc<dyn EmailClient>;
+    fn add_request_id(&mut self, request_id: Option<String>);
+    fn add_merchant_id(&mut self, merchant_id: Option<String>);
+    fn add_flow_name(&mut self, flow_name: String);
 }
 
 impl AppStateInfo for AppState {
     fn conf(&self) -> settings::Settings {
-        self.conf.to_owned()
-    }
-    fn flow_name(&self) -> String {
-        self.flow_name.to_owned()
+        self.conf.as_ref().to_owned()
     }
     fn store(&self) -> Box<dyn StorageInterface> {
         self.store.to_owned()
     }
     #[cfg(feature = "email")]
-    fn email_client(&self) -> Box<dyn EmailClient> {
+    fn email_client(&self) -> Arc<dyn EmailClient> {
         self.email_client.to_owned()
     }
+    fn add_request_id(&mut self, request_id: Option<String>) {
+        self.api_client.add_request_id(request_id);
+    }
+    fn add_merchant_id(&mut self, merchant_id: Option<String>) {
+        self.api_client.add_merchant_id(merchant_id);
+    }
+    fn add_flow_name(&mut self, flow_name: String) {
+        self.flow_name = flow_name;
+    }
+}
+
+impl AsRef<Self> for AppState {
+    fn as_ref(&self) -> &Self {
+        self
+    }
 }
 
 impl AppState {
@@ -107,15 +123,15 @@ impl AppState {
         .expect("Failed while performing KMS decryption");
 
         #[cfg(feature = "email")]
-        let email_client = Box::new(AwsSes::new(&conf.email).await);
+        let email_client = Arc::new(AwsSes::new(&conf.email).await);
         Self {
             flow_name: String::from("default"),
             store,
-            conf,
+            conf: Arc::new(conf),
             #[cfg(feature = "email")]
             email_client,
             #[cfg(feature = "kms")]
-            kms_secrets,
+            kms_secrets: Arc::new(kms_secrets),
             api_client,
         }
     }
diff --git a/crates/router/src/routes/cache.rs b/crates/router/src/routes/cache.rs
index 4a54a9bb627..419f8a95f26 100644
--- a/crates/router/src/routes/cache.rs
+++ b/crates/router/src/routes/cache.rs
@@ -19,10 +19,10 @@ pub async fn invalidate(
 
     api::server_wrap(
         flow,
-        state.get_ref(),
+        state,
         &req,
         &key,
-        |state, _, key| cache::invalidate(&*state.store, key),
+        |state, _, key| cache::invalidate(state, key),
         &auth::AdminApiAuth,
     )
     .await
diff --git a/crates/router/src/routes/cards_info.rs b/crates/router/src/routes/cards_info.rs
index 9586d926893..ff2acacf9bf 100644
--- a/crates/router/src/routes/cards_info.rs
+++ b/crates/router/src/routes/cards_info.rs
@@ -43,7 +43,7 @@ pub async fn card_iin_info(
 
     api::server_wrap(
         Flow::CardsInfo,
-        state.as_ref(),
+        state,
         &req,
         payload,
         |state, auth, req| cards_info::retrieve_card_info(state, auth.merchant_account, req),
diff --git a/crates/router/src/routes/configs.rs b/crates/router/src/routes/configs.rs
index 16c15db6638..e48e8770183 100644
--- a/crates/router/src/routes/configs.rs
+++ b/crates/router/src/routes/configs.rs
@@ -19,10 +19,10 @@ pub async fn config_key_create(
 
     api::server_wrap(
         flow,
-        state.get_ref(),
+        state,
         &req,
         payload,
-        |state, _, data| configs::set_config(&*state.store, data),
+        |state, _, data| configs::set_config(state, data),
         &auth::AdminApiAuth,
     )
     .await
@@ -39,10 +39,10 @@ pub async fn config_key_retrieve(
 
     api::server_wrap(
         flow,
-        state.get_ref(),
+        state,
         &req,
         &key,
-        |state, _, key| configs::read_config(&*state.store, key),
+        |state, _, key| configs::read_config(state, key),
         &auth::AdminApiAuth,
     )
     .await
@@ -62,10 +62,10 @@ pub async fn config_key_update(
 
     api::server_wrap(
         flow,
-        state.get_ref(),
+        state,
         &req,
         &payload,
-        |state, _, payload| configs::update_config(&*state.store, payload),
+        |state, _, payload| configs::update_config(state, payload),
         &auth::AdminApiAuth,
     )
     .await
diff --git a/crates/router/src/routes/customers.rs b/crates/router/src/routes/customers.rs
index 321da8a8cc4..1ad822efcdf 100644
--- a/crates/router/src/routes/customers.rs
+++ b/crates/router/src/routes/customers.rs
@@ -32,12 +32,10 @@ pub async fn customers_create(
     let flow = Flow::CustomersCreate;
     api::server_wrap(
         flow,
-        state.get_ref(),
+        state,
         &req,
         json_payload.into_inner(),
-        |state, auth, req| {
-            create_customer(&*state.store, auth.merchant_account, auth.key_store, req)
-        },
+        |state, auth, req| create_customer(state, auth.merchant_account, auth.key_store, req),
         &auth::ApiKeyAuth,
     )
     .await
@@ -78,12 +76,10 @@ pub async fn customers_retrieve(
 
     api::server_wrap(
         flow,
-        state.get_ref(),
+        state,
         &req,
         payload,
-        |state, auth, req| {
-            retrieve_customer(&*state.store, auth.merchant_account, auth.key_store, req)
-        },
+        |state, auth, req| retrieve_customer(state, auth.merchant_account, auth.key_store, req),
         &*auth,
     )
     .await
@@ -117,12 +113,10 @@ pub async fn customers_update(
     json_payload.customer_id = customer_id;
     api::server_wrap(
         flow,
-        state.get_ref(),
+        state,
         &req,
         json_payload.into_inner(),
-        |state, auth, req| {
-            update_customer(&*state.store, auth.merchant_account, req, auth.key_store)
-        },
+        |state, auth, req| update_customer(state, auth.merchant_account, req, auth.key_store),
         &auth::ApiKeyAuth,
     )
     .await
@@ -156,7 +150,7 @@ pub async fn customers_delete(
     .into_inner();
     api::server_wrap(
         flow,
-        state.get_ref(),
+        state,
         &req,
         payload,
         |state, auth, req| delete_customer(state, auth.merchant_account, req, auth.key_store),
@@ -178,7 +172,7 @@ pub async fn get_customer_mandates(
 
     api::server_wrap(
         flow,
-        state.get_ref(),
+        state,
         &req,
         customer_id,
         |state, auth, req| {
diff --git a/crates/router/src/routes/disputes.rs b/crates/router/src/routes/disputes.rs
index 7747569e709..61574a55280 100644
--- a/crates/router/src/routes/disputes.rs
+++ b/crates/router/src/routes/disputes.rs
@@ -38,7 +38,7 @@ pub async fn retrieve_dispute(
     };
     api::server_wrap(
         flow,
-        state.get_ref(),
+        state,
         &req,
         dispute_id,
         |state, auth, req| disputes::retrieve_dispute(state, auth.merchant_account, req),
@@ -81,7 +81,7 @@ pub async fn retrieve_disputes_list(
     let payload = payload.into_inner();
     api::server_wrap(
         flow,
-        state.get_ref(),
+        state,
         &req,
         payload,
         |state, auth, req| disputes::retrieve_disputes_list(state, auth.merchant_account, req),
@@ -117,7 +117,7 @@ pub async fn accept_dispute(
     };
     api::server_wrap(
         flow,
-        state.get_ref(),
+        state,
         &req,
         dispute_id,
         |state, auth, req| {
@@ -150,7 +150,7 @@ pub async fn submit_dispute_evidence(
     let flow = Flow::DisputesEvidenceSubmit;
     api::server_wrap(
         flow,
-        state.get_ref(),
+        state,
         &req,
         json_payload.into_inner(),
         |state, auth, req| {
@@ -191,7 +191,7 @@ pub async fn attach_dispute_evidence(
     };
     api::server_wrap(
         flow,
-        state.get_ref(),
+        state,
         &req,
         attach_evidence_request,
         |state, auth, req| {
@@ -229,7 +229,7 @@ pub async fn retrieve_dispute_evidence(
     };
     api::server_wrap(
         flow,
-        state.get_ref(),
+        state,
         &req,
         dispute_id,
         |state, auth, req| disputes::retrieve_dispute_evidence(state, auth.merchant_account, req),
diff --git a/crates/router/src/routes/dummy_connector.rs b/crates/router/src/routes/dummy_connector.rs
index e21f9d4dd9b..f64b7ceb77c 100644
--- a/crates/router/src/routes/dummy_connector.rs
+++ b/crates/router/src/routes/dummy_connector.rs
@@ -21,7 +21,7 @@ pub async fn dummy_connector_authorize_payment(
     let payload = types::DummyConnectorPaymentConfirmRequest { attempt_id };
     api::server_wrap(
         flow,
-        state.get_ref(),
+        state,
         &req,
         payload,
         |state, _, req| core::payment_authorize(state, req),
@@ -45,7 +45,7 @@ pub async fn dummy_connector_complete_payment(
     };
     api::server_wrap(
         flow,
-        state.get_ref(),
+        state,
         &req,
         payload,
         |state, _, req| core::payment_complete(state, req),
@@ -64,7 +64,7 @@ pub async fn dummy_connector_payment(
     let flow = types::Flow::DummyPaymentCreate;
     api::server_wrap(
         flow,
-        state.get_ref(),
+        state,
         &req,
         payload,
         |state, _, req| core::payment(state, req),
@@ -84,7 +84,7 @@ pub async fn dummy_connector_payment_data(
     let payload = types::DummyConnectorPaymentRetrieveRequest { payment_id };
     api::server_wrap(
         flow,
-        state.get_ref(),
+        state,
         &req,
         payload,
         |state, _, req| core::payment_data(state, req),
@@ -105,7 +105,7 @@ pub async fn dummy_connector_refund(
     payload.payment_id = Some(path.to_string());
     api::server_wrap(
         flow,
-        state.get_ref(),
+        state,
         &req,
         payload,
         |state, _, req| core::refund_payment(state, req),
@@ -125,7 +125,7 @@ pub async fn dummy_connector_refund_data(
     let payload = types::DummyConnectorRefundRetrieveRequest { refund_id };
     api::server_wrap(
         flow,
-        state.get_ref(),
+        state,
         &req,
         payload,
         |state, _, req| core::refund_data(state, req),
diff --git a/crates/router/src/routes/dummy_connector/core.rs b/crates/router/src/routes/dummy_connector/core.rs
index 64bd3a7d3a9..e8f84b3047e 100644
--- a/crates/router/src/routes/dummy_connector/core.rs
+++ b/crates/router/src/routes/dummy_connector/core.rs
@@ -10,7 +10,7 @@ use crate::{
 };
 
 pub async fn payment(
-    state: &AppState,
+    state: AppState,
     req: types::DummyConnectorPaymentRequest,
 ) -> types::DummyConnectorResponse<types::DummyConnectorPaymentResponse> {
     utils::tokio_mock_sleep(
@@ -21,17 +21,17 @@ pub async fn payment(
 
     let payment_attempt: types::DummyConnectorPaymentAttempt = req.into();
     let payment_data =
-        types::DummyConnectorPaymentData::process_payment_attempt(state, payment_attempt)?;
+        types::DummyConnectorPaymentData::process_payment_attempt(&state, payment_attempt)?;
 
     utils::store_data_in_redis(
-        state,
+        &state,
         payment_data.attempt_id.clone(),
         payment_data.payment_id.clone(),
         state.conf.dummy_connector.authorize_ttl,
     )
     .await?;
     utils::store_data_in_redis(
-        state,
+        &state,
         payment_data.payment_id.clone(),
         payment_data.clone(),
         state.conf.dummy_connector.payment_ttl,
@@ -41,7 +41,7 @@ pub async fn payment(
 }
 
 pub async fn payment_data(
-    state: &AppState,
+    state: AppState,
     req: types::DummyConnectorPaymentRetrieveRequest,
 ) -> types::DummyConnectorResponse<types::DummyConnectorPaymentResponse> {
     utils::tokio_mock_sleep(
@@ -50,15 +50,15 @@ pub async fn payment_data(
     )
     .await;
 
-    let payment_data = utils::get_payment_data_from_payment_id(state, req.payment_id).await?;
+    let payment_data = utils::get_payment_data_from_payment_id(&state, req.payment_id).await?;
     Ok(api::ApplicationResponse::Json(payment_data.into()))
 }
 
 pub async fn payment_authorize(
-    state: &AppState,
+    state: AppState,
     req: types::DummyConnectorPaymentConfirmRequest,
 ) -> types::DummyConnectorResponse<String> {
-    let payment_data = utils::get_payment_data_by_attempt_id(state, req.attempt_id.clone()).await;
+    let payment_data = utils::get_payment_data_by_attempt_id(&state, req.attempt_id.clone()).await;
     let dummy_connector_conf = &state.conf.dummy_connector;
 
     if let Ok(payment_data_inner) = payment_data {
@@ -83,7 +83,7 @@ pub async fn payment_authorize(
 }
 
 pub async fn payment_complete(
-    state: &AppState,
+    state: AppState,
     req: types::DummyConnectorPaymentCompleteRequest,
 ) -> types::DummyConnectorResponse<()> {
     utils::tokio_mock_sleep(
@@ -92,7 +92,7 @@ pub async fn payment_complete(
     )
     .await;
 
-    let payment_data = utils::get_payment_data_by_attempt_id(state, req.attempt_id.clone()).await;
+    let payment_data = utils::get_payment_data_by_attempt_id(&state, req.attempt_id.clone()).await;
 
     let payment_status = if req.confirm {
         types::DummyConnectorStatus::Succeeded
@@ -115,7 +115,7 @@ pub async fn payment_complete(
             ..payment_data
         };
         utils::store_data_in_redis(
-            state,
+            &state,
             updated_payment_data.payment_id.clone(),
             updated_payment_data.clone(),
             state.conf.dummy_connector.payment_ttl,
@@ -145,7 +145,7 @@ pub async fn payment_complete(
 }
 
 pub async fn refund_payment(
-    state: &AppState,
+    state: AppState,
     req: types::DummyConnectorRefundRequest,
 ) -> types::DummyConnectorResponse<types::DummyConnectorRefundResponse> {
     utils::tokio_mock_sleep(
@@ -162,7 +162,7 @@ pub async fn refund_payment(
         })?;
 
     let mut payment_data =
-        utils::get_payment_data_from_payment_id(state, payment_id.clone()).await?;
+        utils::get_payment_data_from_payment_id(&state, payment_id.clone()).await?;
 
     payment_data.is_eligible_for_refund(req.amount)?;
 
@@ -170,7 +170,7 @@ pub async fn refund_payment(
     payment_data.eligible_amount -= req.amount;
 
     utils::store_data_in_redis(
-        state,
+        &state,
         payment_id,
         payment_data.to_owned(),
         state.conf.dummy_connector.payment_ttl,
@@ -187,7 +187,7 @@ pub async fn refund_payment(
     );
 
     utils::store_data_in_redis(
-        state,
+        &state,
         refund_id,
         refund_data.to_owned(),
         state.conf.dummy_connector.refund_ttl,
@@ -197,7 +197,7 @@ pub async fn refund_payment(
 }
 
 pub async fn refund_data(
-    state: &AppState,
+    state: AppState,
     req: types::DummyConnectorRefundRetrieveRequest,
 ) -> types::DummyConnectorResponse<types::DummyConnectorRefundResponse> {
     let refund_id = req.refund_id;
diff --git a/crates/router/src/routes/ephemeral_key.rs b/crates/router/src/routes/ephemeral_key.rs
index 7d49ef444fd..e0b407c5ba3 100644
--- a/crates/router/src/routes/ephemeral_key.rs
+++ b/crates/router/src/routes/ephemeral_key.rs
@@ -18,7 +18,7 @@ pub async fn ephemeral_key_create(
     let payload = json_payload.into_inner();
     api::server_wrap(
         flow,
-        state.get_ref(),
+        state,
         &req,
         payload,
         |state, auth, req| {
@@ -39,10 +39,10 @@ pub async fn ephemeral_key_delete(
     let payload = path.into_inner();
     api::server_wrap(
         flow,
-        state.get_ref(),
+        state,
         &req,
         payload,
-        |state, _, req| helpers::delete_ephemeral_key(&*state.store, req),
+        |state, _, req| helpers::delete_ephemeral_key(state, req),
         &auth::ApiKeyAuth,
     )
     .await
diff --git a/crates/router/src/routes/files.rs b/crates/router/src/routes/files.rs
index 6b643f3b5c3..cfb3aba6bf9 100644
--- a/crates/router/src/routes/files.rs
+++ b/crates/router/src/routes/files.rs
@@ -39,7 +39,7 @@ pub async fn files_create(
     };
     api::server_wrap(
         flow,
-        state.get_ref(),
+        state,
         &req,
         create_file_request,
         |state, auth, req| files_create_core(state, auth.merchant_account, auth.key_store, req),
@@ -77,7 +77,7 @@ pub async fn files_delete(
     };
     api::server_wrap(
         flow,
-        state.get_ref(),
+        state,
         &req,
         file_id,
         |state, auth, req| files_delete_core(state, auth.merchant_account, req),
@@ -115,7 +115,7 @@ pub async fn files_retrieve(
     };
     api::server_wrap(
         flow,
-        state.get_ref(),
+        state,
         &req,
         file_id,
         |state, auth, req| files_retrieve_core(state, auth.merchant_account, auth.key_store, req),
diff --git a/crates/router/src/routes/mandates.rs b/crates/router/src/routes/mandates.rs
index 77feade91c3..d9f32be8cc1 100644
--- a/crates/router/src/routes/mandates.rs
+++ b/crates/router/src/routes/mandates.rs
@@ -38,7 +38,7 @@ pub async fn get_mandate(
     };
     api::server_wrap(
         flow,
-        state.get_ref(),
+        state,
         &req,
         mandate_id,
         |state, auth, req| mandate::get_mandate(state, auth.merchant_account, req),
@@ -77,10 +77,10 @@ pub async fn revoke_mandate(
     };
     api::server_wrap(
         flow,
-        state.get_ref(),
+        state,
         &req,
         mandate_id,
-        |state, auth, req| mandate::revoke_mandate(&*state.store, auth.merchant_account, req),
+        |state, auth, req| mandate::revoke_mandate(state, auth.merchant_account, req),
         &auth::ApiKeyAuth,
     )
     .await
@@ -118,7 +118,7 @@ pub async fn retrieve_mandates_list(
     let payload = payload.into_inner();
     api::server_wrap(
         flow,
-        state.get_ref(),
+        state,
         &req,
         payload,
         |state, auth, req| mandate::retrieve_mandates_list(state, auth.merchant_account, req),
diff --git a/crates/router/src/routes/payment_methods.rs b/crates/router/src/routes/payment_methods.rs
index c828c045683..5b7a9cb8421 100644
--- a/crates/router/src/routes/payment_methods.rs
+++ b/crates/router/src/routes/payment_methods.rs
@@ -36,7 +36,7 @@ pub async fn create_payment_method_api(
     let flow = Flow::PaymentMethodsCreate;
     api::server_wrap(
         flow,
-        state.get_ref(),
+        state,
         &req,
         json_payload.into_inner(),
         |state, auth, req| async move {
@@ -86,7 +86,7 @@ pub async fn list_payment_method_api(
 
     api::server_wrap(
         flow,
-        state.get_ref(),
+        state,
         &req,
         payload,
         |state, auth, req| {
@@ -137,7 +137,7 @@ pub async fn list_customer_payment_method_api(
     let customer_id = customer_id.into_inner().0;
     api::server_wrap(
         flow,
-        state.get_ref(),
+        state,
         &req,
         payload,
         |state, auth, req| {
@@ -193,7 +193,7 @@ pub async fn list_customer_payment_method_api_client(
     };
     api::server_wrap(
         flow,
-        state.get_ref(),
+        state,
         &req,
         payload,
         |state, auth, req| {
@@ -241,7 +241,7 @@ pub async fn payment_method_retrieve_api(
 
     api::server_wrap(
         flow,
-        state.get_ref(),
+        state,
         &req,
         payload,
         |state, _auth, pm| cards::retrieve_payment_method(state, pm),
@@ -280,7 +280,7 @@ pub async fn payment_method_update_api(
 
     api::server_wrap(
         flow,
-        state.get_ref(),
+        state,
         &req,
         json_payload.into_inner(),
         |state, auth, payload| {
@@ -326,7 +326,7 @@ pub async fn payment_method_delete_api(
     };
     api::server_wrap(
         flow,
-        state.get_ref(),
+        state,
         &req,
         pm,
         |state, auth, req| cards::delete_payment_method(state, auth.merchant_account, req),
diff --git a/crates/router/src/routes/payments.rs b/crates/router/src/routes/payments.rs
index c0508ca9277..2e73a205544 100644
--- a/crates/router/src/routes/payments.rs
+++ b/crates/router/src/routes/payments.rs
@@ -98,7 +98,7 @@ pub async fn payments_create(
 
     api::server_wrap(
         flow,
-        state.get_ref(),
+        state,
         &req,
         payload,
         |state, auth, req| {
@@ -149,7 +149,7 @@ pub async fn payments_start(
         attempt_id: attempt_id.clone(),
     };
     api::server_wrap(flow,
-        state.get_ref(),
+        state,
         &req,
         payload,
         |state,auth, req| {
@@ -213,7 +213,7 @@ pub async fn payments_retrieve(
 
     api::server_wrap(
         flow,
-        state.get_ref(),
+        state,
         &req,
         payload,
         |state, auth, req| {
@@ -271,7 +271,7 @@ pub async fn payments_retrieve_with_gateway_creds(
     let flow = Flow::PaymentsRetrieve;
     api::server_wrap(
         flow,
-        state.get_ref(),
+        state,
         &req,
         payload,
         |state, auth, req| {
@@ -335,7 +335,7 @@ pub async fn payments_update(
 
     api::server_wrap(
         flow,
-        state.get_ref(),
+        state,
         &req,
         payload,
         |state, auth, req| {
@@ -408,7 +408,7 @@ pub async fn payments_confirm(
         };
     api::server_wrap(
         flow,
-        state.get_ref(),
+        state,
         &req,
         payload,
         |state, auth, req| {
@@ -461,7 +461,7 @@ pub async fn payments_capture(
 
     api::server_wrap(
         flow,
-        state.get_ref(),
+        state,
         &req,
         capture_payload,
         |state, auth, payload| {
@@ -507,7 +507,7 @@ pub async fn payments_connector_session(
 
     api::server_wrap(
         flow,
-        state.get_ref(),
+        state,
         &req,
         sessions_payload,
         |state, auth, payload| {
@@ -573,7 +573,7 @@ pub async fn payments_redirect_response(
     };
     api::server_wrap(
         flow,
-        state.get_ref(),
+        state,
         &req,
         payload,
         |state, auth, req| {
@@ -628,7 +628,7 @@ pub async fn payments_redirect_response_with_creds_identifier(
     let flow = Flow::PaymentsRedirect;
     api::server_wrap(
         flow,
-        state.get_ref(),
+        state,
         &req,
         payload,
         |state, auth, req| {
@@ -666,7 +666,7 @@ pub async fn payments_complete_authorize(
     };
     api::server_wrap(
         flow,
-        state.get_ref(),
+        state,
         &req,
         payload,
         |state, auth, req| {
@@ -714,7 +714,7 @@ pub async fn payments_cancel(
     payload.payment_id = payment_id;
     api::server_wrap(
         flow,
-        state.get_ref(),
+        state,
         &req,
         payload,
         |state, auth, req| {
@@ -770,10 +770,10 @@ pub async fn payments_list(
     let payload = payload.into_inner();
     api::server_wrap(
         flow,
-        state.get_ref(),
+        state,
         &req,
         payload,
-        |state, auth, req| payments::list_payments(&*state.store, auth.merchant_account, req),
+        |state, auth, req| payments::list_payments(state, auth.merchant_account, req),
         &auth::ApiKeyAuth,
     )
     .await
@@ -790,12 +790,10 @@ pub async fn payments_list_by_filter(
     let payload = payload.into_inner();
     api::server_wrap(
         flow,
-        state.get_ref(),
+        state,
         &req,
         payload,
-        |state, auth, req| {
-            payments::apply_filters_on_payments(&*state.store, auth.merchant_account, req)
-        },
+        |state, auth, req| payments::apply_filters_on_payments(state, auth.merchant_account, req),
         &auth::ApiKeyAuth,
     )
     .await
@@ -812,12 +810,10 @@ pub async fn get_filters_for_payments(
     let payload = payload.into_inner();
     api::server_wrap(
         flow,
-        state.get_ref(),
+        state,
         &req,
         payload,
-        |state, auth, req| {
-            payments::get_filters_for_payments(&*state.store, auth.merchant_account, req)
-        },
+        |state, auth, req| payments::get_filters_for_payments(state, auth.merchant_account, req),
         &auth::ApiKeyAuth,
     )
     .await
@@ -825,7 +821,7 @@ pub async fn get_filters_for_payments(
 
 async fn authorize_verify_select<Op>(
     operation: Op,
-    state: &app::AppState,
+    state: app::AppState,
     merchant_account: domain::MerchantAccount,
     key_store: domain::MerchantKeyStore,
     header_payload: HeaderPayload,
diff --git a/crates/router/src/routes/payouts.rs b/crates/router/src/routes/payouts.rs
index 987866acb47..468b92030ba 100644
--- a/crates/router/src/routes/payouts.rs
+++ b/crates/router/src/routes/payouts.rs
@@ -32,7 +32,7 @@ pub async fn payouts_create(
     let flow = Flow::PayoutsCreate;
     api::server_wrap(
         flow,
-        state.get_ref(),
+        state,
         &req,
         json_payload.into_inner(),
         |state, auth, req| payouts_create_core(state, auth.merchant_account, auth.key_store, req),
@@ -71,7 +71,7 @@ pub async fn payouts_retrieve(
     let flow = Flow::PayoutsRetrieve;
     api::server_wrap(
         flow,
-        state.get_ref(),
+        state,
         &req,
         payout_retrieve_request,
         |state, auth, req| payouts_retrieve_core(state, auth.merchant_account, auth.key_store, req),
@@ -110,7 +110,7 @@ pub async fn payouts_update(
     payout_update_payload.payout_id = Some(payout_id);
     api::server_wrap(
         flow,
-        state.get_ref(),
+        state,
         &req,
         payout_update_payload,
         |state, auth, req| payouts_update_core(state, auth.merchant_account, auth.key_store, req),
@@ -149,7 +149,7 @@ pub async fn payouts_cancel(
 
     api::server_wrap(
         flow,
-        state.get_ref(),
+        state,
         &req,
         payload,
         |state, auth, req| payouts_cancel_core(state, auth.merchant_account, auth.key_store, req),
@@ -188,7 +188,7 @@ pub async fn payouts_fulfill(
 
     api::server_wrap(
         flow,
-        state.get_ref(),
+        state,
         &req,
         payload,
         |state, auth, req| payouts_fulfill_core(state, auth.merchant_account, auth.key_store, req),
diff --git a/crates/router/src/routes/refunds.rs b/crates/router/src/routes/refunds.rs
index 781da3e0b60..b5789c9a1e9 100644
--- a/crates/router/src/routes/refunds.rs
+++ b/crates/router/src/routes/refunds.rs
@@ -33,7 +33,7 @@ pub async fn refunds_create(
     let flow = Flow::RefundsCreate;
     api::server_wrap(
         flow,
-        state.get_ref(),
+        state,
         &req,
         json_payload.into_inner(),
         |state, auth, req| refund_create_core(state, auth.merchant_account, auth.key_store, req),
@@ -76,7 +76,7 @@ pub async fn refunds_retrieve(
 
     api::server_wrap(
         flow,
-        state.get_ref(),
+        state,
         &req,
         refund_request,
         |state, auth, refund_request| {
@@ -117,7 +117,7 @@ pub async fn refunds_retrieve_with_body(
     let flow = Flow::RefundsRetrieve;
     api::server_wrap(
         flow,
-        state.get_ref(),
+        state,
         &req,
         json_payload.into_inner(),
         |state, auth, req| {
@@ -164,12 +164,10 @@ pub async fn refunds_update(
     let refund_id = path.into_inner();
     api::server_wrap(
         flow,
-        state.get_ref(),
+        state,
         &req,
         json_payload.into_inner(),
-        |state, auth, req| {
-            refund_update_core(&*state.store, auth.merchant_account, &refund_id, req)
-        },
+        |state, auth, req| refund_update_core(state, auth.merchant_account, &refund_id, req),
         &auth::ApiKeyAuth,
     )
     .await
@@ -199,10 +197,10 @@ pub async fn refunds_list(
     let flow = Flow::RefundsList;
     api::server_wrap(
         flow,
-        state.get_ref(),
+        state,
         &req,
         payload.into_inner(),
-        |state, auth, req| refund_list(&*state.store, auth.merchant_account, req),
+        |state, auth, req| refund_list(state, auth.merchant_account, req),
         &auth::ApiKeyAuth,
     )
     .await
@@ -232,10 +230,10 @@ pub async fn refunds_filter_list(
     let flow = Flow::RefundsList;
     api::server_wrap(
         flow,
-        state.get_ref(),
+        state,
         &req,
         payload.into_inner(),
-        |state, auth, req| refund_filter_list(&*state.store, auth.merchant_account, req),
+        |state, auth, req| refund_filter_list(state, auth.merchant_account, req),
         &auth::ApiKeyAuth,
     )
     .await
diff --git a/crates/router/src/routes/verification.rs b/crates/router/src/routes/verification.rs
index 4ccaf12825a..8173d00b84e 100644
--- a/crates/router/src/routes/verification.rs
+++ b/crates/router/src/routes/verification.rs
@@ -17,17 +17,18 @@ pub async fn apple_pay_merchant_registration(
 ) -> impl Responder {
     let flow = Flow::Verification;
     let merchant_id = path.into_inner();
+    let kms_conf = &state.clone().conf.kms;
     api::server_wrap(
         flow,
-        state.get_ref(),
+        state,
         &req,
         json_payload,
         |state, _, body| {
             verification::verify_merchant_creds_for_applepay(
-                state,
+                state.clone(),
                 &req,
                 body,
-                &state.conf.kms,
+                kms_conf,
                 merchant_id.clone(),
             )
         },
@@ -48,12 +49,12 @@ pub async fn retrieve_apple_pay_verified_domains(
 
     api::server_wrap(
         flow,
-        state.get_ref(),
+        state,
         &req,
         merchant_id.clone(),
         |state, _, _| {
             verification::get_verified_apple_domains_with_mid_mca_id(
-                &*state.store,
+                state,
                 merchant_id.to_string(),
                 mca_id.to_string(),
             )
diff --git a/crates/router/src/routes/webhooks.rs b/crates/router/src/routes/webhooks.rs
index b8740321472..c92b8bfd581 100644
--- a/crates/router/src/routes/webhooks.rs
+++ b/crates/router/src/routes/webhooks.rs
@@ -19,7 +19,7 @@ pub async fn receive_incoming_webhook<W: types::OutgoingWebhookType>(
 
     api::server_wrap(
         flow,
-        state.get_ref(),
+        state,
         &req,
         body,
         |state, auth, body| {
diff --git a/crates/router/src/services/api.rs b/crates/router/src/services/api.rs
index feee1db5e4a..dc25d567864 100644
--- a/crates/router/src/services/api.rs
+++ b/crates/router/src/services/api.rs
@@ -1,4 +1,4 @@
-mod client;
+pub mod client;
 pub mod request;
 
 use std::{
@@ -10,14 +10,14 @@ use std::{
     time::{Duration, Instant},
 };
 
-use actix_web::{body, HttpRequest, HttpResponse, Responder, ResponseError};
+use actix_web::{body, web, FromRequest, HttpRequest, HttpResponse, Responder, ResponseError};
 use api_models::enums::CaptureMethod;
 pub use client::{proxy_bypass_urls, ApiClient, MockApiClient, ProxyClient};
 use common_utils::errors::ReportSwitchExt;
 pub use common_utils::request::{ContentType, Method, Request, RequestBuilder};
 use error_stack::{report, IntoReport, Report, ResultExt};
 use masking::{ExposeOptionInterface, PeekInterface};
-use router_env::{instrument, tracing, Tag};
+use router_env::{instrument, tracing, tracing_actix_web::RequestId, Tag};
 use serde::Serialize;
 use serde_json::json;
 
@@ -416,7 +416,10 @@ pub async fn call_connector_api(
 ) -> CustomResult<Result<types::Response, types::Response>, errors::ApiClientError> {
     let current_time = Instant::now();
 
-    let response = send_request(state, request, None).await;
+    let response = state
+        .api_client
+        .send_request(state, request, None, true)
+        .await;
 
     let elapsed_time = current_time.elapsed();
     logger::info!(request_time=?elapsed_time);
@@ -449,8 +452,18 @@ pub async fn send_request(
         request.certificate,
         request.certificate_key,
     )?;
-    let headers = request.headers.construct_header_map()?;
 
+    let mut headers_with_request_id = request.headers;
+    headers_with_request_id.insert((
+        crate::headers::X_REQUEST_ID.to_string(),
+        state
+            .api_client
+            .get_request_id()
+            .ok_or(errors::ApiClientError::InternalServerErrorReceived)
+            .into_report()?
+            .into(),
+    ));
+    let headers = headers_with_request_id.construct_header_map()?;
     let metrics_tag = router_env::opentelemetry::KeyValue {
         key: consts::METRICS_HOST_TAG_NAME.into(),
         value: url.host_str().unwrap_or_default().to_string().into(),
@@ -704,35 +717,50 @@ pub enum AuthFlow {
 #[instrument(skip(request, payload, state, func, api_auth), fields(merchant_id))]
 pub async fn server_wrap_util<'a, 'b, A, U, T, Q, F, Fut, E, OErr>(
     flow: &'a impl router_env::types::FlowMetric,
-    state: &'b A,
+    state: web::Data<A>,
     request: &'a HttpRequest,
     payload: T,
     func: F,
     api_auth: &dyn auth::AuthenticateAndFetch<U, A>,
 ) -> CustomResult<ApplicationResponse<Q>, OErr>
 where
-    F: Fn(&'b A, U, T) -> Fut,
+    F: Fn(A, U, T) -> Fut,
     'b: 'a,
     Fut: Future<Output = CustomResult<ApplicationResponse<Q>, E>>,
     Q: Serialize + Debug + 'a,
     T: Debug,
-    A: AppStateInfo,
+    A: AppStateInfo + Clone,
     U: auth::AuthInfo,
     CustomResult<ApplicationResponse<Q>, E>: ReportSwitchExt<ApplicationResponse<Q>, OErr>,
     CustomResult<U, errors::ApiErrorResponse>: ReportSwitchExt<U, OErr>,
     OErr: ResponseError + Sync + Send + 'static,
 {
+    let request_id = RequestId::extract(request)
+        .await
+        .ok()
+        .map(|id| id.as_hyphenated().to_string());
+
+    let mut request_state = state.get_ref().clone();
+
+    request_state.add_request_id(request_id);
+
     let auth_out = api_auth
-        .authenticate_and_fetch(request.headers(), state)
+        .authenticate_and_fetch(request.headers(), &request_state)
         .await
         .switch()?;
+
     let merchant_id = auth_out
         .get_merchant_id()
         .unwrap_or("MERCHANT_ID_NOT_FOUND")
         .to_string();
+
+    request_state.add_merchant_id(Some(merchant_id.clone()));
+
+    request_state.add_flow_name(flow.to_string());
+
     tracing::Span::current().record("merchant_id", &merchant_id);
 
-    let output = func(state, auth_out, payload).await.switch();
+    let output = func(request_state, auth_out, payload).await.switch();
 
     let status_code = match output.as_ref() {
         Ok(res) => metrics::request::track_response_status_code(res),
@@ -748,21 +776,21 @@ where
     skip(request, state, func, api_auth, payload),
     fields(request_method, request_url_path)
 )]
-pub async fn server_wrap<'a, 'b, A, T, U, Q, F, Fut, E>(
+pub async fn server_wrap<'a, A, T, U, Q, F, Fut, E>(
     flow: impl router_env::types::FlowMetric,
-    state: &'b A,
+    state: web::Data<A>,
     request: &'a HttpRequest,
     payload: T,
     func: F,
     api_auth: &dyn auth::AuthenticateAndFetch<U, A>,
 ) -> HttpResponse
 where
-    F: Fn(&'b A, U, T) -> Fut,
+    F: Fn(A, U, T) -> Fut,
     Fut: Future<Output = CustomResult<ApplicationResponse<Q>, E>>,
     Q: Serialize + Debug + 'a,
     T: Debug,
     U: auth::AuthInfo,
-    A: AppStateInfo,
+    A: AppStateInfo + Clone,
     ApplicationResponse<Q>: Debug,
     CustomResult<ApplicationResponse<Q>, E>:
         ReportSwitchExt<ApplicationResponse<Q>, api_models::errors::types::ApiErrorResponse>,
@@ -776,7 +804,7 @@ where
     logger::info!(tag = ?Tag::BeginRequest, payload = ?payload);
 
     let res = match metrics::request::record_request_time_metric(
-        server_wrap_util(&flow, state, request, payload, func, api_auth),
+        server_wrap_util(&flow, state.clone(), request, payload, func, api_auth),
         &flow,
     )
     .await
diff --git a/crates/router/src/services/api/client.rs b/crates/router/src/services/api/client.rs
index 4ffeb82df0e..f9bbff00846 100644
--- a/crates/router/src/services/api/client.rs
+++ b/crates/router/src/services/api/client.rs
@@ -6,13 +6,14 @@ use masking::PeekInterface;
 use once_cell::sync::OnceCell;
 use reqwest::multipart::Form;
 
-use super::request::Maskable;
+use super::{request::Maskable, Request};
 use crate::{
     configs::settings::{Locker, Proxy},
     core::{
         errors::{ApiClientError, CustomResult},
         payments,
     },
+    routes::AppState,
 };
 
 static NON_PROXIED_CLIENT: OnceCell<reqwest::Client> = OnceCell::new();
@@ -140,6 +141,7 @@ pub trait RequestBuilder: Send + Sync {
     >;
 }
 
+#[async_trait::async_trait]
 pub trait ApiClient: dyn_clone::DynClone
 where
     Self: Send + Sync,
@@ -156,6 +158,19 @@ where
         certificate: Option<String>,
         certificate_key: Option<String>,
     ) -> CustomResult<Box<dyn RequestBuilder>, ApiClientError>;
+
+    async fn send_request(
+        &self,
+        state: &AppState,
+        request: Request,
+        option_timeout_secs: Option<u64>,
+        forward_to_kafka: bool,
+    ) -> CustomResult<reqwest::Response, ApiClientError>;
+
+    fn add_request_id(&mut self, _request_id: Option<String>);
+    fn get_request_id(&self) -> Option<String>;
+    fn add_merchant_id(&mut self, _merchant_id: Option<String>);
+    fn add_flow_name(&mut self, _flow_name: String);
 }
 
 dyn_clone::clone_trait_object!(ApiClient);
@@ -165,6 +180,7 @@ pub struct ProxyClient {
     proxy_client: reqwest::Client,
     non_proxy_client: reqwest::Client,
     whitelisted_urls: Vec<String>,
+    request_id: Option<String>,
 }
 
 impl ProxyClient {
@@ -205,9 +221,11 @@ impl ProxyClient {
             proxy_client,
             non_proxy_client,
             whitelisted_urls,
+            request_id: None,
         })
     }
-    fn get_reqwest_client(
+
+    pub fn get_reqwest_client(
         &self,
         base_url: String,
         client_certificate: Option<String>,
@@ -298,6 +316,7 @@ impl RequestBuilder for RouterRequestBuilder {
 
 // TODO: remove this when integrating this trait
 #[allow(dead_code)]
+#[async_trait::async_trait]
 impl ApiClient for ProxyClient {
     fn request(
         &self,
@@ -321,6 +340,27 @@ impl ApiClient for ProxyClient {
             inner: Some(client_builder.request(method, url)),
         }))
     }
+    async fn send_request(
+        &self,
+        state: &AppState,
+        request: Request,
+        option_timeout_secs: Option<u64>,
+        _forward_to_kafka: bool,
+    ) -> CustomResult<reqwest::Response, ApiClientError> {
+        crate::services::send_request(state, request, option_timeout_secs).await
+    }
+
+    fn add_request_id(&mut self, _request_id: Option<String>) {
+        self.request_id = _request_id
+    }
+
+    fn get_request_id(&self) -> Option<String> {
+        self.request_id.clone()
+    }
+
+    fn add_merchant_id(&mut self, _merchant_id: Option<String>) {}
+
+    fn add_flow_name(&mut self, _flow_name: String) {}
 }
 
 ///
@@ -329,6 +369,7 @@ impl ApiClient for ProxyClient {
 #[derive(Clone)]
 pub struct MockApiClient;
 
+#[async_trait::async_trait]
 impl ApiClient for MockApiClient {
     fn request(
         &self,
@@ -349,4 +390,28 @@ impl ApiClient for MockApiClient {
         // [#2066]: Add Mock implementation for ApiClient
         Err(ApiClientError::UnexpectedState.into())
     }
+
+    async fn send_request(
+        &self,
+        _state: &AppState,
+        _request: Request,
+        _option_timeout_secs: Option<u64>,
+        _forward_to_kafka: bool,
+    ) -> CustomResult<reqwest::Response, ApiClientError> {
+        // [#2066]: Add Mock implementation for ApiClient
+        Err(ApiClientError::UnexpectedState.into())
+    }
+
+    fn add_request_id(&mut self, _request_id: Option<String>) {
+        // [#2066]: Add Mock implementation for ApiClient
+    }
+
+    fn get_request_id(&self) -> Option<String> {
+        // [#2066]: Add Mock implementation for ApiClient
+        None
+    }
+
+    fn add_merchant_id(&mut self, _merchant_id: Option<String>) {}
+
+    fn add_flow_name(&mut self, _flow_name: String) {}
 }
diff --git a/crates/router/tests/payments.rs b/crates/router/tests/payments.rs
index f3e4ab1b152..1bff639d346 100644
--- a/crates/router/tests/payments.rs
+++ b/crates/router/tests/payments.rs
@@ -362,7 +362,7 @@ async fn payments_create_core() {
         services::ApplicationResponse::JsonWithHeaders((expected_response, vec![]));
     let actual_response =
         payments::payments_core::<api::Authorize, api::PaymentsResponse, _, _, _>(
-            &state,
+            state,
             merchant_account,
             key_store,
             payments::PaymentCreate,
@@ -532,7 +532,7 @@ async fn payments_create_core_adyen_no_redirect() {
     ));
     let actual_response =
         payments::payments_core::<api::Authorize, api::PaymentsResponse, _, _, _>(
-            &state,
+            state,
             merchant_account,
             key_store,
             payments::PaymentCreate,
diff --git a/crates/router/tests/payments2.rs b/crates/router/tests/payments2.rs
index 9d7af81022d..91b2a454eea 100644
--- a/crates/router/tests/payments2.rs
+++ b/crates/router/tests/payments2.rs
@@ -122,7 +122,7 @@ async fn payments_create_core() {
         services::ApplicationResponse::JsonWithHeaders((expected_response, vec![]));
     let actual_response =
         router::core::payments::payments_core::<api::Authorize, api::PaymentsResponse, _, _, _>(
-            &state,
+            state,
             merchant_account,
             key_store,
             payments::PaymentCreate,
@@ -294,7 +294,7 @@ async fn payments_create_core_adyen_no_redirect() {
     ));
     let actual_response =
         router::core::payments::payments_core::<api::Authorize, api::PaymentsResponse, _, _, _>(
-            &state,
+            state,
             merchant_account,
             key_store,
             payments::PaymentCreate,

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

- [x] New feature
- [x] Refactoring

## Description
<!-- Describe your changes in detail -->
This PR adds additional parameters in `AppState` : `request_id` and `merchant_id` and a couple of functions in AppStateInfo : for adding `merchant_id` and for adding `flow_name` alongside refactoring `AppState` references.

## 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).
-->
This PR closes https://github.com/juspay/hyperswitch/issues/2132.

## 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)?
-->
Manually using Postman.

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