diff --git a/crates/router/src/bin/scheduler.rs b/crates/router/src/bin/scheduler.rs index 62c8c03e1a97..e18ed318be17 100644 --- a/crates/router/src/bin/scheduler.rs +++ b/crates/router/src/bin/scheduler.rs @@ -158,7 +158,7 @@ pub async fn deep_health_check( let app_state = Arc::clone(&state.into_inner()); let service_name = service.into_inner(); for (tenant, _) in stores { - let session_state_res = app_state.clone().get_session_state(&tenant, || { + let session_state_res = app_state.clone().get_session_state(&tenant, None, || { errors::ApiErrorResponse::MissingRequiredField { field_name: "tenant_id", } @@ -397,7 +397,7 @@ async fn start_scheduler( WorkflowRunner {}, |state, tenant| { Arc::new(state.clone()) - .get_session_state(tenant, || ProcessTrackerError::TenantNotFound.into()) + .get_session_state(tenant, None, || ProcessTrackerError::TenantNotFound.into()) }, ) .await diff --git a/crates/router/src/core/payment_link.rs b/crates/router/src/core/payment_link.rs index 498a00c240df..477803c92a27 100644 --- a/crates/router/src/core/payment_link.rs +++ b/crates/router/src/core/payment_link.rs @@ -6,7 +6,7 @@ use api_models::{ }; use common_utils::{ consts::{DEFAULT_LOCALE, DEFAULT_SESSION_EXPIRY}, - ext_traits::{AsyncExt, OptionExt, ValueExt}, + ext_traits::{OptionExt, ValueExt}, types::{AmountConvertor, StringMajorUnitForCore}, }; use error_stack::{report, ResultExt}; @@ -28,9 +28,8 @@ use crate::{ }, errors::RouterResponse, get_payment_link_config_value, get_payment_link_config_value_based_on_priority, - headers::ACCEPT_LANGUAGE, routes::SessionState, - services::{self, authentication::get_header_value_by_key}, + services, types::{ api::payment_link::PaymentLinkResponseExt, domain, @@ -70,7 +69,6 @@ pub async fn form_payment_link_data( key_store: domain::MerchantKeyStore, merchant_id: common_utils::id_type::MerchantId, payment_id: common_utils::id_type::PaymentId, - locale: Option, ) -> RouterResult<(PaymentLink, PaymentLinkData, PaymentLinkConfig)> { todo!() } @@ -82,7 +80,6 @@ pub async fn form_payment_link_data( key_store: domain::MerchantKeyStore, merchant_id: common_utils::id_type::MerchantId, payment_id: common_utils::id_type::PaymentId, - locale: Option, ) -> RouterResult<(PaymentLink, PaymentLinkData, PaymentLinkConfig)> { let db = &*state.store; let key_manager_state = &state.into(); @@ -242,7 +239,7 @@ pub async fn form_payment_link_data( redirect: false, theme: payment_link_config.theme.clone(), return_url: return_url.clone(), - locale: locale.clone(), + locale: Some(state.clone().locale), transaction_details: payment_link_config.transaction_details.clone(), unified_code: payment_attempt.unified_code, unified_message: payment_attempt.unified_message, @@ -273,7 +270,7 @@ pub async fn form_payment_link_data( display_sdk_only: payment_link_config.display_sdk_only, hide_card_nickname_field: payment_link_config.hide_card_nickname_field, show_card_form_by_default: payment_link_config.show_card_form_by_default, - locale, + locale: Some(state.clone().locale), transaction_details: payment_link_config.transaction_details.clone(), background_image: payment_link_config.background_image.clone(), details_layout: payment_link_config.details_layout, @@ -296,17 +293,9 @@ pub async fn initiate_secure_payment_link_flow( payment_id: common_utils::id_type::PaymentId, request_headers: &header::HeaderMap, ) -> RouterResponse { - let locale = get_header_value_by_key(ACCEPT_LANGUAGE.into(), request_headers)? - .map(|val| val.to_string()); - let (payment_link, payment_link_details, payment_link_config) = form_payment_link_data( - &state, - merchant_account, - key_store, - merchant_id, - payment_id, - locale, - ) - .await?; + let (payment_link, payment_link_details, payment_link_config) = + form_payment_link_data(&state, merchant_account, key_store, merchant_id, payment_id) + .await?; validator::validate_secure_payment_link_render_request( request_headers, @@ -396,19 +385,10 @@ pub async fn initiate_payment_link_flow( key_store: domain::MerchantKeyStore, merchant_id: common_utils::id_type::MerchantId, payment_id: common_utils::id_type::PaymentId, - request_headers: &header::HeaderMap, ) -> RouterResponse { - let locale = get_header_value_by_key(ACCEPT_LANGUAGE.into(), request_headers)? - .map(|val| val.to_string()); - let (_, payment_details, payment_link_config) = form_payment_link_data( - &state, - merchant_account, - key_store, - merchant_id, - payment_id, - locale, - ) - .await?; + let (_, payment_details, payment_link_config) = + form_payment_link_data(&state, merchant_account, key_store, merchant_id, payment_id) + .await?; let css_script = get_color_scheme_css(&payment_link_config); let js_script = get_js_script(&payment_details)?; @@ -727,7 +707,6 @@ pub async fn get_payment_link_status( _key_store: domain::MerchantKeyStore, _merchant_id: common_utils::id_type::MerchantId, _payment_id: common_utils::id_type::PaymentId, - _request_headers: &header::HeaderMap, ) -> RouterResponse { todo!() } @@ -739,10 +718,7 @@ pub async fn get_payment_link_status( key_store: domain::MerchantKeyStore, merchant_id: common_utils::id_type::MerchantId, payment_id: common_utils::id_type::PaymentId, - request_headers: &header::HeaderMap, ) -> RouterResponse { - let locale = get_header_value_by_key(ACCEPT_LANGUAGE.into(), request_headers)? - .map(|val| val.to_string()); let db = &*state.store; let key_manager_state = &(&state).into(); @@ -858,19 +834,14 @@ pub async fn get_payment_link_status( consts::DEFAULT_UNIFIED_ERROR_MESSAGE.to_owned(), ) }; - let unified_translated_message = locale - .as_ref() - .async_and_then(|locale_str| async { - helpers::get_unified_translation( - &state, - unified_code.to_owned(), - unified_message.to_owned(), - locale_str.to_owned(), - ) - .await - }) - .await - .or(Some(unified_message)); + let unified_translated_message = helpers::get_unified_translation( + &state, + unified_code.to_owned(), + unified_message.to_owned(), + state.locale.clone(), + ) + .await + .or(Some(unified_message)); let payment_details = api_models::payments::PaymentLinkStatusDetails { amount, @@ -885,7 +856,7 @@ pub async fn get_payment_link_status( redirect: true, theme: payment_link_config.theme.clone(), return_url, - locale, + locale: Some(state.locale.clone()), transaction_details: payment_link_config.transaction_details, unified_code: Some(unified_code), unified_message: unified_translated_message, diff --git a/crates/router/src/core/payout_link.rs b/crates/router/src/core/payout_link.rs index 22354b4c00fc..e45b4fcead1d 100644 --- a/crates/router/src/core/payout_link.rs +++ b/crates/router/src/core/payout_link.rs @@ -46,7 +46,6 @@ pub async fn initiate_payout_link( key_store: domain::MerchantKeyStore, req: payouts::PayoutLinkInitiateRequest, request_headers: &header::HeaderMap, - locale: String, ) -> RouterResponse { let db: &dyn StorageInterface = &*state.store; let merchant_id = merchant_account.get_id(); @@ -128,7 +127,7 @@ pub async fn initiate_payout_link( GenericLinks { allowed_domains, data: GenericLinksData::ExpiredLink(expired_link_data), - locale, + locale: state.locale, }, ))) } @@ -245,7 +244,7 @@ pub async fn initiate_payout_link( enabled_payment_methods_with_required_fields, amount, currency: payout.destination_currency, - locale: locale.clone(), + locale: state.locale.clone(), form_layout: link_data.form_layout, test_mode: link_data.test_mode.unwrap_or(false), }; @@ -270,7 +269,7 @@ pub async fn initiate_payout_link( GenericLinks { allowed_domains, data: GenericLinksData::PayoutLink(generic_form_data), - locale, + locale: state.locale.clone(), }, ))) } @@ -282,7 +281,7 @@ pub async fn initiate_payout_link( &state, payout_attempt.unified_code.as_ref(), payout_attempt.unified_message.as_ref(), - &locale, + &state.locale.clone(), ) .await?; let js_data = payouts::PayoutLinkStatusDetails { @@ -322,7 +321,7 @@ pub async fn initiate_payout_link( GenericLinks { allowed_domains, data: GenericLinksData::PayoutLinkStatus(generic_status_data), - locale, + locale: state.locale.clone(), }, ))) } diff --git a/crates/router/src/core/payouts.rs b/crates/router/src/core/payouts.rs index b2d6b2ace45c..3c8432795a37 100644 --- a/crates/router/src/core/payouts.rs +++ b/crates/router/src/core/payouts.rs @@ -317,7 +317,6 @@ pub async fn payouts_create_core( merchant_account: domain::MerchantAccount, key_store: domain::MerchantKeyStore, req: payouts::PayoutCreateRequest, - locale: &str, ) -> RouterResponse { // Validate create request let (payout_id, payout_method_data, profile_id, customer) = @@ -332,7 +331,7 @@ pub async fn payouts_create_core( &payout_id, &profile_id, payout_method_data.as_ref(), - locale, + &state.locale, customer.as_ref(), ) .await?; @@ -382,7 +381,6 @@ pub async fn payouts_confirm_core( merchant_account: domain::MerchantAccount, key_store: domain::MerchantKeyStore, req: payouts::PayoutCreateRequest, - locale: &str, ) -> RouterResponse { let mut payout_data = make_payout_data( &state, @@ -390,7 +388,7 @@ pub async fn payouts_confirm_core( None, &key_store, &payouts::PayoutRequest::PayoutCreateRequest(Box::new(req.to_owned())), - locale, + &state.locale, ) .await?; let payout_attempt = payout_data.payout_attempt.to_owned(); @@ -454,7 +452,6 @@ pub async fn payouts_update_core( merchant_account: domain::MerchantAccount, key_store: domain::MerchantKeyStore, req: payouts::PayoutCreateRequest, - locale: &str, ) -> RouterResponse { let payout_id = req.payout_id.clone().get_required_value("payout_id")?; let mut payout_data = make_payout_data( @@ -463,7 +460,7 @@ pub async fn payouts_update_core( None, &key_store, &payouts::PayoutRequest::PayoutCreateRequest(Box::new(req.to_owned())), - locale, + &state.locale, ) .await?; @@ -539,7 +536,6 @@ pub async fn payouts_retrieve_core( profile_id: Option, key_store: domain::MerchantKeyStore, req: payouts::PayoutRetrieveRequest, - locale: &str, ) -> RouterResponse { let mut payout_data = make_payout_data( &state, @@ -547,7 +543,7 @@ pub async fn payouts_retrieve_core( profile_id, &key_store, &payouts::PayoutRequest::PayoutRetrieveRequest(req.to_owned()), - locale, + &state.locale, ) .await?; let payout_attempt = payout_data.payout_attempt.to_owned(); @@ -584,7 +580,6 @@ pub async fn payouts_cancel_core( merchant_account: domain::MerchantAccount, key_store: domain::MerchantKeyStore, req: payouts::PayoutActionRequest, - locale: &str, ) -> RouterResponse { let mut payout_data = make_payout_data( &state, @@ -592,7 +587,7 @@ pub async fn payouts_cancel_core( None, &key_store, &payouts::PayoutRequest::PayoutActionRequest(req.to_owned()), - locale, + &state.locale, ) .await?; @@ -678,7 +673,6 @@ pub async fn payouts_fulfill_core( merchant_account: domain::MerchantAccount, key_store: domain::MerchantKeyStore, req: payouts::PayoutActionRequest, - locale: &str, ) -> RouterResponse { let mut payout_data = make_payout_data( &state, @@ -686,7 +680,7 @@ pub async fn payouts_fulfill_core( None, &key_store, &payouts::PayoutRequest::PayoutActionRequest(req.to_owned()), - locale, + &state.locale, ) .await?; @@ -773,7 +767,6 @@ pub async fn payouts_list_core( _profile_id_list: Option>, _key_store: domain::MerchantKeyStore, _constraints: payouts::PayoutListConstraints, - _locale: &str, ) -> RouterResponse { todo!() } @@ -789,7 +782,6 @@ pub async fn payouts_list_core( profile_id_list: Option>, key_store: domain::MerchantKeyStore, constraints: payouts::PayoutListConstraints, - _locale: &str, ) -> RouterResponse { validator::validate_payout_list_request(&constraints)?; let merchant_id = merchant_account.get_id(); @@ -910,7 +902,6 @@ pub async fn payouts_filtered_list_core( profile_id_list: Option>, key_store: domain::MerchantKeyStore, filters: payouts::PayoutListFilterConstraints, - _locale: &str, ) -> RouterResponse { let limit = &filters.limit; validator::validate_payout_list_request_for_joins(*limit)?; @@ -1014,7 +1005,6 @@ pub async fn payouts_list_available_filters_core( merchant_account: domain::MerchantAccount, profile_id_list: Option>, time_range: common_utils::types::TimeRange, - _locale: &str, ) -> RouterResponse { let db = state.store.as_ref(); let payouts = db diff --git a/crates/router/src/core/refunds.rs b/crates/router/src/core/refunds.rs index a3f6b1d22321..e78c9471e61e 100644 --- a/crates/router/src/core/refunds.rs +++ b/crates/router/src/core/refunds.rs @@ -512,7 +512,6 @@ pub async fn refund_retrieve_core( }) .transpose()?; - let locale = state.get_locale(); let unified_translated_message = if let (Some(unified_code), Some(unified_message)) = (refund.unified_code.clone(), refund.unified_message.clone()) { @@ -520,7 +519,7 @@ pub async fn refund_retrieve_core( &state, unified_code, unified_message.clone(), - locale.to_owned(), + state.locale.to_string(), ) .await .or(Some(unified_message)) @@ -957,7 +956,6 @@ pub async fn validate_and_create_refund( } } }; - let locale = state.get_locale(); let unified_translated_message = if let (Some(unified_code), Some(unified_message)) = (refund.unified_code.clone(), refund.unified_message.clone()) { @@ -965,7 +963,7 @@ pub async fn validate_and_create_refund( state, unified_code, unified_message.clone(), - locale.to_owned(), + state.locale.to_string(), ) .await .or(Some(unified_message)) diff --git a/crates/router/src/db/events.rs b/crates/router/src/db/events.rs index 6bb7de1b7d99..33fcece85a01 100644 --- a/crates/router/src/db/events.rs +++ b/crates/router/src/db/events.rs @@ -734,6 +734,7 @@ mod tests { let state = &Arc::new(app_state) .get_session_state( &common_utils::id_type::TenantId::try_from_string("public".to_string()).unwrap(), + None, || {}, ) .unwrap(); diff --git a/crates/router/src/db/merchant_connector_account.rs b/crates/router/src/db/merchant_connector_account.rs index 0abbccd2cb35..fc0fa5aca75f 100644 --- a/crates/router/src/db/merchant_connector_account.rs +++ b/crates/router/src/db/merchant_connector_account.rs @@ -1561,6 +1561,7 @@ mod merchant_connector_account_cache_tests { let state = &Arc::new(app_state) .get_session_state( &common_utils::id_type::TenantId::try_from_string("public".to_string()).unwrap(), + None, || {}, ) .unwrap(); @@ -1746,6 +1747,7 @@ mod merchant_connector_account_cache_tests { let state = &Arc::new(app_state) .get_session_state( &common_utils::id_type::TenantId::try_from_string("public".to_string()).unwrap(), + None, || {}, ) .unwrap(); diff --git a/crates/router/src/db/merchant_key_store.rs b/crates/router/src/db/merchant_key_store.rs index 9f12ec8e8fd8..aaeba6085a07 100644 --- a/crates/router/src/db/merchant_key_store.rs +++ b/crates/router/src/db/merchant_key_store.rs @@ -350,6 +350,7 @@ mod tests { let state = &Arc::new(app_state) .get_session_state( &common_utils::id_type::TenantId::try_from_string("public".to_string()).unwrap(), + None, || {}, ) .unwrap(); diff --git a/crates/router/src/routes/app.rs b/crates/router/src/routes/app.rs index 528a13f08160..f8b5ef445678 100644 --- a/crates/router/src/routes/app.rs +++ b/crates/router/src/routes/app.rs @@ -131,14 +131,6 @@ impl SessionState { request_id: self.request_id.map(|req_id| (*req_id).to_string()), } } - - pub fn get_locale(&self) -> &String { - &self.locale - } - - pub fn set_locale(&mut self, locale: String) { - self.locale = locale - } } pub trait SessionStateInfo { @@ -467,6 +459,7 @@ impl AppState { pub fn get_session_state( self: Arc, tenant: &id_type::TenantId, + locale: Option, err: F, ) -> Result where @@ -493,7 +486,7 @@ impl AppState { opensearch_client: Arc::clone(&self.opensearch_client), grpc_client: Arc::clone(&self.grpc_client), theme_storage_client: self.theme_storage_client.clone(), - locale: common_utils::consts::DEFAULT_LOCALE.to_string(), + locale: locale.unwrap_or(common_utils::consts::DEFAULT_LOCALE.to_string()), }) } } diff --git a/crates/router/src/routes/payment_link.rs b/crates/router/src/routes/payment_link.rs index 71f10fe73e91..361367c7d277 100644 --- a/crates/router/src/routes/payment_link.rs +++ b/crates/router/src/routes/payment_link.rs @@ -65,7 +65,6 @@ pub async fn initiate_payment_link( payment_id, merchant_id: merchant_id.clone(), }; - let headers = req.headers(); Box::pin(api::server_wrap( flow, state, @@ -78,7 +77,6 @@ pub async fn initiate_payment_link( auth.key_store, payload.merchant_id.clone(), payload.payment_id.clone(), - headers, ) }, &crate::services::authentication::MerchantIdAuth(merchant_id), @@ -183,7 +181,6 @@ pub async fn payment_link_status( payment_id, merchant_id: merchant_id.clone(), }; - let headers = req.headers(); Box::pin(api::server_wrap( flow, state, @@ -196,7 +193,6 @@ pub async fn payment_link_status( auth.key_store, payload.merchant_id.clone(), payload.payment_id.clone(), - headers, ) }, &crate::services::authentication::MerchantIdAuth(merchant_id), diff --git a/crates/router/src/routes/payout_link.rs b/crates/router/src/routes/payout_link.rs index 25528b21ed85..0234b4fca828 100644 --- a/crates/router/src/routes/payout_link.rs +++ b/crates/router/src/routes/payout_link.rs @@ -1,14 +1,12 @@ use actix_web::{web, Responder}; use api_models::payouts::PayoutLinkInitiateRequest; -use common_utils::consts::DEFAULT_LOCALE; use router_env::Flow; use crate::{ core::{api_locking, payout_link::*}, - headers::ACCEPT_LANGUAGE, services::{ api, - authentication::{self as auth, get_header_value_by_key}, + authentication::{self as auth}, }, AppState, }; @@ -25,25 +23,13 @@ pub async fn render_payout_link( payout_id, }; let headers = req.headers(); - let locale = get_header_value_by_key(ACCEPT_LANGUAGE.into(), headers) - .ok() - .flatten() - .map(|val| val.to_string()) - .unwrap_or(DEFAULT_LOCALE.to_string()); Box::pin(api::server_wrap( flow, state, &req, payload.clone(), |state, auth, req, _| { - initiate_payout_link( - state, - auth.merchant_account, - auth.key_store, - req, - headers, - locale.clone(), - ) + initiate_payout_link(state, auth.merchant_account, auth.key_store, req, headers) }, &auth::MerchantIdAuth(merchant_id), api_locking::LockAction::NotApplicable, diff --git a/crates/router/src/routes/payouts.rs b/crates/router/src/routes/payouts.rs index 4d5ba26b842e..4044630b4da4 100644 --- a/crates/router/src/routes/payouts.rs +++ b/crates/router/src/routes/payouts.rs @@ -13,7 +13,6 @@ use crate::{ authorization::permissions::Permission, }, types::api::payouts as payout_types, - utils, }; /// Payouts - Create @@ -24,7 +23,6 @@ pub async fn payouts_create( json_payload: web::Json, ) -> HttpResponse { let flow = Flow::PayoutsCreate; - let locale = utils::get_locale_from_header(req.headers()); Box::pin(api::server_wrap( flow, @@ -32,7 +30,7 @@ pub async fn payouts_create( &req, json_payload.into_inner(), |state, auth: auth::AuthenticationData, req, _| { - payouts_create_core(state, auth.merchant_account, auth.key_store, req, &locale) + payouts_create_core(state, auth.merchant_account, auth.key_store, req) }, &auth::HeaderAuth(auth::ApiKeyAuth), api_locking::LockAction::NotApplicable, @@ -55,7 +53,6 @@ pub async fn payouts_retrieve( merchant_id: query_params.merchant_id.to_owned(), }; let flow = Flow::PayoutsRetrieve; - let locale = utils::get_locale_from_header(req.headers()); Box::pin(api::server_wrap( flow, @@ -69,7 +66,6 @@ pub async fn payouts_retrieve( auth.profile_id, auth.key_store, req, - &locale, ) }, auth::auth_type( @@ -92,7 +88,6 @@ pub async fn payouts_update( json_payload: web::Json, ) -> HttpResponse { let flow = Flow::PayoutsUpdate; - let locale = utils::get_locale_from_header(req.headers()); let payout_id = path.into_inner(); let mut payout_update_payload = json_payload.into_inner(); payout_update_payload.payout_id = Some(payout_id); @@ -102,7 +97,7 @@ pub async fn payouts_update( &req, payout_update_payload, |state, auth: auth::AuthenticationData, req, _| { - payouts_update_core(state, auth.merchant_account, auth.key_store, req, &locale) + payouts_update_core(state, auth.merchant_account, auth.key_store, req) }, &auth::HeaderAuth(auth::ApiKeyAuth), api_locking::LockAction::NotApplicable, @@ -128,7 +123,6 @@ pub async fn payouts_confirm( Ok(auth) => auth, Err(e) => return api::log_and_return_error_response(e), }; - let locale = utils::get_locale_from_header(req.headers()); Box::pin(api::server_wrap( flow, @@ -136,7 +130,7 @@ pub async fn payouts_confirm( &req, payload, |state, auth, req, _| { - payouts_confirm_core(state, auth.merchant_account, auth.key_store, req, &locale) + payouts_confirm_core(state, auth.merchant_account, auth.key_store, req) }, &*auth_type, api_locking::LockAction::NotApplicable, @@ -155,7 +149,6 @@ pub async fn payouts_cancel( let flow = Flow::PayoutsCancel; let mut payload = json_payload.into_inner(); payload.payout_id = path.into_inner(); - let locale = utils::get_locale_from_header(req.headers()); Box::pin(api::server_wrap( flow, @@ -163,7 +156,7 @@ pub async fn payouts_cancel( &req, payload, |state, auth: auth::AuthenticationData, req, _| { - payouts_cancel_core(state, auth.merchant_account, auth.key_store, req, &locale) + payouts_cancel_core(state, auth.merchant_account, auth.key_store, req) }, &auth::HeaderAuth(auth::ApiKeyAuth), api_locking::LockAction::NotApplicable, @@ -181,7 +174,6 @@ pub async fn payouts_fulfill( let flow = Flow::PayoutsFulfill; let mut payload = json_payload.into_inner(); payload.payout_id = path.into_inner(); - let locale = utils::get_locale_from_header(req.headers()); Box::pin(api::server_wrap( flow, @@ -189,7 +181,7 @@ pub async fn payouts_fulfill( &req, payload, |state, auth: auth::AuthenticationData, req, _| { - payouts_fulfill_core(state, auth.merchant_account, auth.key_store, req, &locale) + payouts_fulfill_core(state, auth.merchant_account, auth.key_store, req) }, &auth::HeaderAuth(auth::ApiKeyAuth), api_locking::LockAction::NotApplicable, @@ -207,7 +199,6 @@ pub async fn payouts_list( ) -> HttpResponse { let flow = Flow::PayoutsList; let payload = json_payload.into_inner(); - let locale = utils::get_locale_from_header(req.headers()); Box::pin(api::server_wrap( flow, @@ -215,14 +206,7 @@ pub async fn payouts_list( &req, payload, |state, auth: auth::AuthenticationData, req, _| { - payouts_list_core( - state, - auth.merchant_account, - None, - auth.key_store, - req, - &locale, - ) + payouts_list_core(state, auth.merchant_account, None, auth.key_store, req) }, auth::auth_type( &auth::HeaderAuth(auth::ApiKeyAuth), @@ -246,7 +230,6 @@ pub async fn payouts_list_profile( ) -> HttpResponse { let flow = Flow::PayoutsList; let payload = json_payload.into_inner(); - let locale = utils::get_locale_from_header(req.headers()); Box::pin(api::server_wrap( flow, @@ -260,7 +243,6 @@ pub async fn payouts_list_profile( auth.profile_id.map(|profile_id| vec![profile_id]), auth.key_store, req, - &locale, ) }, auth::auth_type( @@ -285,7 +267,6 @@ pub async fn payouts_list_by_filter( ) -> HttpResponse { let flow = Flow::PayoutsList; let payload = json_payload.into_inner(); - let locale = utils::get_locale_from_header(req.headers()); Box::pin(api::server_wrap( flow, @@ -293,14 +274,7 @@ pub async fn payouts_list_by_filter( &req, payload, |state, auth: auth::AuthenticationData, req, _| { - payouts_filtered_list_core( - state, - auth.merchant_account, - None, - auth.key_store, - req, - &locale, - ) + payouts_filtered_list_core(state, auth.merchant_account, None, auth.key_store, req) }, auth::auth_type( &auth::HeaderAuth(auth::ApiKeyAuth), @@ -324,7 +298,6 @@ pub async fn payouts_list_by_filter_profile( ) -> HttpResponse { let flow = Flow::PayoutsList; let payload = json_payload.into_inner(); - let locale = utils::get_locale_from_header(req.headers()); Box::pin(api::server_wrap( flow, @@ -338,7 +311,6 @@ pub async fn payouts_list_by_filter_profile( auth.profile_id.map(|profile_id| vec![profile_id]), auth.key_store, req, - &locale, ) }, auth::auth_type( @@ -363,7 +335,6 @@ pub async fn payouts_list_available_filters_for_merchant( ) -> HttpResponse { let flow = Flow::PayoutsFilter; let payload = json_payload.into_inner(); - let locale = utils::get_locale_from_header(req.headers()); Box::pin(api::server_wrap( flow, @@ -371,7 +342,7 @@ pub async fn payouts_list_available_filters_for_merchant( &req, payload, |state, auth: auth::AuthenticationData, req, _| { - payouts_list_available_filters_core(state, auth.merchant_account, None, req, &locale) + payouts_list_available_filters_core(state, auth.merchant_account, None, req) }, auth::auth_type( &auth::HeaderAuth(auth::ApiKeyAuth), @@ -395,7 +366,6 @@ pub async fn payouts_list_available_filters_for_profile( ) -> HttpResponse { let flow = Flow::PayoutsFilter; let payload = json_payload.into_inner(); - let locale = utils::get_locale_from_header(req.headers()); Box::pin(api::server_wrap( flow, @@ -408,7 +378,6 @@ pub async fn payouts_list_available_filters_for_profile( auth.merchant_account, auth.profile_id.map(|profile_id| vec![profile_id]), req, - &locale, ) }, auth::auth_type( diff --git a/crates/router/src/services/api.rs b/crates/router/src/services/api.rs index 7af95f539eae..f90528353cfb 100644 --- a/crates/router/src/services/api.rs +++ b/crates/router/src/services/api.rs @@ -760,15 +760,15 @@ where )? }; - let mut session_state = Arc::new(app_state.clone()).get_session_state(&tenant_id, || { - errors::ApiErrorResponse::InvalidTenant { - tenant_id: tenant_id.get_string_repr().to_string(), - } - .switch() - })?; - session_state.add_request_id(request_id); let locale = utils::get_locale_from_header(&incoming_request_header.clone()); - session_state.set_locale(locale); + let mut session_state = + Arc::new(app_state.clone()).get_session_state(&tenant_id, Some(locale), || { + errors::ApiErrorResponse::InvalidTenant { + tenant_id: tenant_id.get_string_repr().to_string(), + } + .switch() + })?; + session_state.add_request_id(request_id); let mut request_state = session_state.get_req_state(); request_state.event_context.record_info(request_id); diff --git a/crates/router/tests/cache.rs b/crates/router/tests/cache.rs index 55b92b4aace5..a1f85534b6bc 100644 --- a/crates/router/tests/cache.rs +++ b/crates/router/tests/cache.rs @@ -20,6 +20,7 @@ async fn invalidate_existing_cache_success() { let state = Arc::new(app_state) .get_session_state( &common_utils::id_type::TenantId::try_from_string("public".to_string()).unwrap(), + None, || {}, ) .unwrap(); diff --git a/crates/router/tests/connectors/aci.rs b/crates/router/tests/connectors/aci.rs index e3fd2bc1ee9c..2fbd9a7ed249 100644 --- a/crates/router/tests/connectors/aci.rs +++ b/crates/router/tests/connectors/aci.rs @@ -222,6 +222,7 @@ async fn payments_create_success() { let state = Arc::new(app_state) .get_session_state( &id_type::TenantId::try_from_string("public".to_string()).unwrap(), + None, || {}, ) .unwrap(); @@ -272,6 +273,7 @@ async fn payments_create_failure() { let state = Arc::new(app_state) .get_session_state( &id_type::TenantId::try_from_string("public".to_string()).unwrap(), + None, || {}, ) .unwrap(); @@ -338,6 +340,7 @@ async fn refund_for_successful_payments() { let state = Arc::new(app_state) .get_session_state( &id_type::TenantId::try_from_string("public".to_string()).unwrap(), + None, || {}, ) .unwrap(); @@ -411,6 +414,7 @@ async fn refunds_create_failure() { let state = Arc::new(app_state) .get_session_state( &id_type::TenantId::try_from_string("public".to_string()).unwrap(), + None, || {}, ) .unwrap(); diff --git a/crates/router/tests/connectors/utils.rs b/crates/router/tests/connectors/utils.rs index 361cda63a9f9..1b25e884a3dc 100644 --- a/crates/router/tests/connectors/utils.rs +++ b/crates/router/tests/connectors/utils.rs @@ -604,6 +604,7 @@ pub trait ConnectorActions: Connector { let state = Arc::new(app_state) .get_session_state( &common_utils::id_type::TenantId::try_from_string("public".to_string()).unwrap(), + None, || {}, ) .unwrap(); @@ -647,6 +648,7 @@ pub trait ConnectorActions: Connector { let state = Arc::new(app_state) .get_session_state( &common_utils::id_type::TenantId::try_from_string("public".to_string()).unwrap(), + None, || {}, ) .unwrap(); @@ -691,6 +693,7 @@ pub trait ConnectorActions: Connector { let state = Arc::new(app_state) .get_session_state( &common_utils::id_type::TenantId::try_from_string("public".to_string()).unwrap(), + None, || {}, ) .unwrap(); @@ -734,6 +737,7 @@ pub trait ConnectorActions: Connector { let state = Arc::new(app_state) .get_session_state( &common_utils::id_type::TenantId::try_from_string("public".to_string()).unwrap(), + None, || {}, ) .unwrap(); @@ -828,6 +832,7 @@ pub trait ConnectorActions: Connector { let state = Arc::new(app_state) .get_session_state( &common_utils::id_type::TenantId::try_from_string("public".to_string()).unwrap(), + None, || {}, ) .unwrap(); @@ -868,6 +873,7 @@ async fn call_connector< let state = Arc::new(app_state) .get_session_state( &common_utils::id_type::TenantId::try_from_string("public".to_string()).unwrap(), + None, || {}, ) .unwrap(); diff --git a/crates/router/tests/payments.rs b/crates/router/tests/payments.rs index beaacb79fc01..e1fe40b42065 100644 --- a/crates/router/tests/payments.rs +++ b/crates/router/tests/payments.rs @@ -297,6 +297,7 @@ async fn payments_create_core() { let state = Arc::new(app_state) .get_session_state( &id_type::TenantId::try_from_string("public".to_string()).unwrap(), + None, || {}, ) .unwrap(); @@ -558,6 +559,7 @@ async fn payments_create_core_adyen_no_redirect() { let state = Arc::new(app_state) .get_session_state( &id_type::TenantId::try_from_string("public".to_string()).unwrap(), + None, || {}, ) .unwrap(); diff --git a/crates/router/tests/payments2.rs b/crates/router/tests/payments2.rs index 1d573d007ba6..49d2e12b819f 100644 --- a/crates/router/tests/payments2.rs +++ b/crates/router/tests/payments2.rs @@ -58,6 +58,7 @@ async fn payments_create_core() { let state = Arc::new(app_state) .get_session_state( &id_type::TenantId::try_from_string("public".to_string()).unwrap(), + None, || {}, ) .unwrap(); @@ -327,6 +328,7 @@ async fn payments_create_core_adyen_no_redirect() { let state = Arc::new(app_state) .get_session_state( &id_type::TenantId::try_from_string("public".to_string()).unwrap(), + None, || {}, ) .unwrap(); diff --git a/crates/router/tests/services.rs b/crates/router/tests/services.rs index c014370b24f4..36f969dac1cf 100644 --- a/crates/router/tests/services.rs +++ b/crates/router/tests/services.rs @@ -20,6 +20,7 @@ async fn get_redis_conn_failure() { let state = Arc::new(app_state) .get_session_state( &common_utils::id_type::TenantId::try_from_string("public".to_string()).unwrap(), + None, || {}, ) .unwrap(); @@ -51,6 +52,7 @@ async fn get_redis_conn_success() { let state = Arc::new(app_state) .get_session_state( &common_utils::id_type::TenantId::try_from_string("public".to_string()).unwrap(), + None, || {}, ) .unwrap();