Skip to content

Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation

feat(multitenancy): add support for multitenancy and handle the same in router, producer, consumer, drainer and analytics (#4630)

Jagan15d6c3e846a7
diff --git a/config/config.example.toml b/config/config.example.toml
index 5d40d0e55e..8aa0ca9e52 100644
--- a/config/config.example.toml
+++ b/config/config.example.toml
@@ -629,3 +629,9 @@ disputes = "hyperswitch-dispute-events"
[saved_payment_methods]
sdk_eligible_payment_methods = "card"
+
+[multitenancy]
+enabled = false
+
+[multitenancy.tenants]
+public = { name = "hyperswitch", base_url = "http://localhost:8080", schema = "public", redis_key_prefix = ""} # schema -> Postgres db schema, redis_key_prefix -> redis key distinguisher, base_url -> url of the tenant
\ No newline at end of file
diff --git a/config/deployments/env_specific.toml b/config/deployments/env_specific.toml
index 7215e1931a..a097e1b66d 100644
--- a/config/deployments/env_specific.toml
+++ b/config/deployments/env_specific.toml
@@ -230,7 +230,6 @@ recon_admin_api_key = "recon_test_admin" # recon_admin API key for recon authent
# Server configuration
[server]
-base_url = "https://server_base_url"
workers = 8
port = 8080
host = "127.0.0.1"
@@ -253,3 +252,9 @@ encryption_manager = "aws_kms" # Encryption manager client to be used
[encryption_management.aws_kms]
key_id = "kms_key_id" # The AWS key ID used by the KMS SDK for decrypting data.
region = "kms_region" # The AWS region used by the KMS SDK for decrypting data.
+
+[multitenancy]
+enabled = false
+
+[multitenancy.tenants]
+public = { name = "hyperswitch", base_url = "http://localhost:8080", schema = "public", redis_key_prefix = ""}
\ No newline at end of file
diff --git a/config/development.toml b/config/development.toml
index 496ce6477a..d12a667b63 100644
--- a/config/development.toml
+++ b/config/development.toml
@@ -628,3 +628,9 @@ disputes = "hyperswitch-dispute-events"
[saved_payment_methods]
sdk_eligible_payment_methods = "card"
+
+[multitenancy]
+enabled = false
+
+[multitenancy.tenants]
+public = { name = "hyperswitch", base_url = "http://localhost:8080", schema = "public", redis_key_prefix = ""}
\ No newline at end of file
diff --git a/config/docker_compose.toml b/config/docker_compose.toml
index b94b5c8afb..3f6c9523e9 100644
--- a/config/docker_compose.toml
+++ b/config/docker_compose.toml
@@ -492,3 +492,9 @@ disputes = "hyperswitch-dispute-events"
[saved_payment_methods]
sdk_eligible_payment_methods = "card"
+
+[multitenancy]
+enabled = false
+
+[multitenancy.tenants]
+public = { name = "hyperswitch", base_url = "http://localhost:8080", schema = "public", redis_key_prefix = ""}
\ No newline at end of file
diff --git a/crates/analytics/src/lib.rs b/crates/analytics/src/lib.rs
index 1deca1e075..f658f67909 100644
--- a/crates/analytics/src/lib.rs
+++ b/crates/analytics/src/lib.rs
@@ -601,20 +601,20 @@ impl AnalyticsProvider {
}
}
- pub async fn from_conf(config: &AnalyticsConfig) -> Self {
+ pub async fn from_conf(config: &AnalyticsConfig, tenant: &str) -> Self {
match config {
- AnalyticsConfig::Sqlx { sqlx } => Self::Sqlx(SqlxClient::from_conf(sqlx).await),
+ AnalyticsConfig::Sqlx { sqlx } => Self::Sqlx(SqlxClient::from_conf(sqlx, tenant).await),
AnalyticsConfig::Clickhouse { clickhouse } => Self::Clickhouse(ClickhouseClient {
config: Arc::new(clickhouse.clone()),
}),
AnalyticsConfig::CombinedCkh { sqlx, clickhouse } => Self::CombinedCkh(
- SqlxClient::from_conf(sqlx).await,
+ SqlxClient::from_conf(sqlx, tenant).await,
ClickhouseClient {
config: Arc::new(clickhouse.clone()),
},
),
AnalyticsConfig::CombinedSqlx { sqlx, clickhouse } => Self::CombinedSqlx(
- SqlxClient::from_conf(sqlx).await,
+ SqlxClient::from_conf(sqlx, tenant).await,
ClickhouseClient {
config: Arc::new(clickhouse.clone()),
},
diff --git a/crates/analytics/src/sqlx.rs b/crates/analytics/src/sqlx.rs
index d3cb24a00c..3a1b7f2d46 100644
--- a/crates/analytics/src/sqlx.rs
+++ b/crates/analytics/src/sqlx.rs
@@ -4,12 +4,14 @@ use api_models::{
analytics::refunds::RefundType,
enums::{DisputeStage, DisputeStatus},
};
-use common_utils::errors::{CustomResult, ParsingError};
+use common_utils::{
+ errors::{CustomResult, ParsingError},
+ DbConnectionParams,
+};
use diesel_models::enums::{
AttemptStatus, AuthenticationType, Currency, PaymentMethod, RefundStatus,
};
use error_stack::ResultExt;
-use masking::PeekInterface;
use sqlx::{
postgres::{PgArgumentBuffer, PgPoolOptions, PgRow, PgTypeInfo, PgValueRef},
Decode, Encode,
@@ -49,12 +51,8 @@ impl Default for SqlxClient {
}
impl SqlxClient {
- pub async fn from_conf(conf: &Database) -> Self {
- let password = &conf.password.peek();
- let database_url = format!(
- "postgres://{}:{}@{}:{}/{}",
- conf.username, password, conf.host, conf.port, conf.dbname
- );
+ pub async fn from_conf(conf: &Database, schema: &str) -> Self {
+ let database_url = conf.get_database_url(schema);
#[allow(clippy::expect_used)]
let pool = PgPoolOptions::new()
.max_connections(conf.pool_size)
diff --git a/crates/common_utils/src/consts.rs b/crates/common_utils/src/consts.rs
index 0ea826d15c..0fe5cd7d7c 100644
--- a/crates/common_utils/src/consts.rs
+++ b/crates/common_utils/src/consts.rs
@@ -84,6 +84,9 @@ pub const DEFAULT_TTL_FOR_EXTENDED_CARD_INFO: u16 = 15 * 60;
/// Max ttl for Extended card info in redis (in seconds)
pub const MAX_TTL_FOR_EXTENDED_CARD_INFO: u16 = 60 * 60 * 2;
+/// Default tenant to be used when multitenancy is disabled
+pub const DEFAULT_TENANT: &str = "public";
+
/// Max Length for MerchantReferenceId
pub const MAX_ALLOWED_MERCHANT_REFERENCE_ID_LENGTH: u8 = 64;
diff --git a/crates/common_utils/src/lib.rs b/crates/common_utils/src/lib.rs
index d77442ad40..4e515e3d6a 100644
--- a/crates/common_utils/src/lib.rs
+++ b/crates/common_utils/src/lib.rs
@@ -2,6 +2,8 @@
#![warn(missing_docs, missing_debug_implementations)]
#![doc = include_str!(concat!(env!("CARGO_MANIFEST_DIR" ), "/", "README.md"))]
+use masking::{PeekInterface, Secret};
+
use crate::{
consts::ID_LENGTH,
id_type::{CustomerId, MerchantReferenceId},
@@ -224,6 +226,27 @@ pub fn generate_time_ordered_id(prefix: &str) -> String {
format!("{prefix}_{}", uuid::Uuid::now_v7().as_simple())
}
+#[allow(missing_docs)]
+pub trait DbConnectionParams {
+ fn get_username(&self) -> &str;
+ fn get_password(&self) -> Secret<String>;
+ fn get_host(&self) -> &str;
+ fn get_port(&self) -> u16;
+ fn get_dbname(&self) -> &str;
+ fn get_database_url(&self, schema: &str) -> String {
+ format!(
+ "postgres://{}:{}@{}:{}/{}?application_name={}&options=-c search_path%3D{}",
+ self.get_username(),
+ self.get_password().peek(),
+ self.get_host(),
+ self.get_port(),
+ self.get_dbname(),
+ schema,
+ schema,
+ )
+ }
+}
+
#[cfg(test)]
mod nanoid_tests {
#![allow(clippy::unwrap_used)]
diff --git a/crates/drainer/src/connection.rs b/crates/drainer/src/connection.rs
index c539e9a734..ec3bc44973 100644
--- a/crates/drainer/src/connection.rs
+++ b/crates/drainer/src/connection.rs
@@ -1,6 +1,6 @@
use bb8::PooledConnection;
+use common_utils::DbConnectionParams;
use diesel::PgConnection;
-use masking::PeekInterface;
use crate::{settings::Database, Settings};
@@ -18,15 +18,12 @@ pub async fn redis_connection(conf: &Settings) -> redis_interface::RedisConnecti
///
/// Will panic if could not create a db pool
#[allow(clippy::expect_used)]
-pub async fn diesel_make_pg_pool(database: &Database, _test_transaction: bool) -> PgPool {
- let database_url = format!(
- "postgres://{}:{}@{}:{}/{}",
- database.username,
- database.password.peek(),
- database.host,
- database.port,
- database.dbname
- );
+pub async fn diesel_make_pg_pool(
+ database: &Database,
+ _test_transaction: bool,
+ schema: &str,
+) -> PgPool {
+ let database_url = database.get_database_url(schema);
let manager = async_bb8_diesel::ConnectionManager::<PgConnection>::new(database_url);
let pool = bb8::Pool::builder()
.max_size(database.pool_size)
diff --git a/crates/drainer/src/handler.rs b/crates/drainer/src/handler.rs
index 35ad467d5f..77aefb422a 100644
--- a/crates/drainer/src/handler.rs
+++ b/crates/drainer/src/handler.rs
@@ -1,4 +1,7 @@
-use std::sync::{atomic, Arc};
+use std::{
+ collections::HashMap,
+ sync::{atomic, Arc},
+};
use router_env::tracing::Instrument;
use tokio::{
@@ -31,12 +34,12 @@ pub struct HandlerInner {
loop_interval: Duration,
active_tasks: Arc<atomic::AtomicU64>,
conf: DrainerSettings,
- store: Arc<Store>,
+ stores: HashMap<String, Arc<Store>>,
running: Arc<atomic::AtomicBool>,
}
impl Handler {
- pub fn from_conf(conf: DrainerSettings, store: Arc<Store>) -> Self {
+ pub fn from_conf(conf: DrainerSettings, stores: HashMap<String, Arc<Store>>) -> Self {
let shutdown_interval = Duration::from_millis(conf.shutdown_interval.into());
let loop_interval = Duration::from_millis(conf.loop_interval.into());
@@ -49,7 +52,7 @@ impl Handler {
loop_interval,
active_tasks,
conf,
- store,
+ stores,
running,
};
@@ -68,21 +71,23 @@ impl Handler {
while self.running.load(atomic::Ordering::SeqCst) {
metrics::DRAINER_HEALTH.add(&metrics::CONTEXT, 1, &[]);
- if self.store.is_stream_available(stream_index).await {
- let _task_handle = tokio::spawn(
- drainer_handler(
- self.store.clone(),
- stream_index,
- self.conf.max_read_count,
- self.active_tasks.clone(),
- jobs_picked.clone(),
- )
- .in_current_span(),
- );
+ for store in self.stores.values() {
+ if store.is_stream_available(stream_index).await {
+ let _task_handle = tokio::spawn(
+ drainer_handler(
+ store.clone(),
+ stream_index,
+ self.conf.max_read_count,
+ self.active_tasks.clone(),
+ jobs_picked.clone(),
+ )
+ .in_current_span(),
+ );
+ }
}
stream_index = utils::increment_stream_index(
(stream_index, jobs_picked.clone()),
- self.store.config.drainer_num_partitions,
+ self.conf.num_partitions,
)
.await;
time::sleep(self.loop_interval).await;
@@ -116,18 +121,33 @@ impl Handler {
pub fn spawn_error_handlers(&self, tx: mpsc::Sender<()>) -> errors::DrainerResult<()> {
let (redis_error_tx, redis_error_rx) = oneshot::channel();
+ let redis_conn_clone = self
+ .stores
+ .values()
+ .next()
+ .map(|store| store.redis_conn.clone());
+ match redis_conn_clone {
+ None => {
+ logger::error!("No redis connection found");
+ Err(
+ errors::DrainerError::UnexpectedError("No redis connection found".to_string())
+ .into(),
+ )
+ }
+ Some(redis_conn_clone) => {
+ // Spawn a task to monitor if redis is down or not
+ let _task_handle = tokio::spawn(
+ async move { redis_conn_clone.on_error(redis_error_tx).await }
+ .in_current_span(),
+ );
- let redis_conn_clone = self.store.redis_conn.clone();
-
- // Spawn a task to monitor if redis is down or not
- let _task_handle = tokio::spawn(
- async move { redis_conn_clone.on_error(redis_error_tx).await }.in_current_span(),
- );
-
- //Spawns a task to send shutdown signal if redis goes down
- let _task_handle = tokio::spawn(redis_error_receiver(redis_error_rx, tx).in_current_span());
+ //Spawns a task to send shutdown signal if redis goes down
+ let _task_handle =
+ tokio::spawn(redis_error_receiver(redis_error_rx, tx).in_current_span());
- Ok(())
+ Ok(())
+ }
+ }
}
}
@@ -208,7 +228,10 @@ async fn drainer(
};
// parse_stream_entries returns error if no entries is found, handle it
- let entries = utils::parse_stream_entries(&stream_read, stream_name)?;
+ let entries = utils::parse_stream_entries(
+ &stream_read,
+ store.redis_conn.add_prefix(stream_name).as_str(),
+ )?;
let read_count = entries.len();
metrics::JOBS_PICKED_PER_STREAM.add(
diff --git a/crates/drainer/src/health_check.rs b/crates/drainer/src/health_check.rs
index 443cb5b6f3..1051410899 100644
--- a/crates/drainer/src/health_check.rs
+++ b/crates/drainer/src/health_check.rs
@@ -1,4 +1,4 @@
-use std::sync::Arc;
+use std::{collections::HashMap, sync::Arc};
use actix_web::{web, Scope};
use async_bb8_diesel::{AsyncConnection, AsyncRunQueryDsl};
@@ -8,9 +8,9 @@ use error_stack::ResultExt;
use router_env::{instrument, logger, tracing};
use crate::{
- connection::{pg_connection, redis_connection},
+ connection::pg_connection,
errors::HealthCheckError,
- services::{self, Store},
+ services::{self, log_and_return_error_response, Store},
Settings,
};
@@ -20,10 +20,10 @@ pub const TEST_STREAM_DATA: &[(&str, &str)] = &[("data", "sample_data")];
pub struct Health;
impl Health {
- pub fn server(conf: Settings, store: Arc<Store>) -> Scope {
+ pub fn server(conf: Settings, stores: HashMap<String, Arc<Store>>) -> Scope {
web::scope("health")
.app_data(web::Data::new(conf))
- .app_data(web::Data::new(store))
+ .app_data(web::Data::new(stores))
.service(web::resource("").route(web::get().to(health)))
.service(web::resource("/ready").route(web::get().to(deep_health_check)))
}
@@ -38,25 +38,35 @@ pub async fn health() -> impl actix_web::Responder {
#[instrument(skip_all)]
pub async fn deep_health_check(
conf: web::Data<Settings>,
- store: web::Data<Arc<Store>>,
+ stores: web::Data<HashMap<String, Arc<Store>>>,
) -> impl actix_web::Responder {
- match deep_health_check_func(conf, store).await {
- Ok(response) => services::http_response_json(
- serde_json::to_string(&response)
+ let mut deep_health_res = HashMap::new();
+ for (tenant, store) in stores.iter() {
+ logger::info!("Tenant: {:?}", tenant);
+
+ let response = match deep_health_check_func(conf.clone(), store).await {
+ Ok(response) => serde_json::to_string(&response)
.map_err(|err| {
logger::error!(serialization_error=?err);
})
.unwrap_or_default(),
- ),
-
- Err(err) => services::log_and_return_error_response(err),
+ Err(err) => return log_and_return_error_response(err),
+ };
+ deep_health_res.insert(tenant.clone(), response);
}
+ services::http_response_json(
+ serde_json::to_string(&deep_health_res)
+ .map_err(|err| {
+ logger::error!(serialization_error=?err);
+ })
+ .unwrap_or_default(),
+ )
}
#[instrument(skip_all)]
pub async fn deep_health_check_func(
conf: web::Data<Settings>,
- store: web::Data<Arc<Store>>,
+ store: &Arc<Store>,
) -> Result<DrainerHealthCheckResponse, error_stack::Report<HealthCheckError>> {
logger::info!("Deep health check was called");
@@ -146,8 +156,11 @@ impl HealthCheckInterface for Store {
Ok(())
}
- async fn health_check_redis(&self, conf: &Settings) -> CustomResult<(), HealthCheckRedisError> {
- let redis_conn = redis_connection(conf).await;
+ async fn health_check_redis(
+ &self,
+ _conf: &Settings,
+ ) -> CustomResult<(), HealthCheckRedisError> {
+ let redis_conn = self.redis_conn.clone();
redis_conn
.serialize_and_set_key_with_expiry("test_key", "test_value", 30)
@@ -181,15 +194,14 @@ impl HealthCheckInterface for Store {
logger::debug!("Stream append succeeded");
- let output = self
- .redis_conn
+ let output = redis_conn
.stream_read_entries(TEST_STREAM_NAME, "0-0", Some(10))
.await
.change_context(HealthCheckRedisError::StreamReadFailed)?;
logger::debug!("Stream read succeeded");
let (_, id_to_trim) = output
- .get(TEST_STREAM_NAME)
+ .get(&redis_conn.add_prefix(TEST_STREAM_NAME))
.and_then(|entries| {
entries
.last()
diff --git a/crates/drainer/src/lib.rs b/crates/drainer/src/lib.rs
index cb2b55d202..5b67640663 100644
--- a/crates/drainer/src/lib.rs
+++ b/crates/drainer/src/lib.rs
@@ -10,7 +10,7 @@ pub mod settings;
mod stream;
mod types;
mod utils;
-use std::sync::Arc;
+use std::{collections::HashMap, sync::Arc};
mod secrets_transformers;
use actix_web::dev::Server;
@@ -30,8 +30,11 @@ use crate::{
connection::pg_connection, services::Store, settings::DrainerSettings, types::StreamData,
};
-pub async fn start_drainer(store: Arc<Store>, conf: DrainerSettings) -> errors::DrainerResult<()> {
- let drainer_handler = handler::Handler::from_conf(conf, store);
+pub async fn start_drainer(
+ stores: HashMap<String, Arc<Store>>,
+ conf: DrainerSettings,
+) -> errors::DrainerResult<()> {
+ let drainer_handler = handler::Handler::from_conf(conf, stores);
let (tx, rx) = mpsc::channel::<()>(1);
@@ -59,11 +62,11 @@ pub async fn start_drainer(store: Arc<Store>, conf: DrainerSettings) -> errors::
pub async fn start_web_server(
conf: Settings,
- store: Arc<Store>,
+ stores: HashMap<String, Arc<Store>>,
) -> Result<Server, errors::DrainerError> {
let server = conf.server.clone();
let web_server = actix_web::HttpServer::new(move || {
- actix_web::App::new().service(health_check::Health::server(conf.clone(), store.clone()))
+ actix_web::App::new().service(health_check::Health::server(conf.clone(), stores.clone()))
})
.bind((server.host.as_str(), server.port))?
.run();
diff --git a/crates/drainer/src/main.rs b/crates/drainer/src/main.rs
index 64e66619d7..f3f822129c 100644
--- a/crates/drainer/src/main.rs
+++ b/crates/drainer/src/main.rs
@@ -1,3 +1,5 @@
+use std::collections::HashMap;
+
use drainer::{
errors::DrainerResult, logger::logger, services, settings, start_drainer, start_web_server,
};
@@ -17,7 +19,11 @@ async fn main() -> DrainerResult<()> {
let state = settings::AppState::new(conf.clone()).await;
- let store = std::sync::Arc::new(services::Store::new(&state.conf, false).await);
+ let mut stores = HashMap::new();
+ for (tenant_name, tenant) in conf.multitenancy.get_tenants() {
+ let store = std::sync::Arc::new(services::Store::new(&state.conf, false, tenant).await);
+ stores.insert(tenant_name.clone(), store);
+ }
#[cfg(feature = "vergen")]
println!("Starting drainer (Version: {})", router_env::git_tag!());
@@ -29,9 +35,12 @@ async fn main() -> DrainerResult<()> {
);
#[allow(clippy::expect_used)]
- let web_server = Box::pin(start_web_server(state.conf.as_ref().clone(), store.clone()))
- .await
- .expect("Failed to create the server");
+ let web_server = Box::pin(start_web_server(
+ state.conf.as_ref().clone(),
+ stores.clone(),
+ ))
+ .await
+ .expect("Failed to create the server");
tokio::spawn(
async move {
@@ -44,7 +53,7 @@ async fn main() -> DrainerResult<()> {
logger::debug!(startup_config=?conf);
logger::info!("Drainer started [{:?}] [{:?}]", conf.drainer, conf.log);
- start_drainer(store.clone(), conf.drainer).await?;
+ start_drainer(stores.clone(), conf.drainer).await?;
Ok(())
}
diff --git a/crates/drainer/src/secrets_transformers.rs b/crates/drainer/src/secrets_transformers.rs
index 4ffb584a15..0582ccd798 100644
--- a/crates/drainer/src/secrets_transformers.rs
+++ b/crates/drainer/src/secrets_transformers.rs
@@ -45,5 +45,6 @@ pub async fn fetch_raw_secrets(
drainer: conf.drainer,
encryption_management: conf.encryption_management,
secrets_management: conf.secrets_management,
+ multitenancy: conf.multitenancy,
}
}
diff --git a/crates/drainer/src/services.rs b/crates/drainer/src/services.rs
index 9e0165548a..55ffe0c4e7 100644
--- a/crates/drainer/src/services.rs
+++ b/crates/drainer/src/services.rs
@@ -2,16 +2,18 @@ use std::sync::Arc;
use actix_web::{body, HttpResponse, ResponseError};
use error_stack::Report;
+use redis_interface::RedisConnectionPool;
use crate::{
connection::{diesel_make_pg_pool, PgPool},
logger,
+ settings::Tenant,
};
#[derive(Clone)]
pub struct Store {
pub master_pool: PgPool,
- pub redis_conn: Arc<redis_interface::RedisConnectionPool>,
+ pub redis_conn: Arc<RedisConnectionPool>,
pub config: StoreConfig,
pub request_id: Option<String>,
}
@@ -28,11 +30,19 @@ impl Store {
/// Panics if there is a failure while obtaining the HashiCorp client using the provided configuration.
/// This panic indicates a critical failure in setting up external services, and the application cannot proceed without a valid HashiCorp client.
///
- pub async fn new(config: &crate::Settings, test_transaction: bool) -> Self {
+ pub async fn new(config: &crate::Settings, test_transaction: bool, tenant: &Tenant) -> Self {
+ let redis_conn = crate::connection::redis_connection(config).await;
Self {
- master_pool: diesel_make_pg_pool(config.master_database.get_inner(), test_transaction)
- .await,
- redis_conn: Arc::new(crate::connection::redis_connection(config).await),
+ master_pool: diesel_make_pg_pool(
+ config.master_database.get_inner(),
+ test_transaction,
+ &tenant.schema,
+ )
+ .await,
+ redis_conn: Arc::new(RedisConnectionPool::clone(
+ &redis_conn,
+ &tenant.redis_key_prefix,
+ )),
config: StoreConfig {
drainer_stream_name: config.drainer.stream_name.clone(),
drainer_num_partitions: config.drainer.num_partitions,
diff --git a/crates/drainer/src/settings.rs b/crates/drainer/src/settings.rs
index e68ede9e8b..311cee0ced 100644
--- a/crates/drainer/src/settings.rs
+++ b/crates/drainer/src/settings.rs
@@ -1,6 +1,6 @@
-use std::{path::PathBuf, sync::Arc};
+use std::{collections::HashMap, path::PathBuf, sync::Arc};
-use common_utils::ext_traits::ConfigExt;
+use common_utils::{ext_traits::ConfigExt, DbConnectionParams};
use config::{Environment, File};
use external_services::managers::{
encryption_management::EncryptionManagementConfig, secrets_management::SecretsManagementConfig,
@@ -73,6 +73,7 @@ pub struct Settings<S: SecretState> {
pub drainer: DrainerSettings,
pub encryption_management: EncryptionManagementConfig,
pub secrets_management: SecretsManagementConfig,
+ pub multitenancy: Multitenancy,
}
#[derive(Debug, Deserialize, Clone)]
@@ -87,6 +88,24 @@ pub struct Database {
pub connection_timeout: u64,
}
+impl DbConnectionParams for Database {
+ fn get_username(&self) -> &str {
+ &self.username
+ }
+ fn get_password(&self) -> Secret<String> {
+ self.password.clone()
+ }
+ fn get_host(&self) -> &str {
+ &self.host
+ }
+ fn get_port(&self) -> u16 {
+ self.port
+ }
+ fn get_dbname(&self) -> &str {
+ &self.dbname
+ }
+}
+
#[derive(Debug, Clone, Deserialize)]
#[serde(default)]
pub struct DrainerSettings {
@@ -97,6 +116,35 @@ pub struct DrainerSettings {
pub loop_interval: u32, // in milliseconds
}
+#[derive(Debug, Deserialize, Clone, Default)]
+pub struct Multitenancy {
+ pub enabled: bool,
+ pub tenants: TenantConfig,
+}
+impl Multitenancy {
+ pub fn get_tenants(&self) -> &HashMap<String, Tenant> {
+ &self.tenants.0
+ }
+ pub fn get_tenant_names(&self) -> Vec<String> {
+ self.tenants.0.keys().cloned().collect()
+ }
+ pub fn get_tenant(&self, tenant_id: &str) -> Option<&Tenant> {
+ self.tenants.0.get(tenant_id)
+ }
+}
+
+#[derive(Debug, Deserialize, Clone, Default)]
+#[serde(transparent)]
+pub struct TenantConfig(pub HashMap<String, Tenant>);
+
+#[derive(Debug, Deserialize, Clone, Default)]
+pub struct Tenant {
+ pub name: String,
+ pub base_url: String,
+ pub schema: String,
+ pub redis_key_prefix: String,
+}
+
#[derive(Debug, Deserialize, Clone)]
#[serde(default)]
pub struct Server {
diff --git a/crates/hyperswitch_domain_models/src/errors/api_error_response.rs b/crates/hyperswitch_domain_models/src/errors/api_error_response.rs
index 26a6f1618f..053eb493ce 100644
--- a/crates/hyperswitch_domain_models/src/errors/api_error_response.rs
+++ b/crates/hyperswitch_domain_models/src/errors/api_error_response.rs
@@ -271,6 +271,10 @@ pub enum ApiErrorResponse {
InvalidCookie,
#[error(error_type = ErrorType::InvalidRequestError, code = "IR_27", message = "Extended card info does not exist")]
ExtendedCardInfoNotFound,
+ #[error(error_type = ErrorType::ProcessingError, code = "HE_06", message = "Missing tenant id")]
+ MissingTenantId,
+ #[error(error_type = ErrorType::ProcessingError, code = "HE_06", message = "Invalid tenant id: {tenant_id}")]
+ InvalidTenant { tenant_id: String },
}
#[derive(Clone)]
@@ -603,6 +607,12 @@ impl ErrorSwitch<api_models::errors::types::ApiErrorResponse> for ApiErrorRespon
Self::ExtendedCardInfoNotFound => {
AER::NotFound(ApiError::new("IR", 27, "Extended card info does not exist", None))
}
+ Self::MissingTenantId => {
+ AER::InternalServerError(ApiError::new("HE", 6, "Missing Tenant ID in the request".to_string(), None))
+ }
+ Self::InvalidTenant { tenant_id } => {
+ AER::InternalServerError(ApiError::new("HE", 6, format!("Invalid Tenant {tenant_id}"), None))
+ }
}
}
}
diff --git a/crates/redis_interface/src/commands.rs b/crates/redis_interface/src/commands.rs
index 504820822c..ccfeb3e5b1 100644
--- a/crates/redis_interface/src/commands.rs
+++ b/crates/redis_interface/src/commands.rs
@@ -31,6 +31,13 @@ use crate::{
};
impl super::RedisConnectionPool {
+ pub fn add_prefix(&self, key: &str) -> String {
+ if self.key_prefix.is_empty() {
+ key.to_string()
+ } else {
+ format!("{}:{}", self.key_prefix, key)
+ }
+ }
#[instrument(level = "DEBUG", skip(self))]
pub async fn set_key<V>(&self, key: &str, value: V) -> CustomResult<(), errors::RedisError>
where
@@ -39,7 +46,7 @@ impl super::RedisConnectionPool {
{
self.pool
.set(
- key,
+ self.add_prefix(key),
value,
Some(Expiration::EX(self.config.default_ttl.into())),
None,
@@ -144,7 +151,7 @@ impl super::RedisConnectionPool {
self.pool
.set(
- key,
+ self.add_prefix(key),
serialized.as_slice(),
Some(Expiration::EX(seconds)),
None,
@@ -160,7 +167,7 @@ impl super::RedisConnectionPool {
V: FromRedis + Unpin + Send + 'static,
{
self.pool
- .get(key)
+ .get(self.add_prefix(key))
.await
.change_context(errors::RedisError::GetFailed)
}
@@ -171,7 +178,7 @@ impl super::RedisConnectionPool {
V: Into<MultipleKeys> + Unpin + Send + 'static,
{
self.pool
- .exists(key)
+ .exists(self.add_prefix(key))
.await
.change_context(errors::RedisError::GetFailed)
}
@@ -197,7 +204,7 @@ impl super::RedisConnectionPool {
#[instrument(level = "DEBUG", skip(self))]
pub async fn delete_key(&self, key: &str) -> CustomResult<DelReply, errors::RedisError> {
self.pool
- .del(key)
+ .del(self.add_prefix(key))
.await
.change_context(errors::RedisError::DeleteFailed)
}
@@ -214,7 +221,13 @@ impl super::RedisConnectionPool {
V::Error: Into<fred::error::RedisError> + Send + Sync,
{
self.pool
- .set(key, value, Some(Expiration::EX(seconds)), None, false)
+ .set(
+ self.add_prefix(key),
+ value,
+ Some(Expiration::EX(seconds)),
+ None,
+ false,
+ )
.await
.change_context(errors::RedisError::SetExFailed)
}
@@ -232,7 +245,7 @@ impl super::RedisConnectionPool {
{
self.pool
.set(
- key,
+ self.add_prefix(key),
value,
Some(Expiration::EX(
seconds.unwrap_or(self.config.default_ttl.into()),
@@ -251,7 +264,7 @@ impl super::RedisConnectionPool {
seconds: i64,
) -> CustomResult<(), errors::RedisError> {
self.pool
- .expire(key, seconds)
+ .expire(self.add_prefix(key), seconds)
.await
.change_context(errors::RedisError::SetExpiryFailed)
}
@@ -263,7 +276,7 @@ impl super::RedisConnectionPool {
timestamp: i64,
) -> CustomResult<(), errors::RedisError> {
self.pool
- .expire_at(key, timestamp)
+ .expire_at(self.add_prefix(key), timestamp)
.await
.change_context(errors::RedisError::SetExpiryFailed)
}
@@ -281,7 +294,7 @@ impl super::RedisConnectionPool {
{
let output: Result<(), _> = self
.pool
- .hset(key, values)
+ .hset(self.add_prefix(key), values)
.await
.change_context(errors::RedisError::SetHashFailed);
// setting expiry for the key
@@ -306,7 +319,7 @@ impl super::RedisConnectionPool {
{
let output: Result<HsetnxReply, _> = self
.pool
- .hsetnx(key, field, value)
+ .hsetnx(self.add_prefix(key), field, value)
.await
.change_context(errors::RedisError::SetHashFieldFailed);
@@ -368,7 +381,7 @@ impl super::RedisConnectionPool {
Ok(self
.pool
.next()
- .hscan::<&str, &str>(key, pattern, count)
+ .hscan::<&str, &str>(&self.add_prefix(key), pattern, count)
.filter_map(|value| async move {
match value {
Ok(mut v) => {
@@ -419,7 +432,7 @@ impl super::RedisConnectionPool {
V: FromRedis + Unpin + Send + 'static,
{
self.pool
- .hget(key, field)
+ .hget(self.add_prefix(key), field)
.await
.change_context(errors::RedisError::GetHashFieldFailed)
}
@@ -456,7 +469,7 @@ impl super::RedisConnectionPool {
V::Error: Into<fred::error::RedisError> + Send,
{
self.pool
- .sadd(key, members)
+ .sadd(self.add_prefix(key), members)
.await
.change_context(errors::RedisError::SetAddMembersFailed)
}
@@ -473,7 +486,7 @@ impl super::RedisConnectionPool {
F::Error: Into<fred::error::RedisError> + Send + Sync,
{
self.pool
- .xadd(stream, false, None, entry_id, fields)
+ .xadd(self.add_prefix(stream), false, None, entry_id, fields)
.await
.change_context(errors::RedisError::StreamAppendFailed)
}
@@ -488,7 +501,7 @@ impl super::RedisConnectionPool {
Ids: Into<MultipleStrings> + Debug + Send + Sync,
{
self.pool
- .xdel(stream, ids)
+ .xdel(self.add_prefix(stream), ids)
.await
.change_context(errors::RedisError::StreamDeleteFailed)
}
@@ -504,7 +517,7 @@ impl super::RedisConnectionPool {
C::Error: Into<fred::error::RedisError> + Send + Sync,
{
self.pool
- .xtrim(stream, xcap)
+ .xtrim(self.add_prefix(stream), xcap)
.await
.change_context(errors::RedisError::StreamTrimFailed)
}
@@ -520,22 +533,34 @@ impl super::RedisConnectionPool {
Ids: Into<MultipleIDs> + Debug + Send + Sync,
{
self.pool
- .xack(stream, group, ids)
+ .xack(self.add_prefix(stream), group, ids)
.await
.change_context(errors::RedisError::StreamAcknowledgeFailed)
}
#[instrument(level = "DEBUG", skip(self))]
- pub async fn stream_get_length<K>(&self, stream: K) -> CustomResult<usize, errors::RedisError>
- where
- K: Into<RedisKey> + Debug + Send + Sync,
- {
+ pub async fn stream_get_length(&self, stream: &str) -> CustomResult<usize, errors::RedisError> {
self.pool
- .xlen(stream)
+ .xlen(self.add_prefix(stream))
.await
.change_context(errors::RedisError::GetLengthFailed)
}
+ pub fn get_keys_with_prefix<K>(&self, keys: K) -> MultipleKeys
+ where
+ K: Into<MultipleKeys> + Debug + Send + Sync,
+ {
+ let multiple_keys: MultipleKeys = keys.into();
+ let res = multiple_keys
+ .inner()
+ .iter()
+ .filter_map(|key| key.as_str())
+ .map(|k| self.add_prefix(k))
+ .map(RedisKey::from)
+ .collect::<Vec<_>>();
+ MultipleKeys::from(res)
+ }
+
#[instrument(level = "DEBUG", skip(self))]
pub async fn stream_read_entries<K, Ids>(
&self,
@@ -547,11 +572,12 @@ impl super::RedisConnectionPool {
K: Into<MultipleKeys> + Debug + Send + Sync,
Ids: Into<MultipleIDs> + Debug + Send + Sync,
{
+ let strms = self.get_keys_with_prefix(streams);
self.pool
.xread_map(
Some(read_count.unwrap_or(self.config.default_stream_read_count)),
None,
- streams,
+ strms,
ids,
)
.await
@@ -579,10 +605,22 @@ impl super::RedisConnectionPool {
match group {
Some((group_name, consumer_name)) => {
self.pool
- .xreadgroup_map(group_name, consumer_name, count, block, false, streams, ids)
+ .xreadgroup_map(
+ group_name,
+ consumer_name,
+ count,
+ block,
+ false,
+ self.get_keys_with_prefix(streams),
+ ids,
+ )
+ .await
+ }
+ None => {
+ self.pool
+ .xread_map(count, block, self.get_keys_with_prefix(streams), ids)
.await
}
- None => self.pool.xread_map(count, block, streams, ids).await,
}
.map_err(|err| match err.kind() {
RedisErrorKind::NotFound | RedisErrorKind::Parse => {
@@ -610,7 +648,7 @@ impl super::RedisConnectionPool {
}
self.pool
- .xgroup_create(stream, group, id, true)
+ .xgroup_create(self.add_prefix(stream), group, id, true)
.await
.change_context(errors::RedisError::ConsumerGroupCreateFailed)
}
@@ -622,7 +660,7 @@ impl super::RedisConnectionPool {
group: &str,
) -> CustomResult<usize, errors::RedisError> {
self.pool
- .xgroup_destroy(stream, group)
+ .xgroup_destroy(self.add_prefix(stream), group)
.await
.change_context(errors::RedisError::ConsumerGroupDestroyFailed)
}
@@ -636,7 +674,7 @@ impl super::RedisConnectionPool {
consumer: &str,
) -> CustomResult<usize, errors::RedisError> {
self.pool
- .xgroup_delconsumer(stream, group, consumer)
+ .xgroup_delconsumer(self.add_prefix(stream), group, consumer)
.await
.change_context(errors::RedisError::ConsumerGroupRemoveConsumerFailed)
}
@@ -649,7 +687,7 @@ impl super::RedisConnectionPool {
id: &RedisEntryId,
) -> CustomResult<String, errors::RedisError> {
self.pool
- .xgroup_setid(stream, group, id)
+ .xgroup_setid(self.add_prefix(stream), group, id)
.await
.change_context(errors::RedisError::ConsumerGroupSetIdFailed)
}
@@ -669,7 +707,7 @@ impl super::RedisConnectionPool {
{
self.pool
.xclaim(
- stream,
+ self.add_prefix(stream),
group,
consumer,
min_idle_time,
diff --git a/crates/redis_interface/src/lib.rs b/crates/redis_interface/src/lib.rs
index df74d72833..dc4fd3bbc9 100644
--- a/crates/redis_interface/src/lib.rs
+++ b/crates/redis_interface/src/lib.rs
@@ -30,10 +30,11 @@ use fred::{interfaces::ClientLike, prelude::EventInterface};
pub use self::types::*;
pub struct RedisConnectionPool {
- pub pool: fred::prelude::RedisPool,
- config: RedisConfig,
- pub subscriber: SubscriberClient,
- pub publisher: RedisClient,
+ pub pool: Arc<fred::prelude::RedisPool>,
+ pub key_prefix: String,
+ pub config: Arc<RedisConfig>,
+ pub subscriber: Arc<SubscriberClient>,
+ pub publisher: Arc<RedisClient>,
pub is_redis_available: Arc<atomic::AtomicBool>,
}
@@ -166,14 +167,24 @@ impl RedisConnectionPool {
let config = RedisConfig::from(conf);
Ok(Self {
- pool,
- config,
+ pool: Arc::new(pool),
+ config: Arc::new(config),
is_redis_available: Arc::new(atomic::AtomicBool::new(true)),
- subscriber,
- publisher,
+ subscriber: Arc::new(subscriber),
+ publisher: Arc::new(publisher),
+ key_prefix: String::default(),
})
}
-
+ pub fn clone(&self, key_prefix: &str) -> Self {
+ Self {
+ pool: Arc::clone(&self.pool),
+ key_prefix: key_prefix.to_string(),
+ config: Arc::clone(&self.config),
+ subscriber: Arc::clone(&self.subscriber),
+ publisher: Arc::clone(&self.publisher),
+ is_redis_available: Arc::clone(&self.is_redis_available),
+ }
+ }
pub async fn on_error(&self, tx: tokio::sync::oneshot::Sender<()>) {
use futures::StreamExt;
use tokio_stream::wrappers::BroadcastStream;
@@ -211,7 +222,7 @@ impl RedisConnectionPool {
}
}
-struct RedisConfig {
+pub struct RedisConfig {
default_ttl: u32,
default_stream_read_count: u64,
default_hash_ttl: u32,
diff --git a/crates/router/src/bin/scheduler.rs b/crates/router/src/bin/scheduler.rs
index 5341a1b09c..7e78a355e5 100644
--- a/crates/router/src/bin/scheduler.rs
+++ b/crates/router/src/bin/scheduler.rs
@@ -1,5 +1,5 @@
#![recursion_limit = "256"]
-use std::{str::FromStr, sync::Arc};
+use std::{collections::HashMap, str::FromStr, sync::Arc};
use actix_web::{dev::Server, web, Scope};
use api_models::health_check::SchedulerHealthCheckResponse;
@@ -22,7 +22,7 @@ use router_env::{
};
use scheduler::{
consumer::workflows::ProcessTrackerWorkflow, errors::ProcessTrackerError,
- workflows::ProcessTrackerWorkflows, SchedulerAppState,
+ workflows::ProcessTrackerWorkflows, SchedulerSessionState,
};
use storage_impl::errors::ApplicationError;
use tokio::sync::{mpsc, oneshot};
@@ -146,24 +146,54 @@ pub async fn deep_health_check(
state: web::Data<routes::AppState>,
service: web::Data<String>,
) -> impl actix_web::Responder {
- let report = deep_health_check_func(state, service).await;
- match report {
- Ok(response) => services::http_response_json(
- serde_json::to_string(&response)
- .map_err(|err| {
- logger::error!(serialization_error=?err);
- })
- .unwrap_or_default(),
- ),
- Err(err) => api::log_and_return_error_response(err),
+ let mut checks = HashMap::new();
+ let stores = state.stores.clone();
+ 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, || {
+ errors::ApiErrorResponse::MissingRequiredField {
+ field_name: "tenant_id",
+ }
+ .into()
+ });
+ let session_state = match session_state_res {
+ Ok(state) => state,
+ Err(err) => {
+ return api::log_and_return_error_response(err);
+ }
+ };
+ let report = deep_health_check_func(session_state, &service_name).await;
+ match report {
+ Ok(response) => {
+ checks.insert(
+ tenant,
+ serde_json::to_string(&response)
+ .map_err(|err| {
+ logger::error!(serialization_error=?err);
+ })
+ .unwrap_or_default(),
+ );
+ }
+ Err(err) => {
+ return api::log_and_return_error_response(err);
+ }
+ }
}
+ services::http_response_json(
+ serde_json::to_string(&checks)
+ .map_err(|err| {
+ logger::error!(serialization_error=?err);
+ })
+ .unwrap_or_default(),
+ )
}
#[instrument(skip_all)]
pub async fn deep_health_check_func(
- state: web::Data<routes::AppState>,
- service: web::Data<String>,
+ state: routes::SessionState,
+ service: &str,
) -> errors::RouterResult<SchedulerHealthCheckResponse> {
- logger::info!("{} deep health check was called", service.into_inner());
+ logger::info!("{} deep health check was called", service);
logger::debug!("Database health check begin");
@@ -215,10 +245,10 @@ pub async fn deep_health_check_func(
pub struct WorkflowRunner;
#[async_trait::async_trait]
-impl ProcessTrackerWorkflows<routes::AppState> for WorkflowRunner {
+impl ProcessTrackerWorkflows<routes::SessionState> for WorkflowRunner {
async fn trigger_workflow<'a>(
&'a self,
- state: &'a routes::AppState,
+ state: &'a routes::SessionState,
process: storage::ProcessTracker,
) -> CustomResult<(), ProcessTrackerError> {
let runner = process
@@ -233,7 +263,7 @@ impl ProcessTrackerWorkflows<routes::AppState> for WorkflowRunner {
.attach_printable("Failed to parse workflow runner name")?;
let get_operation = |runner: storage::ProcessTrackerRunner| -> CustomResult<
- Box<dyn ProcessTrackerWorkflow<routes::AppState>>,
+ Box<dyn ProcessTrackerWorkflow<routes::SessionState>>,
ProcessTrackerError,
> {
match runner {
@@ -286,7 +316,7 @@ impl ProcessTrackerWorkflows<routes::AppState> for WorkflowRunner {
let operation = get_operation(runner)?;
let app_state = &state.clone();
- let output = operation.execute_workflow(app_state, process.clone()).await;
+ let output = operation.execute_workflow(state, process.clone()).await;
match output {
Ok(_) => operation.success_handler(app_state, process).await,
Err(error) => match operation
@@ -327,6 +357,10 @@ async fn start_scheduler(
Arc::new(scheduler_settings),
channel,
WorkflowRunner {},
+ |state, tenant| {
+ Arc::new(state.clone())
+ .get_session_state(tenant, || ProcessTrackerError::TenantNotFound.into())
+ },
)
.await
}
diff --git a/crates/router/src/compatibility/stripe/customers.rs b/crates/router/src/compatibility/stripe/customers.rs
index 67c0f973b9..65abb012b9 100644
--- a/crates/router/src/compatibility/stripe/customers.rs
+++ b/crates/router/src/compatibility/stripe/customers.rs
@@ -155,7 +155,7 @@ pub async fn customer_delete(
state.into_inner(),
&req,
payload,
- |state, auth, req, _| {
+ |state, auth: auth::AuthenticationData, req, _| {
customers::delete_customer(state, auth.merchant_account, req, auth.key_store)
},
&auth::ApiKeyAuth,
diff --git a/crates/router/src/compatibility/stripe/errors.rs b/crates/router/src/compatibility/stripe/errors.rs
index 528381061c..17fcea9b82 100644
--- a/crates/router/src/compatibility/stripe/errors.rs
+++ b/crates/router/src/compatibility/stripe/errors.rs
@@ -264,6 +264,8 @@ pub enum StripeErrorCode {
PaymentMethodDeleteFailed,
#[error(error_type = StripeErrorType::InvalidRequestError, code = "", message = "Extended card info does not exist")]
ExtendedCardInfoNotFound,
+ #[error(error_type = StripeErrorType::InvalidRequestError, code = "IR_28", message = "Invalid tenant")]
+ InvalidTenant,
// [#216]: https://github.com/juspay/hyperswitch/issues/216
// Implement the remaining stripe error codes
@@ -646,6 +648,8 @@ impl From<errors::ApiErrorResponse> for StripeErrorCode {
Self::InvalidWalletToken { wallet_name }
}
errors::ApiErrorResponse::ExtendedCardInfoNotFound => Self::ExtendedCardInfoNotFound,
+ errors::ApiErrorResponse::InvalidTenant { tenant_id: _ }
+ | errors::ApiErrorResponse::MissingTenantId => Self::InvalidTenant,
}
}
}
@@ -725,7 +729,8 @@ impl actix_web::ResponseError for StripeErrorCode {
| Self::InternalServerError
| Self::MandateActive
| Self::CustomerRedacted
- | Self::WebhookProcessingError => StatusCode::INTERNAL_SERVER_ERROR,
+ | Self::WebhookProcessingError
+ | Self::InvalidTenant => StatusCode::INTERNAL_SERVER_ERROR,
Self::ReturnUrlUnavailable => StatusCode::SERVICE_UNAVAILABLE,
Self::ExternalConnectorError { status_code, .. } => {
StatusCode::from_u16(*status_code).unwrap_or(StatusCode::INTERNAL_SERVER_ERROR)
diff --git a/crates/router/src/compatibility/wrap.rs b/crates/router/src/compatibility/wrap.rs
index 96163727da..b6012c425a 100644
--- a/crates/router/src/compatibility/wrap.rs
+++ b/crates/router/src/compatibility/wrap.rs
@@ -10,7 +10,7 @@ use crate::{
events::api_logs::ApiEventMetric,
routes::{
app::{AppStateInfo, ReqState},
- metrics, AppState,
+ metrics, AppState, SessionState,
},
services::{self, api, authentication as auth, logger},
};
@@ -22,11 +22,11 @@ pub async fn compatibility_api_wrap<'a, 'b, U, T, Q, F, Fut, S, E, E2>(
request: &'a HttpRequest,
payload: T,
func: F,
- api_authentication: &dyn auth::AuthenticateAndFetch<U, AppState>,
+ api_authentication: &dyn auth::AuthenticateAndFetch<U, SessionState>,
lock_action: api_locking::LockAction,
) -> HttpResponse
where
- F: Fn(AppState, U, T, ReqState) -> Fut,
+ F: Fn(SessionState, U, T, ReqState) -> Fut,
Fut: Future<Output = CustomResult<api::ApplicationResponse<Q>, E2>>,
E2: ErrorSwitch<E> + std::error::Error + Send + Sync + 'static,
Q: Serialize + std::fmt::Debug + 'a + ApiEventMetric,
@@ -49,6 +49,7 @@ where
api::server_wrap_util(
&flow,
state.clone().into(),
+ request.headers(),
req_state,
request,
payload,
diff --git a/crates/router/src/configs/defaults.rs b/crates/router/src/configs/defaults.rs
index 77f424d833..c989e4c04c 100644
--- a/crates/router/src/configs/defaults.rs
+++ b/crates/router/src/configs/defaults.rs
@@ -11,7 +11,6 @@ impl Default for super::settings::Server {
workers: num_cpus::get_physical(),
host: "localhost".into(),
request_body_limit: 16 * 1024, // POST request body is limited to 16KiB
- base_url: "http://localhost:8080".into(),
shutdown_timeout: 30,
}
}
diff --git a/crates/router/src/configs/secrets_transformers.rs b/crates/router/src/configs/secrets_transformers.rs
index dc8b5dd6bd..2f90833905 100644
--- a/crates/router/src/configs/secrets_transformers.rs
+++ b/crates/router/src/configs/secrets_transformers.rs
@@ -367,5 +367,6 @@ pub(crate) async fn fetch_raw_secrets(
cors: conf.cors,
unmasked_headers: conf.unmasked_headers,
saved_payment_methods: conf.saved_payment_methods,
+ multitenancy: conf.multitenancy,
}
}
diff --git a/crates/router/src/configs/settings.rs b/crates/router/src/configs/settings.rs
index 8ac27cce31..c71ed4496b 100644
--- a/crates/router/src/configs/settings.rs
+++ b/crates/router/src/configs/settings.rs
@@ -120,9 +120,49 @@ pub struct Settings<S: SecretState> {
#[cfg(feature = "olap")]
pub connector_onboarding: SecretStateContainer<ConnectorOnboarding, S>,
pub unmasked_headers: UnmaskedHeaders,
+ pub multitenancy: Multitenancy,
pub saved_payment_methods: EligiblePaymentMethods,
}
+#[derive(Debug, Deserialize, Clone, Default)]
+pub struct Multitenancy {
+ pub tenants: TenantConfig,
+ pub enabled: bool,
+}
+
+impl Multitenancy {
+ pub fn get_tenants(&self) -> &HashMap<String, Tenant> {
+ &self.tenants.0
+ }
+ pub fn get_tenant_names(&self) -> Vec<String> {
+ self.tenants.0.keys().cloned().collect()
+ }
+ pub fn get_tenant(&self, tenant_id: &str) -> Option<&Tenant> {
+ self.tenants.0.get(tenant_id)
+ }
+}
+
+#[derive(Debug, Deserialize, Clone, Default)]
+#[serde(transparent)]
+pub struct TenantConfig(pub HashMap<String, Tenant>);
+
+#[derive(Debug, Deserialize, Clone, Default)]
+pub struct Tenant {
+ pub name: String,
+ pub base_url: String,
+ pub schema: String,
+ pub redis_key_prefix: String,
+}
+
+impl storage_impl::config::TenantConfig for Tenant {
+ fn get_schema(&self) -> &str {
+ self.schema.as_str()
+ }
+ fn get_redis_key_prefix(&self) -> &str {
+ self.redis_key_prefix.as_str()
+ }
+}
+
#[derive(Debug, Deserialize, Clone, Default)]
pub struct UnmaskedHeaders {
#[serde(deserialize_with = "deserialize_hashset")]
@@ -447,7 +487,6 @@ pub struct Server {
pub workers: usize,
pub host: String,
pub request_body_limit: usize,
- pub base_url: String,
pub shutdown_timeout: u64,
}
diff --git a/crates/router/src/connector/nuvei.rs b/crates/router/src/connector/nuvei.rs
index bc556336c3..132311f878 100644
--- a/crates/router/src/connector/nuvei.rs
+++ b/crates/router/src/connector/nuvei.rs
@@ -526,7 +526,7 @@ impl ConnectorIntegration<api::Authorize, types::PaymentsAuthorizeData, types::P
async fn execute_pretasks(
&self,
router_data: &mut types::PaymentsAuthorizeRouterData,
- app_state: &crate::routes::AppState,
+ app_state: &crate::routes::SessionState,
) -> CustomResult<(), errors::ConnectorError> {
let integ: Box<
&(dyn ConnectorIntegration<
diff --git a/crates/router/src/connector/shift4.rs b/crates/router/src/connector/shift4.rs
index 6c54c7019c..f314d621de 100644
--- a/crates/router/src/connector/shift4.rs
+++ b/crates/router/src/connector/shift4.rs
@@ -216,7 +216,7 @@ impl ConnectorIntegration<api::Authorize, types::PaymentsAuthorizeData, types::P
async fn execute_pretasks(
&self,
router_data: &mut types::PaymentsAuthorizeRouterData,
- app_state: &routes::AppState,
+ app_state: &routes::SessionState,
) -> CustomResult<(), errors::ConnectorError> {
if router_data.auth_type == enums::AuthenticationType::ThreeDs
&& router_data.payment_method == enums::PaymentMethod::Card
diff --git a/crates/router/src/connector/square.rs b/crates/router/src/connector/square.rs
index f9a81031b0..4e0812d161 100644
--- a/crates/router/src/connector/square.rs
+++ b/crates/router/src/connector/square.rs
@@ -196,7 +196,7 @@ impl
async fn execute_pretasks(
&self,
router_data: &mut types::TokenizationRouterData,
- app_state: &crate::routes::AppState,
+ app_state: &crate::routes::SessionState,
) -> CustomResult<(), errors::ConnectorError> {
let integ: Box<
&(dyn ConnectorIntegration<
diff --git a/crates/router/src/connector/wise.rs b/crates/router/src/connector/wise.rs
index 667e182b67..763adca1ee 100644
--- a/crates/router/src/connector/wise.rs
+++ b/crates/router/src/connector/wise.rs
@@ -506,7 +506,7 @@ impl services::ConnectorIntegration<api::PoCreate, types::PayoutsData, types::Pa
async fn execute_pretasks(
&self,
router_data: &mut types::PayoutsRouterData<api::PoCreate>,
- app_state: &routes::AppState,
+ app_state: &routes::SessionState,
) -> CustomResult<(), errors::ConnectorError> {
// Create a quote
let quote_router_data =
diff --git a/crates/router/src/core/admin.rs b/crates/router/src/core/admin.rs
index bac825a341..6b582c2c95 100644
--- a/crates/router/src/core/admin.rs
+++ b/crates/router/src/core/admin.rs
@@ -26,7 +26,7 @@ use crate::{
utils as core_utils,
},
db::StorageInterface,
- routes::{metrics, AppState},
+ routes::{metrics, SessionState},
services::{self, api as service_api},
types::{
self, api,
@@ -50,7 +50,7 @@ pub fn create_merchant_publishable_key() -> String {
}
pub async fn create_merchant_account(
- state: AppState,
+ state: SessionState,
req: api::MerchantAccountCreate,
) -> RouterResponse<api::MerchantAccountResponse> {
let db = state.store.as_ref();
@@ -287,7 +287,7 @@ pub async fn create_merchant_account(
#[cfg(feature = "olap")]
pub async fn list_merchant_account(
- state: AppState,
+ state: SessionState,
req: api_models::admin::MerchantAccountListRequest,
) -> RouterResponse<Vec<api::MerchantAccountResponse>> {
let merchant_accounts = state
@@ -311,7 +311,7 @@ pub async fn list_merchant_account(
}
pub async fn get_merchant_account(
- state: AppState,
+ state: SessionState,
req: api::MerchantId,
) -> RouterResponse<api::MerchantAccountResponse> {
let db = state.store.as_ref();
@@ -399,7 +399,7 @@ pub async fn create_business_profile_from_business_labels(
/// For backwards compatibility
/// If any of the fields of merchant account are updated, then update these fields in business profiles
pub async fn update_business_profile_cascade(
- state: AppState,
+ state: SessionState,
merchant_account_update: api::MerchantAccountUpdate,
merchant_id: String,
) -> RouterResult<()> {
@@ -463,7 +463,7 @@ pub async fn update_business_profile_cascade(
}
pub async fn merchant_account_update(
- state: AppState,
+ state: SessionState,
merchant_id: &String,
req: api::MerchantAccountUpdate,
) -> RouterResponse<api::MerchantAccountResponse> {
@@ -617,7 +617,7 @@ pub async fn merchant_account_update(
}
pub async fn merchant_account_delete(
- state: AppState,
+ state: SessionState,
merchant_id: String,
) -> RouterResponse<api::MerchantAccountDeleteResponse> {
let mut is_deleted = false;
@@ -733,7 +733,7 @@ fn validate_certificate_in_mca_metadata(
}
pub async fn create_payment_connector(
- state: AppState,
+ state: SessionState,
req: api::MerchantConnectorCreate,
merchant_id: &String,
) -> RouterResponse<api_models::admin::MerchantConnectorResponse> {
@@ -1084,7 +1084,7 @@ async fn validate_pm_auth(
}
pub async fn retrieve_payment_connector(
- state: AppState,
+ state: SessionState,
merchant_id: String,
merchant_connector_id: String,
) -> RouterResponse<api_models::admin::MerchantConnectorResponse> {
@@ -1117,7 +1117,7 @@ pub async fn retrieve_payment_connector(
}
pub async fn list_payment_connectors(
- state: AppState,
+ state: SessionState,
merchant_id: String,
) -> RouterResponse<Vec<api_models::admin::MerchantConnectorResponse>> {
let store = state.store.as_ref();
@@ -1154,7 +1154,7 @@ pub async fn list_payment_connectors(
}
pub async fn update_payment_connector(
- state: AppState,
+ state: SessionState,
merchant_id: &str,
merchant_connector_id: &str,
req: api_models::admin::MerchantConnectorUpdate,
@@ -1305,7 +1305,7 @@ pub async fn update_payment_connector(
}
pub async fn delete_payment_connector(
- state: AppState,
+ state: SessionState,
merchant_id: String,
merchant_connector_id: String,
) -> RouterResponse<api::MerchantConnectorDeleteResponse> {
@@ -1350,7 +1350,7 @@ pub async fn delete_payment_connector(
}
pub async fn kv_for_merchant(
- state: AppState,
+ state: SessionState,
merchant_id: String,
enable: bool,
) -> RouterResponse<api_models::admin::ToggleKVResponse> {
@@ -1417,7 +1417,7 @@ pub async fn kv_for_merchant(
}
pub async fn toggle_kv_for_all_merchants(
- state: AppState,
+ state: SessionState,
enable: bool,
) -> RouterResponse<api_models::admin::ToggleAllKVResponse> {
let db = state.store.as_ref();
@@ -1447,7 +1447,7 @@ pub async fn toggle_kv_for_all_merchants(
}
pub async fn check_merchant_account_kv_status(
- state: AppState,
+ state: SessionState,
merchant_id: String,
) -> RouterResponse<api_models::admin::ToggleKVResponse> {
let db = state.store.as_ref();
@@ -1519,7 +1519,7 @@ pub async fn create_and_insert_business_profile(
}
pub async fn create_business_profile(
- state: AppState,
+ state: SessionState,
request: api::BusinessProfileCreate,
merchant_id: &str,
) -> RouterResponse<api_models::admin::BusinessProfileResponse> {
@@ -1566,7 +1566,7 @@ pub async fn create_business_profile(
}
pub async fn list_business_profile(
- state: AppState,
+ state: SessionState,
merchant_id: String,
) -> RouterResponse<Vec<api_models::admin::BusinessProfileResponse>> {
let db = state.store.as_ref();
@@ -1586,7 +1586,7 @@ pub async fn list_business_profile(
}
pub async fn retrieve_business_profile(
- state: AppState,
+ state: SessionState,
profile_id: String,
) -> RouterResponse<api_models::admin::BusinessProfileResponse> {
let db = state.store.as_ref();
@@ -1604,7 +1604,7 @@ pub async fn retrieve_business_profile(
}
pub async fn delete_business_profile(
- state: AppState,
+ state: SessionState,
profile_id: String,
merchant_id: &str,
) -> RouterResponse<bool> {
@@ -1620,7 +1620,7 @@ pub async fn delete_business_profile(
}
pub async fn update_business_profile(
- state: AppState,
+ state: SessionState,
profile_id: &str,
merchant_id: &str,
request: api::BusinessProfileUpdate,
@@ -1738,7 +1738,7 @@ pub async fn update_business_profile(
}
pub async fn extended_card_info_toggle(
- state: AppState,
+ state: SessionState,
profile_id: &str,
ext_card_info_choice: admin_types::ExtendedCardInfoChoice,
) -> RouterResponse<admin_types::ExtendedCardInfoChoice> {
@@ -1771,7 +1771,7 @@ pub async fn extended_card_info_toggle(
}
pub async fn connector_agnostic_mit_toggle(
- state: AppState,
+ state: SessionState,
merchant_id: &str,
profile_id: &str,
connector_agnostic_mit_choice: admin_types::ConnectorAgnosticMitChoice,
@@ -2085,7 +2085,7 @@ pub(crate) fn validate_auth_and_metadata_type(
#[cfg(feature = "dummy_connector")]
pub async fn validate_dummy_connector_enabled(
- state: &AppState,
+ state: &SessionState,
connector_name: &api_enums::Connector,
) -> Result<(), errors::ApiErrorResponse> {
if !state.conf.dummy_connector.enabled
diff --git a/crates/router/src/core/api_keys.rs b/crates/router/src/core/api_keys.rs
index 7f2b343b96..8fe536731d 100644
--- a/crates/router/src/core/api_keys.rs
+++ b/crates/router/src/core/api_keys.rs
@@ -9,7 +9,7 @@ use crate::{
configs::settings,
consts,
core::errors::{self, RouterResponse, StorageErrorExt},
- routes::{metrics, AppState},
+ routes::{metrics, SessionState},
services::ApplicationResponse,
types::{api, storage, transformers::ForeignInto},
utils,
@@ -110,7 +110,7 @@ impl PlaintextApiKey {
#[instrument(skip_all)]
pub async fn create_api_key(
- state: AppState,
+ state: SessionState,
api_key: api::CreateApiKeyRequest,
merchant_id: String,
) -> RouterResponse<api::CreateApiKeyResponse> {
@@ -244,7 +244,7 @@ pub async fn add_api_key_expiry_task(
#[instrument(skip_all)]
pub async fn retrieve_api_key(
- state: AppState,
+ state: SessionState,
merchant_id: &str,
key_id: &str,
) -> RouterResponse<api::RetrieveApiKeyResponse> {
@@ -261,7 +261,7 @@ pub async fn retrieve_api_key(
#[instrument(skip_all)]
pub async fn update_api_key(
- state: AppState,
+ state: SessionState,
api_key: api::UpdateApiKeyRequest,
) -> RouterResponse<api::RetrieveApiKeyResponse> {
let merchant_id = api_key.merchant_id.clone();
@@ -395,7 +395,7 @@ pub async fn update_api_key_expiry_task(
#[instrument(skip_all)]
pub async fn revoke_api_key(
- state: AppState,
+ state: SessionState,
merchant_id: &str,
key_id: &str,
) -> RouterResponse<api::RevokeApiKeyResponse> {
@@ -463,7 +463,7 @@ pub async fn revoke_api_key_expiry_task(
#[instrument(skip_all)]
pub async fn list_api_keys(
- state: AppState,
+ state: SessionState,
merchant_id: String,
limit: Option<i64>,
offset: Option<i64>,
diff --git a/crates/router/src/core/api_locking.rs b/crates/router/src/core/api_locking.rs
index ec205f5242..8723c5fc14 100644
--- a/crates/router/src/core/api_locking.rs
+++ b/crates/router/src/core/api_locking.rs
@@ -6,7 +6,7 @@ use redis_interface as redis;
use router_env::{instrument, logger, tracing};
use super::errors::{self, RouterResult};
-use crate::routes::{app::AppStateInfo, lock_utils};
+use crate::routes::{app::SessionStateInfo, lock_utils};
pub const API_LOCK_PREFIX: &str = "API_LOCK";
@@ -50,7 +50,7 @@ impl LockAction {
#[instrument(skip_all)]
pub async fn perform_locking_action<A>(self, state: &A, merchant_id: String) -> RouterResult<()>
where
- A: AppStateInfo,
+ A: SessionStateInfo,
{
match self {
Self::Hold { input } => {
@@ -111,7 +111,7 @@ impl LockAction {
#[instrument(skip_all)]
pub async fn free_lock_action<A>(self, state: &A, merchant_id: String) -> RouterResult<()>
where
- A: AppStateInfo,
+ A: SessionStateInfo,
{
match self {
Self::Hold { input } => {
diff --git a/crates/router/src/core/authentication.rs b/crates/router/src/core/authentication.rs
index 7828473df6..ec799365f7 100644
--- a/crates/router/src/core/authentication.rs
+++ b/crates/router/src/core/authentication.rs
@@ -12,14 +12,14 @@ use masking::ExposeInterface;
use super::errors::StorageErrorExt;
use crate::{
core::{errors::ApiErrorResponse, payments as payments_core},
- routes::AppState,
+ routes::SessionState,
types::{self as core_types, api, domain, storage},
utils::check_if_pull_mechanism_for_external_3ds_enabled_from_connector_metadata,
};
#[allow(clippy::too_many_arguments)]
pub async fn perform_authentication(
- state: &AppState,
+ state: &SessionState,
merchant_id: String,
authentication_connector: String,
payment_method_data: payments::PaymentMethodData,
@@ -78,7 +78,7 @@ pub async fn perform_authentication(
}
pub async fn perform_post_authentication(
- state: &AppState,
+ state: &SessionState,
key_store: &domain::MerchantKeyStore,
business_profile: storage::BusinessProfile,
authentication_id: String,
@@ -117,7 +117,7 @@ pub async fn perform_post_authentication(
}
pub async fn perform_pre_authentication(
- state: &AppState,
+ state: &SessionState,
key_store: &domain::MerchantKeyStore,
card_number: cards::CardNumber,
token: String,
diff --git a/crates/router/src/core/authentication/utils.rs b/crates/router/src/core/authentication/utils.rs
index 6128352f2b..ec44f299c7 100644
--- a/crates/router/src/core/authentication/utils.rs
+++ b/crates/router/src/core/authentication/utils.rs
@@ -8,7 +8,7 @@ use crate::{
payments,
},
errors::RouterResult,
- routes::AppState,
+ routes::SessionState,
services::{self, execute_connector_processing_step},
types::{
api, authentication::AuthenticationResponseData, domain, storage,
@@ -48,7 +48,7 @@ pub fn get_connector_data_if_separate_authn_supported(
}
pub async fn update_trackers<F: Clone, Req>(
- state: &AppState,
+ state: &SessionState,
router_data: RouterData<F, Req, AuthenticationResponseData>,
authentication: storage::Authentication,
acquirer_details: Option<super::types::AcquirerDetails>,
@@ -171,7 +171,7 @@ impl ForeignFrom<common_enums::AuthenticationStatus> for common_enums::AttemptSt
}
pub async fn create_new_authentication(
- state: &AppState,
+ state: &SessionState,
merchant_id: String,
authentication_connector: String,
token: String,
@@ -228,7 +228,7 @@ pub async fn create_new_authentication(
}
pub async fn do_auth_connector_call<F, Req, Res>(
- state: &AppState,
+ state: &SessionState,
authentication_connector_name: String,
router_data: RouterData<F, Req, Res>,
) -> RouterResult<RouterData<F, Req, Res>>
@@ -255,7 +255,7 @@ where
}
pub async fn get_authentication_connector_data(
- state: &AppState,
+ state: &SessionState,
key_store: &domain::MerchantKeyStore,
business_profile: &storage::BusinessProfile,
) -> RouterResult<(
diff --git a/crates/router/src/core/blocklist.rs b/crates/router/src/core/blocklist.rs
index 12a0802517..947acc506d 100644
--- a/crates/router/src/core/blocklist.rs
+++ b/crates/router/src/core/blocklist.rs
@@ -5,13 +5,13 @@ use api_models::blocklist as api_blocklist;
use crate::{
core::errors::{self, RouterResponse},
- routes::AppState,
+ routes::SessionState,
services,
types::domain,
};
pub async fn add_entry_to_blocklist(
- state: AppState,
+ state: SessionState,
merchant_account: domain::MerchantAccount,
body: api_blocklist::AddToBlocklistRequest,
) -> RouterResponse<api_blocklist::AddToBlocklistResponse> {
@@ -21,7 +21,7 @@ pub async fn add_entry_to_blocklist(
}
pub async fn remove_entry_from_blocklist(
- state: AppState,
+ state: SessionState,
merchant_account: domain::MerchantAccount,
body: api_blocklist::DeleteFromBlocklistRequest,
) -> RouterResponse<api_blocklist::DeleteFromBlocklistResponse> {
@@ -31,7 +31,7 @@ pub async fn remove_entry_from_blocklist(
}
pub async fn list_blocklist_entries(
- state: AppState,
+ state: SessionState,
merchant_account: domain::MerchantAccount,
query: api_blocklist::ListBlocklistQuery,
) -> RouterResponse<Vec<api_blocklist::BlocklistResponse>> {
@@ -41,7 +41,7 @@ pub async fn list_blocklist_entries(
}
pub async fn toggle_blocklist_guard(
- state: AppState,
+ state: SessionState,
merchant_account: domain::MerchantAccount,
query: api_blocklist::ToggleBlocklistQuery,
) -> RouterResponse<api_blocklist::ToggleBlocklistResponse> {
diff --git a/crates/router/src/core/blocklist/transformers.rs b/crates/router/src/core/blocklist/transformers.rs
index a2583e5b60..c349944560 100644
--- a/crates/router/src/core/blocklist/transformers.rs
+++ b/crates/router/src/core/blocklist/transformers.rs
@@ -111,7 +111,7 @@ async fn generate_jwe_payload_for_request(
#[instrument(skip_all)]
pub async fn generate_fingerprint(
- state: &routes::AppState,
+ state: &routes::SessionState,
card_number: StrongSecret<String>,
hash_key: StrongSecret<String>,
locker_choice: api_enums::LockerChoice,
@@ -129,7 +129,7 @@ pub async fn generate_fingerprint(
#[instrument(skip_all)]
async fn call_to_locker_for_fingerprint(
- state: &routes::AppState,
+ state: &routes::SessionState,
payload: &blocklist::GenerateFingerprintRequest,
locker_choice: api_enums::LockerChoice,
) -> CustomResult<blocklist::GenerateFingerprintResponsePayload, errors::VaultError> {
diff --git a/crates/router/src/core/blocklist/utils.rs b/crates/router/src/core/blocklist/utils.rs
index bc8724da82..6c0d3fcd6c 100644
--- a/crates/router/src/core/blocklist/utils.rs
+++ b/crates/router/src/core/blocklist/utils.rs
@@ -5,7 +5,7 @@ use diesel_models::configs;
use error_stack::ResultExt;
use masking::StrongSecret;
-use super::{errors, transformers::generate_fingerprint, AppState};
+use super::{errors, transformers::generate_fingerprint, SessionState};
use crate::{
consts,
core::{
@@ -18,7 +18,7 @@ use crate::{
};
pub async fn delete_entry_from_blocklist(
- state: &AppState,
+ state: &SessionState,
merchant_id: String,
request: api_blocklist::DeleteFromBlocklistRequest,
) -> RouterResult<api_blocklist::DeleteFromBlocklistResponse> {
@@ -44,7 +44,7 @@ pub async fn delete_entry_from_blocklist(
}
pub async fn toggle_blocklist_guard_for_merchant(
- state: &AppState,
+ state: &SessionState,
merchant_id: String,
query: api_blocklist::ToggleBlocklistQuery,
) -> CustomResult<api_blocklist::ToggleBlocklistResponse, errors::ApiErrorResponse> {
@@ -94,7 +94,7 @@ pub fn get_blocklist_guard_key(merchant_id: &str) -> String {
}
pub async fn list_blocklist_entries_for_merchant(
- state: &AppState,
+ state: &SessionState,
merchant_id: String,
query: api_blocklist::ListBlocklistQuery,
) -> RouterResult<Vec<api_blocklist::BlocklistResponse>> {
@@ -138,7 +138,7 @@ fn validate_extended_card_bin(bin: &str) -> RouterResult<()> {
}
pub async fn insert_entry_into_blocklist(
- state: &AppState,
+ state: &SessionState,
merchant_id: String,
to_block: api_blocklist::AddToBlocklistRequest,
) -> RouterResult<api_blocklist::AddToBlocklistResponse> {
@@ -207,7 +207,7 @@ pub async fn insert_entry_into_blocklist(
}
pub async fn get_merchant_fingerprint_secret(
- state: &AppState,
+ state: &SessionState,
merchant_id: &str,
) -> RouterResult<String> {
let key = get_merchant_fingerprint_secret_key(merchant_id);
@@ -246,7 +246,7 @@ fn get_merchant_fingerprint_secret_key(merchant_id: &str) -> String {
async fn duplicate_check_insert_bin(
bin: &str,
- state: &AppState,
+ state: &SessionState,
merchant_id: &str,
data_kind: common_enums::BlocklistDataKind,
) -> RouterResult<storage::Blocklist> {
@@ -287,7 +287,7 @@ async fn duplicate_check_insert_bin(
}
async fn delete_card_bin_blocklist_entry(
- state: &AppState,
+ state: &SessionState,
bin: &str,
merchant_id: &str,
) -> RouterResult<storage::Blocklist> {
@@ -301,7 +301,7 @@ async fn delete_card_bin_blocklist_entry(
}
pub async fn validate_data_for_blocklist<F>(
- state: &AppState,
+ state: &SessionState,
merchant_account: &domain::MerchantAccount,
payment_data: &mut PaymentData<F>,
) -> CustomResult<bool, errors::ApiErrorResponse>
@@ -452,7 +452,7 @@ where
}
pub async fn generate_payment_fingerprint(
- state: &AppState,
+ state: &SessionState,
merchant_id: String,
payment_method_data: Option<crate::types::api::PaymentMethodData>,
) -> CustomResult<Option<String>, errors::ApiErrorResponse> {
diff --git a/crates/router/src/core/cache.rs b/crates/router/src/core/cache.rs
index 8f3cf765e9..8cda60cf70 100644
--- a/crates/router/src/core/cache.rs
+++ b/crates/router/src/core/cache.rs
@@ -3,10 +3,10 @@ use error_stack::{report, ResultExt};
use storage_impl::redis::cache::{publish_into_redact_channel, CacheKind};
use super::errors;
-use crate::{routes::AppState, services};
+use crate::{routes::SessionState, services};
pub async fn invalidate(
- state: AppState,
+ state: SessionState,
key: &str,
) -> CustomResult<services::api::ApplicationResponse<serde_json::Value>, errors::ApiErrorResponse> {
let store = state.store.as_ref();
diff --git a/crates/router/src/core/cards_info.rs b/crates/router/src/core/cards_info.rs
index 4352e1808c..bc01a786d1 100644
--- a/crates/router/src/core/cards_info.rs
+++ b/crates/router/src/core/cards_info.rs
@@ -21,7 +21,7 @@ fn verify_iin_length(card_iin: &str) -> Result<(), errors::ApiErrorResponse> {
#[instrument(skip_all)]
pub async fn retrieve_card_info(
- state: routes::AppState,
+ state: routes::SessionState,
merchant_account: domain::MerchantAccount,
request: api_models::cards_info::CardsInfoRequest,
) -> RouterResponse<api_models::cards_info::CardInfoResponse> {
diff --git a/crates/router/src/core/conditional_config.rs b/crates/router/src/core/conditional_config.rs
index c352e82505..a8bc8a797d 100644
--- a/crates/router/src/core/conditional_config.rs
+++ b/crates/router/src/core/conditional_config.rs
@@ -12,14 +12,14 @@ use super::routing::helpers::{
};
use crate::{
core::errors::{self, RouterResponse},
- routes::AppState,
+ routes::SessionState,
services::api as service_api,
types::domain,
utils::OptionExt,
};
pub async fn upsert_conditional_config(
- state: AppState,
+ state: SessionState,
key_store: domain::MerchantKeyStore,
merchant_account: domain::MerchantAccount,
request: DecisionManager,
@@ -149,7 +149,7 @@ pub async fn upsert_conditional_config(
}
pub async fn delete_conditional_config(
- state: AppState,
+ state: SessionState,
key_store: domain::MerchantKeyStore,
merchant_account: domain::MerchantAccount,
) -> RouterResponse<()> {
@@ -177,7 +177,7 @@ pub async fn delete_conditional_config(
}
pub async fn retrieve_conditional_config(
- state: AppState,
+ state: SessionState,
merchant_account: domain::MerchantAccount,
) -> RouterResponse<DecisionManagerResponse> {
let db = state.store.as_ref();
diff --git a/crates/router/src/core/configs.rs b/crates/router/src/core/configs.rs
index ba2303167d..be8dfc8382 100644
--- a/crates/router/src/core/configs.rs
+++ b/crates/router/src/core/configs.rs
@@ -2,12 +2,12 @@ use error_stack::ResultExt;
use crate::{
core::errors::{self, utils::StorageErrorExt, RouterResponse},
- routes::AppState,
+ routes::SessionState,
services::ApplicationResponse,
types::{api, transformers::ForeignInto},
};
-pub async fn set_config(state: AppState, config: api::Config) -> RouterResponse<api::Config> {
+pub async fn set_config(state: SessionState, config: api::Config) -> RouterResponse<api::Config> {
let store = state.store.as_ref();
let config = store
.insert_config(diesel_models::configs::ConfigNew {
@@ -21,7 +21,7 @@ pub async fn set_config(state: AppState, config: api::Config) -> RouterResponse<
Ok(ApplicationResponse::Json(config.foreign_into()))
}
-pub async fn read_config(state: AppState, key: &str) -> RouterResponse<api::Config> {
+pub async fn read_config(state: SessionState, key: &str) -> RouterResponse<api::Config> {
let store = state.store.as_ref();
let config = store
.find_config_by_key(key)
@@ -31,7 +31,7 @@ pub async fn read_config(state: AppState, key: &str) -> RouterResponse<api::Conf
}
pub async fn update_config(
- state: AppState,
+ state: SessionState,
config_update: &api::ConfigUpdate,
) -> RouterResponse<api::Config> {
let store = state.store.as_ref();
@@ -42,7 +42,7 @@ pub async fn update_config(
Ok(ApplicationResponse::Json(config.foreign_into()))
}
-pub async fn config_delete(state: AppState, key: String) -> RouterResponse<api::Config> {
+pub async fn config_delete(state: SessionState, key: String) -> RouterResponse<api::Config> {
let store = state.store.as_ref();
let config = store
.delete_config_by_key(&key)
diff --git a/crates/router/src/core/connector_onboarding.rs b/crates/router/src/core/connector_onboarding.rs
index b69b2996a6..d6c20cc281 100644
--- a/crates/router/src/core/connector_onboarding.rs
+++ b/crates/router/src/core/connector_onboarding.rs
@@ -7,18 +7,18 @@ use crate::{
services::{authentication as auth, ApplicationResponse},
types as oss_types,
utils::connector_onboarding as utils,
- AppState,
+ SessionState,
};
pub mod paypal;
#[async_trait::async_trait]
pub trait AccessToken {
- async fn access_token(state: &AppState) -> RouterResult<oss_types::AccessToken>;
+ async fn access_token(state: &SessionState) -> RouterResult<oss_types::AccessToken>;
}
pub async fn get_action_url(
- state: AppState,
+ state: SessionState,
user_from_token: auth::UserFromToken,
request: api::ActionUrlRequest,
_req_state: ReqState,
@@ -53,7 +53,7 @@ pub async fn get_action_url(
}
pub async fn sync_onboarding_status(
- state: AppState,
+ state: SessionState,
user_from_token: auth::UserFromToken,
request: api::OnboardingSyncRequest,
_req_state: ReqState,
@@ -107,7 +107,7 @@ pub async fn sync_onboarding_status(
}
pub async fn reset_tracking_id(
- state: AppState,
+ state: SessionState,
user_from_token: auth::UserFromToken,
request: api::ResetTrackingIdRequest,
_req_state: ReqState,
diff --git a/crates/router/src/core/connector_onboarding/paypal.rs b/crates/router/src/core/connector_onboarding/paypal.rs
index 616fcbdc8c..6f28cfcbf8 100644
--- a/crates/router/src/core/connector_onboarding/paypal.rs
+++ b/crates/router/src/core/connector_onboarding/paypal.rs
@@ -11,10 +11,10 @@ use crate::{
services::{send_request, ApplicationResponse, Request},
types::{self as oss_types, api as oss_api_types, api::connector_onboarding as types},
utils::connector_onboarding as utils,
- AppState,
+ SessionState,
};
-fn build_referral_url(state: AppState) -> String {
+fn build_referral_url(state: SessionState) -> String {
format!(
"{}v2/customer/partner-referrals",
state.conf.connectors.paypal.base_url
@@ -22,7 +22,7 @@ fn build_referral_url(state: AppState) -> String {
}
async fn build_referral_request(
- state: AppState,
+ state: SessionState,
tracking_id: String,
return_url: String,
) -> RouterResult<Request> {
@@ -37,7 +37,7 @@ async fn build_referral_request(
}
pub async fn get_action_url_from_paypal(
- state: AppState,
+ state: SessionState,
tracking_id: String,
return_url: String,
) -> RouterResult<String> {
@@ -61,7 +61,7 @@ pub async fn get_action_url_from_paypal(
parsed_response.extract_action_url()
}
-fn merchant_onboarding_status_url(state: AppState, tracking_id: String) -> String {
+fn merchant_onboarding_status_url(state: SessionState, tracking_id: String) -> String {
let partner_id = state
.conf
.connector_onboarding
@@ -78,7 +78,7 @@ fn merchant_onboarding_status_url(state: AppState, tracking_id: String) -> Strin
}
pub async fn sync_merchant_onboarding_status(
- state: AppState,
+ state: SessionState,
tracking_id: String,
) -> RouterResult<api::OnboardingStatus> {
let access_token = utils::paypal::generate_access_token(state.clone()).await?;
@@ -113,7 +113,7 @@ pub async fn sync_merchant_onboarding_status(
}
async fn find_paypal_merchant_by_tracking_id(
- state: AppState,
+ state: SessionState,
tracking_id: String,
access_token: &oss_types::AccessToken,
) -> RouterResult<Option<types::paypal::SellerStatusResponse>> {
@@ -139,7 +139,7 @@ async fn find_paypal_merchant_by_tracking_id(
}
pub async fn update_mca(
- state: &AppState,
+ state: &SessionState,
merchant_id: String,
connector_id: String,
auth_details: oss_types::ConnectorAuthType,
diff --git a/crates/router/src/core/currency.rs b/crates/router/src/core/currency.rs
index f2791deb7b..96d7509827 100644
--- a/crates/router/src/core/currency.rs
+++ b/crates/router/src/core/currency.rs
@@ -5,11 +5,11 @@ use crate::{
core::errors::ApiErrorResponse,
services::ApplicationResponse,
utils::currency::{self, convert_currency, get_forex_rates},
- AppState,
+ SessionState,
};
pub async fn retrieve_forex(
- state: AppState,
+ state: SessionState,
) -> CustomResult<ApplicationResponse<currency::FxExchangeRatesCacheEntry>, ApiErrorResponse> {
let forex_api = state.conf.forex_api.get_inner();
Ok(ApplicationResponse::Json(
@@ -27,7 +27,7 @@ pub async fn retrieve_forex(
}
pub async fn convert_forex(
- state: AppState,
+ state: SessionState,
amount: i64,
to_currency: String,
from_currency: String,
diff --git a/crates/router/src/core/customers.rs b/crates/router/src/core/customers.rs
index 1c983dcde9..ad1a292df0 100644
--- a/crates/router/src/core/customers.rs
+++ b/crates/router/src/core/customers.rs
@@ -13,7 +13,7 @@ use crate::{
payment_methods::cards,
},
pii::PeekInterface,
- routes::{metrics, AppState},
+ routes::{metrics, SessionState},
services,
types::{
api::customers,
@@ -30,7 +30,7 @@ pub const REDACTED: &str = "Redacted";
#[instrument(skip(state))]
pub async fn create_customer(
- state: AppState,
+ state: SessionState,
merchant_account: domain::MerchantAccount,
key_store: domain::MerchantKeyStore,
mut customer_data: customers::CustomerRequest,
@@ -142,7 +142,7 @@ pub async fn create_customer(
#[instrument(skip(state))]
pub async fn retrieve_customer(
- state: AppState,
+ state: SessionState,
merchant_account: domain::MerchantAccount,
key_store: domain::MerchantKeyStore,
req: customers::CustomerId,
@@ -172,7 +172,7 @@ pub async fn retrieve_customer(
#[instrument(skip(state))]
pub async fn list_customers(
- state: AppState,
+ state: SessionState,
merchant_id: String,
key_store: domain::MerchantKeyStore,
) -> errors::CustomerResponse<Vec<customers::CustomerResponse>> {
@@ -193,7 +193,7 @@ pub async fn list_customers(
#[instrument(skip_all)]
pub async fn delete_customer(
- state: AppState,
+ state: SessionState,
merchant_account: domain::MerchantAccount,
req: customers::CustomerId,
key_store: domain::MerchantKeyStore,
@@ -348,7 +348,7 @@ pub async fn delete_customer(
#[instrument(skip(state))]
pub async fn update_customer(
- state: AppState,
+ state: SessionState,
merchant_account: domain::MerchantAccount,
update_customer: customers::CustomerRequest,
key_store: domain::MerchantKeyStore,
diff --git a/crates/router/src/core/disputes.rs b/crates/router/src/core/disputes.rs
index f608100c08..8836128690 100644
--- a/crates/router/src/core/disputes.rs
+++ b/crates/router/src/core/disputes.rs
@@ -10,7 +10,7 @@ use super::{
};
use crate::{
core::{files, payments, utils as core_utils},
- routes::AppState,
+ routes::SessionState,
services,
types::{
api::{self, disputes},
@@ -24,7 +24,7 @@ use crate::{
#[instrument(skip(state))]
pub async fn retrieve_dispute(
- state: AppState,
+ state: SessionState,
merchant_account: domain::MerchantAccount,
req: disputes::DisputeId,
) -> RouterResponse<api_models::disputes::DisputeResponse> {
@@ -41,7 +41,7 @@ pub async fn retrieve_dispute(
#[instrument(skip(state))]
pub async fn retrieve_disputes_list(
- state: AppState,
+ state: SessionState,
merchant_account: domain::MerchantAccount,
constraints: api_models::disputes::DisputeListConstraints,
) -> RouterResponse<Vec<api_models::disputes::DisputeResponse>> {
@@ -60,7 +60,7 @@ pub async fn retrieve_disputes_list(
#[instrument(skip(state))]
pub async fn accept_dispute(
- state: AppState,
+ state: SessionState,
merchant_account: domain::MerchantAccount,
key_store: domain::MerchantKeyStore,
req: disputes::DisputeId,
@@ -161,7 +161,7 @@ pub async fn accept_dispute(
#[instrument(skip(state))]
pub async fn submit_evidence(
- state: AppState,
+ state: SessionState,
merchant_account: domain::MerchantAccount,
key_store: domain::MerchantKeyStore,
req: dispute_models::SubmitEvidenceRequest,
@@ -324,7 +324,7 @@ pub async fn submit_evidence(
}
pub async fn attach_evidence(
- state: AppState,
+ state: SessionState,
merchant_account: domain::MerchantAccount,
key_store: domain::MerchantKeyStore,
attach_evidence_request: api::AttachEvidenceRequest,
@@ -401,7 +401,7 @@ pub async fn attach_evidence(
#[instrument(skip(state))]
pub async fn retrieve_dispute_evidence(
- state: AppState,
+ state: SessionState,
merchant_account: domain::MerchantAccount,
req: disputes::DisputeId,
) -> RouterResponse<Vec<api_models::disputes::DisputeEvidenceBlock>> {
@@ -424,7 +424,7 @@ pub async fn retrieve_dispute_evidence(
}
pub async fn delete_evidence(
- state: AppState,
+ state: SessionState,
merchant_account: domain::MerchantAccount,
delete_evidence_request: dispute_models::DeleteEvidenceRequest,
) -> RouterResponse<serde_json::Value> {
diff --git a/crates/router/src/core/disputes/transformers.rs b/crates/router/src/core/disputes/transformers.rs
index 936184fc99..d37410d5ef 100644
--- a/crates/router/src/core/disputes/transformers.rs
+++ b/crates/router/src/core/disputes/transformers.rs
@@ -4,7 +4,7 @@ use error_stack::ResultExt;
use crate::{
core::{errors, files::helpers::retrieve_file_and_provider_file_id_from_file_id},
- routes::AppState,
+ routes::SessionState,
types::{
api::{self, DisputeEvidence},
domain,
@@ -14,7 +14,7 @@ use crate::{
};
pub async fn get_evidence_request_data(
- state: &AppState,
+ state: &SessionState,
merchant_account: &domain::MerchantAccount,
key_store: &domain::MerchantKeyStore,
evidence_request: api_models::disputes::SubmitEvidenceRequest,
@@ -203,7 +203,7 @@ pub fn update_dispute_evidence(
}
pub async fn get_dispute_evidence_block(
- state: &AppState,
+ state: &SessionState,
merchant_account: &domain::MerchantAccount,
evidence_type: EvidenceType,
file_id: String,
@@ -271,7 +271,7 @@ pub fn delete_evidence_file(
}
pub async fn get_dispute_evidence_vec(
- state: &AppState,
+ state: &SessionState,
merchant_account: domain::MerchantAccount,
dispute_evidence: DisputeEvidence,
) -> CustomResult<Vec<api_models::disputes::DisputeEvidenceBlock>, errors::ApiErrorResponse> {
diff --git a/crates/router/src/core/files.rs b/crates/router/src/core/files.rs
index 5dedcb1486..9ba5c29ce7 100644
--- a/crates/router/src/core/files.rs
+++ b/crates/router/src/core/files.rs
@@ -6,13 +6,13 @@ use error_stack::ResultExt;
use super::errors::{self, RouterResponse};
use crate::{
consts,
- routes::AppState,
+ routes::SessionState,
services::ApplicationResponse,
types::{api, domain},
};
pub async fn files_create_core(
- state: AppState,
+ state: SessionState,
merchant_account: domain::MerchantAccount,
key_store: domain::MerchantKeyStore,
create_file_request: api::CreateFileRequest,
@@ -78,7 +78,7 @@ pub async fn files_create_core(
}
pub async fn files_delete_core(
- state: AppState,
+ state: SessionState,
merchant_account: domain::MerchantAccount,
req: api::FileId,
) -> RouterResponse<serde_json::Value> {
@@ -94,7 +94,7 @@ pub async fn files_delete_core(
}
pub async fn files_retrieve_core(
- state: AppState,
+ state: SessionState,
merchant_account: domain::MerchantAccount,
key_store: domain::MerchantKeyStore,
req: api::FileId,
diff --git a/crates/router/src/core/files/helpers.rs b/crates/router/src/core/files/helpers.rs
index 0c6a88d827..0be198377b 100644
--- a/crates/router/src/core/files/helpers.rs
+++ b/crates/router/src/core/files/helpers.rs
@@ -8,7 +8,7 @@ use crate::{
errors::{self, StorageErrorExt},
payments, utils,
},
- routes::AppState,
+ routes::SessionState,
services,
types::{self, api, domain, transformers::ForeignTryFrom},
};
@@ -31,7 +31,7 @@ pub async fn get_file_purpose(field: &mut Field) -> Option<api::FilePurpose> {
}
pub async fn validate_file_upload(
- state: &AppState,
+ state: &SessionState,
merchant_account: domain::MerchantAccount,
create_file_request: api::CreateFileRequest,
) -> CustomResult<(), errors::ApiErrorResponse> {
@@ -81,7 +81,7 @@ pub async fn validate_file_upload(
}
pub async fn delete_file_using_file_id(
- state: &AppState,
+ state: &SessionState,
file_key: String,
merchant_account: &domain::MerchantAccount,
) -> CustomResult<(), errors::ApiErrorResponse> {
@@ -113,7 +113,7 @@ pub async fn delete_file_using_file_id(
}
pub async fn retrieve_file_from_connector(
- state: &AppState,
+ state: &SessionState,
file_metadata: diesel_models::file::FileMetadata,
merchant_account: &domain::MerchantAccount,
key_store: &domain::MerchantKeyStore,
@@ -171,7 +171,7 @@ pub async fn retrieve_file_from_connector(
}
pub async fn retrieve_file_and_provider_file_id_from_file_id(
- state: &AppState,
+ state: &SessionState,
file_id: Option<String>,
merchant_account: &domain::MerchantAccount,
key_store: &domain::MerchantKeyStore,
@@ -227,7 +227,7 @@ pub async fn retrieve_file_and_provider_file_id_from_file_id(
//Upload file to connector if it supports / store it in S3 and return file_upload_provider, provider_file_id accordingly
pub async fn upload_and_get_provider_provider_file_id_profile_id(
- state: &AppState,
+ state: &SessionState,
merchant_account: &domain::MerchantAccount,
key_store: &domain::MerchantKeyStore,
create_file_request: &api::CreateFileRequest,
diff --git a/crates/router/src/core/fraud_check.rs b/crates/router/src/core/fraud_check.rs
index dddcf58129..f7f7108c2b 100644
--- a/crates/router/src/core/fraud_check.rs
+++ b/crates/router/src/core/fraud_check.rs
@@ -24,7 +24,7 @@ use crate::{
utils as core_utils,
},
db::StorageInterface,
- routes::{app::ReqState, AppState},
+ routes::{app::ReqState, SessionState},
services,
types::{
self as oss_types,
@@ -50,7 +50,7 @@ pub mod types;
#[instrument(skip_all)]
pub async fn call_frm_service<D: Clone, F, Req>(
- state: &AppState,
+ state: &SessionState,
payment_data: &mut payments::PaymentData<D>,
frm_data: &mut FrmData,
merchant_account: &domain::MerchantAccount,
@@ -302,7 +302,7 @@ where
#[allow(clippy::too_many_arguments)]
pub async fn make_frm_data_and_fraud_check_operation<'a, F>(
_db: &dyn StorageInterface,
- state: &AppState,
+ state: &SessionState,
merchant_account: &domain::MerchantAccount,
payment_data: payments::PaymentData<F>,
frm_routing_algorithm: FrmRoutingAlgorithm,
@@ -370,7 +370,7 @@ where
#[allow(clippy::too_many_arguments)]
pub async fn pre_payment_frm_core<'a, F, Req>(
- state: &AppState,
+ state: &SessionState,
merchant_account: &domain::MerchantAccount,
payment_data: &mut payments::PaymentData<F>,
frm_info: &mut FrmInfo<F>,
@@ -456,7 +456,7 @@ where
#[allow(clippy::too_many_arguments)]
pub async fn post_payment_frm_core<'a, F>(
- state: &AppState,
+ state: &SessionState,
req_state: ReqState,
merchant_account: &domain::MerchantAccount,
payment_data: &mut payments::PaymentData<F>,
@@ -547,7 +547,7 @@ pub async fn call_frm_before_connector_call<'a, F, Req>(
operation: &BoxedOperation<'_, F, Req>,
merchant_account: &domain::MerchantAccount,
payment_data: &mut payments::PaymentData<F>,
- state: &AppState,
+ state: &SessionState,
frm_info: &mut Option<FrmInfo<F>>,
customer: &Option<domain::Customer>,
should_continue_transaction: &mut bool,
@@ -643,7 +643,7 @@ impl From<PaymentToFrmData> for PaymentDetails {
#[instrument(skip_all)]
pub async fn frm_fulfillment_core(
- state: AppState,
+ state: SessionState,
merchant_account: domain::MerchantAccount,
key_store: domain::MerchantKeyStore,
req: frm_core_types::FrmFulfillmentRequest,
@@ -705,7 +705,7 @@ pub async fn make_fulfillment_api_call(
db: &dyn StorageInterface,
fraud_check: FraudCheck,
payment_intent: PaymentIntent,
- state: AppState,
+ state: SessionState,
merchant_account: domain::MerchantAccount,
key_store: domain::MerchantKeyStore,
req: frm_core_types::FrmFulfillmentRequest,
diff --git a/crates/router/src/core/fraud_check/flows.rs b/crates/router/src/core/fraud_check/flows.rs
index 3d4916a372..896d062bc1 100644
--- a/crates/router/src/core/fraud_check/flows.rs
+++ b/crates/router/src/core/fraud_check/flows.rs
@@ -11,7 +11,7 @@ use crate::{
errors::RouterResult,
payments::{self, flows::ConstructFlowSpecificData},
},
- routes::AppState,
+ routes::SessionState,
services,
types::{
api::{Connector, FraudCheckConnectorData},
@@ -24,7 +24,7 @@ use crate::{
pub trait FeatureFrm<F, T> {
async fn decide_frm_flows<'a>(
self,
- state: &AppState,
+ state: &SessionState,
connector: &FraudCheckConnectorData,
call_connector_action: payments::CallConnectorAction,
merchant_account: &domain::MerchantAccount,
diff --git a/crates/router/src/core/fraud_check/flows/checkout_flow.rs b/crates/router/src/core/fraud_check/flows/checkout_flow.rs
index c754682f72..74353e83b3 100644
--- a/crates/router/src/core/fraud_check/flows/checkout_flow.rs
+++ b/crates/router/src/core/fraud_check/flows/checkout_flow.rs
@@ -19,7 +19,7 @@ use crate::{
storage::enums as storage_enums,
BrowserInformation, ConnectorAuthType, ResponseId, RouterData,
},
- AppState,
+ SessionState,
};
#[async_trait]
@@ -28,7 +28,7 @@ impl ConstructFlowSpecificData<frm_api::Checkout, FraudCheckCheckoutData, FraudC
{
async fn construct_router_data<'a>(
&self,
- _state: &AppState,
+ _state: &SessionState,
connector_id: &str,
merchant_account: &domain::MerchantAccount,
_key_store: &domain::MerchantKeyStore,
@@ -138,7 +138,7 @@ impl ConstructFlowSpecificData<frm_api::Checkout, FraudCheckCheckoutData, FraudC
impl FeatureFrm<frm_api::Checkout, FraudCheckCheckoutData> for FrmCheckoutRouterData {
async fn decide_frm_flows<'a>(
mut self,
- state: &AppState,
+ state: &SessionState,
connector: &FraudCheckConnectorData,
call_connector_action: payments::CallConnectorAction,
merchant_account: &domain::MerchantAccount,
@@ -156,7 +156,7 @@ impl FeatureFrm<frm_api::Checkout, FraudCheckCheckoutData> for FrmCheckoutRouter
pub async fn decide_frm_flow<'a, 'b>(
router_data: &'b mut FrmCheckoutRouterData,
- state: &'a AppState,
+ state: &'a SessionState,
connector: &FraudCheckConnectorData,
call_connector_action: payments::CallConnectorAction,
_merchant_account: &domain::MerchantAccount,
diff --git a/crates/router/src/core/fraud_check/flows/fulfillment_flow.rs b/crates/router/src/core/fraud_check/flows/fulfillment_flow.rs
index 1f4f2ccebe..f91d87c808 100644
--- a/crates/router/src/core/fraud_check/flows/fulfillment_flow.rs
+++ b/crates/router/src/core/fraud_check/flows/fulfillment_flow.rs
@@ -13,12 +13,12 @@ use crate::{
fraud_check::{FraudCheckFulfillmentData, FrmFulfillmentRouterData},
storage, ConnectorAuthType, ErrorResponse, PaymentAddress, RouterData,
},
- utils, AppState,
+ utils, SessionState,
};
#[instrument(skip_all)]
pub async fn construct_fulfillment_router_data<'a>(
- state: &'a AppState,
+ state: &'a SessionState,
payment_intent: &'a storage::PaymentIntent,
payment_attempt: &storage::PaymentAttempt,
merchant_account: &domain::MerchantAccount,
diff --git a/crates/router/src/core/fraud_check/flows/record_return.rs b/crates/router/src/core/fraud_check/flows/record_return.rs
index b854a33377..b8f8810f09 100644
--- a/crates/router/src/core/fraud_check/flows/record_return.rs
+++ b/crates/router/src/core/fraud_check/flows/record_return.rs
@@ -19,7 +19,7 @@ use crate::{
storage::enums as storage_enums,
ConnectorAuthType, ResponseId, RouterData,
},
- utils, AppState,
+ utils, SessionState,
};
#[async_trait]
@@ -28,7 +28,7 @@ impl ConstructFlowSpecificData<RecordReturn, FraudCheckRecordReturnData, FraudCh
{
async fn construct_router_data<'a>(
&self,
- _state: &AppState,
+ _state: &SessionState,
connector_id: &str,
merchant_account: &domain::MerchantAccount,
_key_store: &domain::MerchantKeyStore,
@@ -110,7 +110,7 @@ impl ConstructFlowSpecificData<RecordReturn, FraudCheckRecordReturnData, FraudCh
impl FeatureFrm<RecordReturn, FraudCheckRecordReturnData> for FrmRecordReturnRouterData {
async fn decide_frm_flows<'a>(
mut self,
- state: &AppState,
+ state: &SessionState,
connector: &FraudCheckConnectorData,
call_connector_action: payments::CallConnectorAction,
merchant_account: &domain::MerchantAccount,
@@ -128,7 +128,7 @@ impl FeatureFrm<RecordReturn, FraudCheckRecordReturnData> for FrmRecordReturnRou
pub async fn decide_frm_flow<'a, 'b>(
router_data: &'b mut FrmRecordReturnRouterData,
- state: &'a AppState,
+ state: &'a SessionState,
connector: &FraudCheckConnectorData,
call_connector_action: payments::CallConnectorAction,
_merchant_account: &domain::MerchantAccount,
diff --git a/crates/router/src/core/fraud_check/flows/sale_flow.rs b/crates/router/src/core/fraud_check/flows/sale_flow.rs
index 829f8b736b..b605c54065 100644
--- a/crates/router/src/core/fraud_check/flows/sale_flow.rs
+++ b/crates/router/src/core/fraud_check/flows/sale_flow.rs
@@ -17,7 +17,7 @@ use crate::{
storage::enums as storage_enums,
ConnectorAuthType, ResponseId, RouterData,
},
- AppState,
+ SessionState,
};
#[async_trait]
@@ -26,7 +26,7 @@ impl ConstructFlowSpecificData<frm_api::Sale, FraudCheckSaleData, FraudCheckResp
{
async fn construct_router_data<'a>(
&self,
- _state: &AppState,
+ _state: &SessionState,
connector_id: &str,
merchant_account: &domain::MerchantAccount,
_key_store: &domain::MerchantKeyStore,
@@ -119,7 +119,7 @@ impl ConstructFlowSpecificData<frm_api::Sale, FraudCheckSaleData, FraudCheckResp
impl FeatureFrm<frm_api::Sale, FraudCheckSaleData> for FrmSaleRouterData {
async fn decide_frm_flows<'a>(
mut self,
- state: &AppState,
+ state: &SessionState,
connector: &FraudCheckConnectorData,
call_connector_action: payments::CallConnectorAction,
merchant_account: &domain::MerchantAccount,
@@ -137,7 +137,7 @@ impl FeatureFrm<frm_api::Sale, FraudCheckSaleData> for FrmSaleRouterData {
pub async fn decide_frm_flow<'a, 'b>(
router_data: &'b mut FrmSaleRouterData,
- state: &'a AppState,
+ state: &'a SessionState,
connector: &FraudCheckConnectorData,
call_connector_action: payments::CallConnectorAction,
_merchant_account: &domain::MerchantAccount,
diff --git a/crates/router/src/core/fraud_check/flows/transaction_flow.rs b/crates/router/src/core/fraud_check/flows/transaction_flow.rs
index 0b851d7b62..8c496792a8 100644
--- a/crates/router/src/core/fraud_check/flows/transaction_flow.rs
+++ b/crates/router/src/core/fraud_check/flows/transaction_flow.rs
@@ -18,7 +18,7 @@ use crate::{
storage::enums as storage_enums,
ConnectorAuthType, ResponseId, RouterData,
},
- AppState,
+ SessionState,
};
#[async_trait]
@@ -31,7 +31,7 @@ impl
{
async fn construct_router_data<'a>(
&self,
- _state: &AppState,
+ _state: &SessionState,
connector_id: &str,
merchant_account: &domain::MerchantAccount,
_key_store: &domain::MerchantKeyStore,
@@ -123,7 +123,7 @@ impl
impl FeatureFrm<frm_api::Transaction, FraudCheckTransactionData> for FrmTransactionRouterData {
async fn decide_frm_flows<'a>(
mut self,
- state: &AppState,
+ state: &SessionState,
connector: &frm_api::FraudCheckConnectorData,
call_connector_action: payments::CallConnectorAction,
merchant_account: &domain::MerchantAccount,
@@ -141,7 +141,7 @@ impl FeatureFrm<frm_api::Transaction, FraudCheckTransactionData> for FrmTransact
pub async fn decide_frm_flow<'a, 'b>(
router_data: &'b mut FrmTransactionRouterData,
- state: &'a AppState,
+ state: &'a SessionState,
connector: &frm_api::FraudCheckConnectorData,
call_connector_action: payments::CallConnectorAction,
_merchant_account: &domain::MerchantAccount,
diff --git a/crates/router/src/core/fraud_check/operation.rs b/crates/router/src/core/fraud_check/operation.rs
index a9b95cdf3b..33a370ac84 100644
--- a/crates/router/src/core/fraud_check/operation.rs
+++ b/crates/router/src/core/fraud_check/operation.rs
@@ -15,7 +15,7 @@ use crate::{
payments,
},
db::StorageInterface,
- routes::{app::ReqState, AppState},
+ routes::{app::ReqState, SessionState},
types::{domain, fraud_check::FrmRouterData},
};
@@ -40,7 +40,7 @@ pub trait FraudCheckOperation<F>: Send + std::fmt::Debug {
pub trait GetTracker<D>: Send {
async fn get_trackers<'a>(
&'a self,
- state: &'a AppState,
+ state: &'a SessionState,
payment_data: D,
frm_connector_details: ConnectorDetailsCore,
) -> RouterResult<Option<FrmData>>;
@@ -51,7 +51,7 @@ pub trait GetTracker<D>: Send {
pub trait Domain<F>: Send + Sync {
async fn post_payment_frm<'a>(
&'a self,
- state: &'a AppState,
+ state: &'a SessionState,
req_state: ReqState,
payment_data: &mut payments::PaymentData<F>,
frm_data: &mut FrmData,
@@ -64,7 +64,7 @@ pub trait Domain<F>: Send + Sync {
async fn pre_payment_frm<'a>(
&'a self,
- state: &'a AppState,
+ state: &'a SessionState,
payment_data: &mut payments::PaymentData<F>,
frm_data: &mut FrmData,
merchant_account: &domain::MerchantAccount,
@@ -79,7 +79,7 @@ pub trait Domain<F>: Send + Sync {
#[allow(clippy::too_many_arguments)]
async fn execute_post_tasks(
&self,
- _state: &AppState,
+ _state: &SessionState,
_req_state: ReqState,
frm_data: &mut FrmData,
_merchant_account: &domain::MerchantAccount,
diff --git a/crates/router/src/core/fraud_check/operation/fraud_check_post.rs b/crates/router/src/core/fraud_check/operation/fraud_check_post.rs
index 6a310aa131..cc4fc0370e 100644
--- a/crates/router/src/core/fraud_check/operation/fraud_check_post.rs
+++ b/crates/router/src/core/fraud_check/operation/fraud_check_post.rs
@@ -38,7 +38,7 @@ use crate::{
},
ResponseId,
},
- utils, AppState,
+ utils, SessionState,
};
#[derive(Debug, Clone, Copy)]
@@ -73,7 +73,7 @@ impl GetTracker<PaymentToFrmData> for FraudCheckPost {
#[instrument(skip_all)]
async fn get_trackers<'a>(
&'a self,
- state: &'a AppState,
+ state: &'a SessionState,
payment_data: PaymentToFrmData,
frm_connector_details: ConnectorDetailsCore,
) -> RouterResult<Option<FrmData>> {
@@ -142,7 +142,7 @@ impl<F: Send + Clone> Domain<F> for FraudCheckPost {
#[instrument(skip_all)]
async fn post_payment_frm<'a>(
&'a self,
- state: &'a AppState,
+ state: &'a SessionState,
_req_state: ReqState,
payment_data: &mut payments::PaymentData<F>,
frm_data: &mut FrmData,
@@ -182,7 +182,7 @@ impl<F: Send + Clone> Domain<F> for FraudCheckPost {
#[instrument(skip_all)]
async fn execute_post_tasks(
&self,
- state: &AppState,
+ state: &SessionState,
req_state: ReqState,
frm_data: &mut FrmData,
merchant_account: &domain::MerchantAccount,
@@ -293,7 +293,7 @@ impl<F: Send + Clone> Domain<F> for FraudCheckPost {
#[instrument(skip_all)]
async fn pre_payment_frm<'a>(
&'a self,
- state: &'a AppState,
+ state: &'a SessionState,
payment_data: &mut payments::PaymentData<F>,
frm_data: &mut FrmData,
merchant_account: &domain::MerchantAccount,
diff --git a/crates/router/src/core/fraud_check/operation/fraud_check_pre.rs b/crates/router/src/core/fraud_check/operation/fraud_check_pre.rs
index ae316e7a11..272cd5aa70 100644
--- a/crates/router/src/core/fraud_check/operation/fraud_check_pre.rs
+++ b/crates/router/src/core/fraud_check/operation/fraud_check_pre.rs
@@ -32,7 +32,7 @@ use crate::{
},
ResponseId,
},
- AppState,
+ SessionState,
};
#[derive(Debug, Clone, Copy)]
@@ -67,7 +67,7 @@ impl GetTracker<PaymentToFrmData> for FraudCheckPre {
#[instrument(skip_all)]
async fn get_trackers<'a>(
&'a self,
- state: &'a AppState,
+ state: &'a SessionState,
payment_data: PaymentToFrmData,
frm_connector_details: ConnectorDetailsCore,
) -> RouterResult<Option<FrmData>> {
@@ -139,7 +139,7 @@ impl<F: Send + Clone> Domain<F> for FraudCheckPre {
#[instrument(skip_all)]
async fn post_payment_frm<'a>(
&'a self,
- state: &'a AppState,
+ state: &'a SessionState,
_req_state: ReqState,
payment_data: &mut payments::PaymentData<F>,
frm_data: &mut FrmData,
@@ -178,7 +178,7 @@ impl<F: Send + Clone> Domain<F> for FraudCheckPre {
async fn pre_payment_frm<'a>(
&'a self,
- state: &'a AppState,
+ state: &'a SessionState,
payment_data: &mut payments::PaymentData<F>,
frm_data: &mut FrmData,
merchant_account: &domain::MerchantAccount,
diff --git a/crates/router/src/core/gsm.rs b/crates/router/src/core/gsm.rs
index 668c1773e2..4a678a5c40 100644
--- a/crates/router/src/core/gsm.rs
+++ b/crates/router/src/core/gsm.rs
@@ -11,12 +11,12 @@ use crate::{
db::gsm::GsmInterface,
services,
types::transformers::ForeignInto,
- AppState,
+ SessionState,
};
#[instrument(skip_all)]
pub async fn create_gsm_rule(
- state: AppState,
+ state: SessionState,
gsm_rule: gsm_api_types::GsmCreateRequest,
) -> RouterResponse<gsm_api_types::GsmResponse> {
let db = state.store.as_ref();
@@ -30,7 +30,7 @@ pub async fn create_gsm_rule(
#[instrument(skip_all)]
pub async fn retrieve_gsm_rule(
- state: AppState,
+ state: SessionState,
gsm_request: gsm_api_types::GsmRetrieveRequest,
) -> RouterResponse<gsm_api_types::GsmResponse> {
let db = state.store.as_ref();
@@ -51,7 +51,7 @@ pub async fn retrieve_gsm_rule(
#[instrument(skip_all)]
pub async fn update_gsm_rule(
- state: AppState,
+ state: SessionState,
gsm_request: gsm_api_types::GsmUpdateRequest,
) -> RouterResponse<gsm_api_types::GsmResponse> {
let db = state.store.as_ref();
@@ -94,7 +94,7 @@ pub async fn update_gsm_rule(
#[instrument(skip_all)]
pub async fn delete_gsm_rule(
- state: AppState,
+ state: SessionState,
gsm_request: gsm_api_types::GsmDeleteRequest,
) -> RouterResponse<gsm_api_types::GsmDeleteResponse> {
let db = state.store.as_ref();
diff --git a/crates/router/src/core/health_check.rs b/crates/router/src/core/health_check.rs
index e90fe77e80..6092ac8bbb 100644
--- a/crates/router/src/core/health_check.rs
+++ b/crates/router/src/core/health_check.rs
@@ -31,7 +31,7 @@ pub trait HealthCheckInterface {
}
#[async_trait::async_trait]
-impl HealthCheckInterface for app::AppState {
+impl HealthCheckInterface for app::SessionState {
async fn health_check_db(&self) -> CustomResult<HealthState, errors::HealthCheckDBError> {
let db = &*self.store;
db.health_check_db().await?;
diff --git a/crates/router/src/core/locker_migration.rs b/crates/router/src/core/locker_migration.rs
index 9dbc542874..d968e62bea 100644
--- a/crates/router/src/core/locker_migration.rs
+++ b/crates/router/src/core/locker_migration.rs
@@ -7,13 +7,13 @@ use futures::TryFutureExt;
use super::{errors::StorageErrorExt, payment_methods::cards};
use crate::{
errors,
- routes::AppState,
+ routes::SessionState,
services::{self, logger},
types::{api, domain},
};
pub async fn rust_locker_migration(
- state: AppState,
+ state: SessionState,
merchant_id: &str,
) -> CustomResult<services::ApplicationResponse<MigrateCardResponse>, errors::ApiErrorResponse> {
let db = state.store.as_ref();
@@ -75,7 +75,7 @@ pub async fn rust_locker_migration(
}
pub async fn call_to_locker(
- state: &AppState,
+ state: &SessionState,
payment_methods: Vec<PaymentMethod>,
customer_id: &id_type::CustomerId,
merchant_id: &str,
@@ -140,6 +140,7 @@ pub async fn call_to_locker(
merchant_account,
api_enums::LockerChoice::HyperswitchCardVault,
Some(pm.locker_id.as_ref().unwrap_or(&pm.payment_method_id)),
+
)
.await
.change_context(errors::ApiErrorResponse::InternalServerError)
diff --git a/crates/router/src/core/mandate.rs b/crates/router/src/core/mandate.rs
index 839f55dea2..f484467f35 100644
--- a/crates/router/src/core/mandate.rs
+++ b/crates/router/src/core/mandate.rs
@@ -14,7 +14,7 @@ use crate::{
payments::CallConnectorAction,
},
db::StorageInterface,
- routes::{metrics, AppState},
+ routes::{metrics, SessionState},
services,
types::{
self,
@@ -32,7 +32,7 @@ use crate::{
#[instrument(skip(state))]
pub async fn get_mandate(
- state: AppState,
+ state: SessionState,
merchant_account: domain::MerchantAccount,
key_store: domain::MerchantKeyStore,
req: mandates::MandateId,
@@ -60,7 +60,7 @@ pub async fn get_mandate(
#[instrument(skip(state))]
pub async fn revoke_mandate(
- state: AppState,
+ state: SessionState,
merchant_account: domain::MerchantAccount,
key_store: domain::MerchantKeyStore,
req: mandates::MandateId,
@@ -223,7 +223,7 @@ pub async fn update_connector_mandate_id(
#[instrument(skip(state))]
pub async fn get_customer_mandates(
- state: AppState,
+ state: SessionState,
merchant_account: domain::MerchantAccount,
key_store: domain::MerchantKeyStore,
req: customers::CustomerId,
@@ -271,7 +271,7 @@ where
}
}
pub async fn update_mandate_procedure<F, FData>(
- state: &AppState,
+ state: &SessionState,
resp: types::RouterData<F, FData, types::PaymentsResponseData>,
mandate: Mandate,
merchant_id: &str,
@@ -342,7 +342,7 @@ where
}
pub async fn mandate_procedure<F, FData>(
- state: &AppState,
+ state: &SessionState,
resp: &types::RouterData<F, FData, types::PaymentsResponseData>,
customer_id: &Option<id_type::CustomerId>,
pm_id: Option<String>,
@@ -472,7 +472,7 @@ where
#[instrument(skip(state))]
pub async fn retrieve_mandates_list(
- state: AppState,
+ state: SessionState,
merchant_account: domain::MerchantAccount,
key_store: domain::MerchantKeyStore,
constraints: api_models::mandates::MandateListConstraints,
diff --git a/crates/router/src/core/mandate/helpers.rs b/crates/router/src/core/mandate/helpers.rs
index 4e9d07b7f8..b0c727925d 100644
--- a/crates/router/src/core/mandate/helpers.rs
+++ b/crates/router/src/core/mandate/helpers.rs
@@ -7,12 +7,12 @@ use hyperswitch_domain_models::mandates::MandateData;
use crate::{
core::{errors, payments},
- routes::AppState,
+ routes::SessionState,
types::{api, domain},
};
pub async fn get_profile_id_for_mandate(
- state: &AppState,
+ state: &SessionState,
merchant_account: &domain::MerchantAccount,
mandate: Mandate,
) -> CustomResult<String, errors::ApiErrorResponse> {
diff --git a/crates/router/src/core/payment_link.rs b/crates/router/src/core/payment_link.rs
index 9b8fd3cbe0..e4ef38ae35 100644
--- a/crates/router/src/core/payment_link.rs
+++ b/crates/router/src/core/payment_link.rs
@@ -14,7 +14,7 @@ use time::PrimitiveDateTime;
use super::errors::{self, RouterResult, StorageErrorExt};
use crate::{
errors::RouterResponse,
- routes::AppState,
+ routes::SessionState,
services,
types::{
api::payment_link::PaymentLinkResponseExt, domain, storage::enums as storage_enums,
@@ -23,7 +23,7 @@ use crate::{
};
pub async fn retrieve_payment_link(
- state: AppState,
+ state: SessionState,
payment_link_id: String,
) -> RouterResponse<api_models::payments::RetrievePaymentLinkResponse> {
let db = &*state.store;
@@ -47,7 +47,7 @@ pub async fn retrieve_payment_link(
}
pub async fn initiate_payment_link_flow(
- state: AppState,
+ state: SessionState,
merchant_account: domain::MerchantAccount,
merchant_id: String,
payment_id: String,
@@ -287,7 +287,7 @@ fn validate_sdk_requirements(
}
pub async fn list_payment_link(
- state: AppState,
+ state: SessionState,
merchant: domain::MerchantAccount,
constraints: api_models::payments::PaymentLinkListConstraints,
) -> RouterResponse<Vec<api_models::payments::RetrievePaymentLinkResponse>> {
@@ -501,7 +501,7 @@ fn check_payment_link_invalid_conditions(
}
pub async fn get_payment_link_status(
- state: AppState,
+ state: SessionState,
merchant_account: domain::MerchantAccount,
merchant_id: String,
payment_id: String,
diff --git a/crates/router/src/core/payment_methods.rs b/crates/router/src/core/payment_methods.rs
index 71f0bdac03..b6d95248ab 100644
--- a/crates/router/src/core/payment_methods.rs
+++ b/crates/router/src/core/payment_methods.rs
@@ -13,7 +13,7 @@ use router_env::{instrument, tracing};
use crate::{
core::{errors::RouterResult, payments::helpers, pm_auth as core_pm_auth},
- routes::AppState,
+ routes::SessionState,
types::{
api::{self, payments},
domain, storage,
@@ -23,7 +23,7 @@ use crate::{
#[instrument(skip_all)]
pub async fn retrieve_payment_method(
pm_data: &Option<payments::PaymentMethodData>,
- state: &AppState,
+ state: &SessionState,
payment_intent: &PaymentIntent,
payment_attempt: &PaymentAttempt,
merchant_key_store: &domain::MerchantKeyStore,
@@ -95,7 +95,7 @@ pub async fn retrieve_payment_method(
#[instrument(skip_all)]
pub async fn retrieve_payment_method_with_token(
- state: &AppState,
+ state: &SessionState,
merchant_key_store: &domain::MerchantKeyStore,
token_data: &storage::PaymentTokenData,
payment_intent: &PaymentIntent,
diff --git a/crates/router/src/core/payment_methods/cards.rs b/crates/router/src/core/payment_methods/cards.rs
index 66a695b2b0..c62f47b536 100644
--- a/crates/router/src/core/payment_methods/cards.rs
+++ b/crates/router/src/core/payment_methods/cards.rs
@@ -263,7 +263,7 @@ pub async fn get_or_insert_payment_method(
#[instrument(skip_all)]
pub async fn get_client_secret_or_add_payment_method(
- state: routes::AppState,
+ state: routes::SessionState,
req: api::PaymentMethodCreate,
merchant_account: &domain::MerchantAccount,
key_store: &domain::MerchantKeyStore,
@@ -337,7 +337,7 @@ pub fn authenticate_pm_client_secret_and_check_expiry(
#[instrument(skip_all)]
pub async fn add_payment_method_data(
- state: routes::AppState,
+ state: routes::SessionState,
req: api::PaymentMethodCreate,
merchant_account: domain::MerchantAccount,
key_store: domain::MerchantKeyStore,
@@ -513,7 +513,7 @@ pub async fn add_payment_method_data(
#[instrument(skip_all)]
pub async fn add_payment_method(
- state: routes::AppState,
+ state: routes::SessionState,
req: api::PaymentMethodCreate,
merchant_account: &domain::MerchantAccount,
key_store: &domain::MerchantKeyStore,
@@ -761,7 +761,7 @@ pub async fn insert_payment_method(
#[instrument(skip_all)]
pub async fn update_customer_payment_method(
- state: routes::AppState,
+ state: routes::SessionState,
merchant_account: domain::MerchantAccount,
req: api::PaymentMethodUpdate,
payment_method_id: &str,
@@ -1017,7 +1017,7 @@ pub fn validate_payment_method_update(
#[cfg(feature = "payouts")]
pub async fn add_bank_to_locker(
- state: &routes::AppState,
+ state: &routes::SessionState,
req: api::PaymentMethodCreate,
merchant_account: &domain::MerchantAccount,
key_store: &domain::MerchantKeyStore,
@@ -1082,7 +1082,7 @@ pub async fn add_bank_to_locker(
/// The response will be the tuple of PaymentMethodResponse and the duplication check of payment_method
pub async fn add_card_to_locker(
- state: &routes::AppState,
+ state: &routes::SessionState,
req: api::PaymentMethodCreate,
card: &api::CardDetail,
customer_id: &id_type::CustomerId,
@@ -1130,7 +1130,7 @@ pub async fn add_card_to_locker(
}
pub async fn get_card_from_locker(
- state: &routes::AppState,
+ state: &routes::SessionState,
customer_id: &id_type::CustomerId,
merchant_id: &str,
card_reference: &str,
@@ -1171,7 +1171,7 @@ pub async fn get_card_from_locker(
}
pub async fn delete_card_from_locker(
- state: &routes::AppState,
+ state: &routes::SessionState,
customer_id: &id_type::CustomerId,
merchant_id: &str,
card_reference: &str,
@@ -1195,7 +1195,7 @@ pub async fn delete_card_from_locker(
#[instrument(skip_all)]
pub async fn add_card_hs(
- state: &routes::AppState,
+ state: &routes::SessionState,
req: api::PaymentMethodCreate,
card: &api::CardDetail,
customer_id: &id_type::CustomerId,
@@ -1259,7 +1259,7 @@ pub async fn decode_and_decrypt_locker_data(
#[instrument(skip_all)]
pub async fn get_payment_method_from_hs_locker<'a>(
- state: &'a routes::AppState,
+ state: &'a routes::SessionState,
key_store: &domain::MerchantKeyStore,
customer_id: &id_type::CustomerId,
merchant_id: &str,
@@ -1321,7 +1321,7 @@ pub async fn get_payment_method_from_hs_locker<'a>(
#[instrument(skip_all)]
pub async fn call_to_locker_hs<'a>(
- state: &routes::AppState,
+ state: &routes::SessionState,
payload: &payment_methods::StoreLockerReq<'a>,
customer_id: &id_type::CustomerId,
locker_choice: api_enums::LockerChoice,
@@ -1394,7 +1394,7 @@ pub async fn update_payment_method_connector_mandate_details(
}
#[instrument(skip_all)]
pub async fn get_card_from_hs_locker<'a>(
- state: &'a routes::AppState,
+ state: &'a routes::SessionState,
customer_id: &id_type::CustomerId,
merchant_id: &str,
card_reference: &'a str,
@@ -1447,7 +1447,7 @@ pub async fn get_card_from_hs_locker<'a>(
#[instrument(skip_all)]
pub async fn delete_card_from_hs_locker<'a>(
- state: &routes::AppState,
+ state: &routes::SessionState,
customer_id: &id_type::CustomerId,
merchant_id: &str,
card_reference: &'a str,
@@ -1652,7 +1652,7 @@ pub async fn mock_delete_card<'a>(
}
//------------------------------------------------------------------------------
pub fn get_banks(
- state: &routes::AppState,
+ state: &routes::SessionState,
pm_type: common_enums::enums::PaymentMethodType,
connectors: Vec<String>,
) -> Result<Vec<BankCodeResponse>, errors::ApiErrorResponse> {
@@ -1734,7 +1734,7 @@ fn get_val(str: String, val: &serde_json::Value) -> Option<String> {
}
pub async fn list_payment_methods(
- state: routes::AppState,
+ state: routes::SessionState,
merchant_account: domain::MerchantAccount,
key_store: domain::MerchantKeyStore,
mut req: api::PaymentMethodListRequest,
@@ -2660,7 +2660,7 @@ async fn validate_payment_method_and_client_secret(
}
pub async fn call_surcharge_decision_management(
- state: routes::AppState,
+ state: routes::SessionState,
merchant_account: &domain::MerchantAccount,
business_profile: &BusinessProfile,
payment_attempt: &storage::PaymentAttempt,
@@ -2710,7 +2710,7 @@ pub async fn call_surcharge_decision_management(
}
pub async fn call_surcharge_decision_management_for_saved_card(
- state: &routes::AppState,
+ state: &routes::SessionState,
merchant_account: &domain::MerchantAccount,
business_profile: &BusinessProfile,
payment_attempt: &storage::PaymentAttempt,
@@ -3313,7 +3313,7 @@ async fn filter_payment_mandate_based(
}
pub async fn do_list_customer_pm_fetch_customer_if_not_passed(
- state: routes::AppState,
+ state: routes::SessionState,
merchant_account: domain::MerchantAccount,
key_store: domain::MerchantKeyStore,
req: Option<api::PaymentMethodListRequest>,
@@ -3369,7 +3369,7 @@ pub async fn do_list_customer_pm_fetch_customer_if_not_passed(
}
pub async fn list_customer_payment_method(
- state: &routes::AppState,
+ state: &routes::SessionState,
merchant_account: domain::MerchantAccount,
key_store: domain::MerchantKeyStore,
payment_intent: Option<storage::PaymentIntent>,
@@ -3684,7 +3684,7 @@ pub async fn list_customer_payment_method(
Ok(services::ApplicationResponse::Json(response))
}
pub async fn get_mca_status(
- state: &routes::AppState,
+ state: &routes::SessionState,
key_store: &domain::MerchantKeyStore,
merchant_id: &str,
connector_mandate_details: Option<storage::PaymentsMandateReference>,
@@ -3744,7 +3744,7 @@ where
pub async fn get_card_details_with_locker_fallback(
pm: &payment_method::PaymentMethod,
key: &[u8],
- state: &routes::AppState,
+ state: &routes::SessionState,
) -> errors::RouterResult<Option<api::CardDetailFromLocker>> {
let card_decrypted =
decrypt::<serde_json::Value, masking::WithType>(pm.payment_method_data.clone(), key)
@@ -3775,7 +3775,7 @@ pub async fn get_card_details_with_locker_fallback(
pub async fn get_card_details_without_locker_fallback(
pm: &payment_method::PaymentMethod,
key: &[u8],
- state: &routes::AppState,
+ state: &routes::SessionState,
) -> errors::RouterResult<api::CardDetailFromLocker> {
let card_decrypted =
decrypt::<serde_json::Value, masking::WithType>(pm.payment_method_data.clone(), key)
@@ -3800,7 +3800,7 @@ pub async fn get_card_details_without_locker_fallback(
}
pub async fn get_card_details_from_locker(
- state: &routes::AppState,
+ state: &routes::SessionState,
pm: &storage::PaymentMethod,
) -> errors::RouterResult<api::CardDetailFromLocker> {
let card = get_card_from_locker(
@@ -3819,7 +3819,7 @@ pub async fn get_card_details_from_locker(
}
pub async fn get_lookup_key_from_locker(
- state: &routes::AppState,
+ state: &routes::SessionState,
payment_token: &str,
pm: &storage::PaymentMethod,
merchant_key_store: &domain::MerchantKeyStore,
@@ -4004,7 +4004,7 @@ pub async fn set_default_payment_method(
pub async fn update_last_used_at(
pm_id: &str,
- state: &routes::AppState,
+ state: &routes::SessionState,
storage_scheme: MerchantStorageScheme,
) -> errors::RouterResult<()> {
let update_last_used = storage::PaymentMethodUpdate::LastUsedUpdate {
@@ -4026,7 +4026,7 @@ pub async fn update_last_used_at(
}
#[cfg(feature = "payouts")]
pub async fn get_bank_from_hs_locker(
- state: &routes::AppState,
+ state: &routes::SessionState,
key_store: &domain::MerchantKeyStore,
temp_token: &str,
customer_id: &id_type::CustomerId,
@@ -4079,7 +4079,7 @@ pub struct TempLockerCardSupport;
impl TempLockerCardSupport {
#[instrument(skip_all)]
async fn create_payment_method_data_in_temp_locker(
- state: &routes::AppState,
+ state: &routes::SessionState,
payment_token: &str,
card: api::CardDetailFromLocker,
pm: &storage::PaymentMethod,
@@ -4161,7 +4161,7 @@ impl TempLockerCardSupport {
#[instrument(skip_all)]
pub async fn retrieve_payment_method(
- state: routes::AppState,
+ state: routes::SessionState,
pm: api::PaymentMethodId,
key_store: domain::MerchantKeyStore,
merchant_account: domain::MerchantAccount,
@@ -4217,7 +4217,7 @@ pub async fn retrieve_payment_method(
#[instrument(skip_all)]
pub async fn delete_payment_method(
- state: routes::AppState,
+ state: routes::SessionState,
merchant_account: domain::MerchantAccount,
pm_id: api::PaymentMethodId,
key_store: domain::MerchantKeyStore,
@@ -4342,7 +4342,7 @@ where
}
pub async fn list_countries_currencies_for_connector_payment_method(
- state: routes::AppState,
+ state: routes::SessionState,
req: ListCountriesCurrenciesRequest,
) -> errors::RouterResponse<ListCountriesCurrenciesResponse> {
Ok(services::ApplicationResponse::Json(
diff --git a/crates/router/src/core/payment_methods/surcharge_decision_configs.rs b/crates/router/src/core/payment_methods/surcharge_decision_configs.rs
index 76881950e3..14beb6be13 100644
--- a/crates/router/src/core/payment_methods/surcharge_decision_configs.rs
+++ b/crates/router/src/core/payment_methods/surcharge_decision_configs.rs
@@ -26,7 +26,7 @@ use crate::{
storage::{self, payment_attempt::PaymentAttemptExt},
transformers::ForeignTryFrom,
},
- AppState,
+ SessionState,
};
static CONF_CACHE: StaticCache<VirInterpreterBackendCacheWrapper> = StaticCache::new();
@@ -95,7 +95,7 @@ impl SurchargeSource {
}
pub async fn perform_surcharge_decision_management_for_payment_method_list(
- state: &AppState,
+ state: &SessionState,
algorithm_ref: routing::RoutingAlgorithmRef,
payment_attempt: &storage::PaymentAttempt,
payment_intent: &storage::PaymentIntent,
@@ -215,7 +215,7 @@ pub async fn perform_surcharge_decision_management_for_payment_method_list(
}
pub async fn perform_surcharge_decision_management_for_session_flow<O>(
- state: &AppState,
+ state: &SessionState,
algorithm_ref: routing::RoutingAlgorithmRef,
payment_data: &mut PaymentData<O>,
payment_method_type_list: &Vec<common_enums::PaymentMethodType>,
@@ -276,7 +276,7 @@ where
Ok(surcharge_metadata)
}
pub async fn perform_surcharge_decision_management_for_saved_cards(
- state: &AppState,
+ state: &SessionState,
algorithm_ref: routing::RoutingAlgorithmRef,
payment_attempt: &storage::PaymentAttempt,
payment_intent: &storage::PaymentIntent,
diff --git a/crates/router/src/core/payment_methods/vault.rs b/crates/router/src/core/payment_methods/vault.rs
index e0d8bada65..9e20017d57 100644
--- a/crates/router/src/core/payment_methods/vault.rs
+++ b/crates/router/src/core/payment_methods/vault.rs
@@ -818,7 +818,7 @@ pub struct Vault;
impl Vault {
#[instrument(skip_all)]
pub async fn get_payment_method_data_from_locker(
- state: &routes::AppState,
+ state: &routes::SessionState,
lookup_key: &str,
merchant_key_store: &domain::MerchantKeyStore,
) -> RouterResult<(Option<api::PaymentMethodData>, SupplementaryVaultData)> {
@@ -834,7 +834,7 @@ impl Vault {
#[instrument(skip_all)]
pub async fn store_payment_method_data_in_locker(
- state: &routes::AppState,
+ state: &routes::SessionState,
token_id: Option<String>,
payment_method: &api::PaymentMethodData,
customer_id: Option<id_type::CustomerId>,
@@ -869,7 +869,7 @@ impl Vault {
#[cfg(feature = "payouts")]
#[instrument(skip_all)]
pub async fn get_payout_method_data_from_temporary_locker(
- state: &routes::AppState,
+ state: &routes::SessionState,
lookup_key: &str,
merchant_key_store: &domain::MerchantKeyStore,
) -> RouterResult<(Option<api::PayoutMethodData>, SupplementaryVaultData)> {
@@ -886,7 +886,7 @@ impl Vault {
#[cfg(feature = "payouts")]
#[instrument(skip_all)]
pub async fn store_payout_method_data_in_locker(
- state: &routes::AppState,
+ state: &routes::SessionState,
token_id: Option<String>,
payout_method: &api::PayoutMethodData,
customer_id: Option<id_type::CustomerId>,
@@ -920,7 +920,7 @@ impl Vault {
#[instrument(skip_all)]
pub async fn delete_locker_payment_method_by_lookup_key(
- state: &routes::AppState,
+ state: &routes::SessionState,
lookup_key: &Option<String>,
) {
if let Some(lookup_key) = lookup_key {
@@ -942,7 +942,7 @@ fn get_redis_locker_key(lookup_key: &str) -> String {
#[instrument(skip(state, value1, value2))]
pub async fn create_tokenize(
- state: &routes::AppState,
+ state: &routes::SessionState,
value1: String,
value2: Option<String>,
lookup_key: String,
@@ -1007,7 +1007,7 @@ pub async fn create_tokenize(
#[instrument(skip(state))]
pub async fn get_tokenized_data(
- state: &routes::AppState,
+ state: &routes::SessionState,
lookup_key: &str,
_should_get_value2: bool,
encryption_key: &masking::Secret<Vec<u8>>,
@@ -1069,7 +1069,10 @@ pub async fn get_tokenized_data(
}
#[instrument(skip(state))]
-pub async fn delete_tokenized_data(state: &routes::AppState, lookup_key: &str) -> RouterResult<()> {
+pub async fn delete_tokenized_data(
+ state: &routes::SessionState,
+ lookup_key: &str,
+) -> RouterResult<()> {
let redis_key = get_redis_locker_key(lookup_key);
let func = || async {
metrics::DELETED_TOKENIZED_CARD.add(&metrics::CONTEXT, 1, &[]);
@@ -1153,7 +1156,7 @@ pub async fn add_delete_tokenized_data_task(
}
pub async fn start_tokenize_data_workflow(
- state: &routes::AppState,
+ state: &routes::SessionState,
tokenize_tracker: &storage::ProcessTracker,
) -> Result<(), errors::ProcessTrackerError> {
let db = &*state.store;
diff --git a/crates/router/src/core/payments.rs b/crates/router/src/core/payments.rs
index 3988f3d4fd..caaecdc862 100644
--- a/crates/router/src/core/payments.rs
+++ b/crates/router/src/core/payments.rs
@@ -77,7 +77,7 @@ use crate::{
},
db::StorageInterface,
logger,
- routes::{app::ReqState, metrics, payment_methods::ParentPaymentMethodToken, AppState},
+ routes::{app::ReqState, metrics, payment_methods::ParentPaymentMethodToken, SessionState},
services::{self, api::Authenticate},
types::{
self as router_types,
@@ -97,7 +97,7 @@ use crate::{
#[allow(clippy::too_many_arguments, clippy::type_complexity)]
#[instrument(skip_all, fields(payment_id, merchant_id))]
pub async fn payments_operation_core<F, Req, Op, FData>(
- state: &AppState,
+ state: &SessionState,
req_state: ReqState,
merchant_account: domain::MerchantAccount,
key_store: domain::MerchantKeyStore,
@@ -571,7 +571,7 @@ where
#[instrument(skip_all)]
pub async fn call_decision_manager<O>(
- state: &AppState,
+ state: &SessionState,
merchant_account: &domain::MerchantAccount,
payment_data: &mut PaymentData<O>,
) -> RouterResult<()>
@@ -606,7 +606,7 @@ where
#[instrument(skip_all)]
async fn populate_surcharge_details<F>(
- state: &AppState,
+ state: &SessionState,
payment_data: &mut PaymentData<F>,
) -> RouterResult<()>
where
@@ -686,7 +686,7 @@ pub fn get_connector_data(
#[instrument(skip_all)]
pub async fn call_surcharge_decision_management_for_session_flow<O>(
- state: &AppState,
+ state: &SessionState,
merchant_account: &domain::MerchantAccount,
payment_data: &mut PaymentData<O>,
session_connector_data: &[api::SessionConnectorData],
@@ -741,7 +741,7 @@ where
}
#[allow(clippy::too_many_arguments)]
pub async fn payments_core<F, Res, Req, Op, FData>(
- state: AppState,
+ state: SessionState,
req_state: ReqState,
merchant_account: domain::MerchantAccount,
key_store: domain::MerchantKeyStore,
@@ -794,7 +794,7 @@ where
payment_data,
customer,
auth_flow,
- &state.conf.server,
+ &state.base_url,
operation,
&state.conf.connector_request_reference_id_config,
connector_http_status_code,
@@ -826,7 +826,7 @@ pub trait PaymentRedirectFlow: Sync {
#[allow(clippy::too_many_arguments)]
async fn call_payment_flow(
&self,
- state: &AppState,
+ state: &SessionState,
req_state: ReqState,
merchant_account: domain::MerchantAccount,
merchant_key_store: domain::MerchantKeyStore,
@@ -848,7 +848,7 @@ pub trait PaymentRedirectFlow: Sync {
#[allow(clippy::too_many_arguments)]
async fn handle_payments_redirect_response(
&self,
- state: AppState,
+ state: SessionState,
req_state: ReqState,
merchant_account: domain::MerchantAccount,
key_store: domain::MerchantKeyStore,
@@ -923,7 +923,7 @@ impl PaymentRedirectFlow for PaymentRedirectCompleteAuthorize {
#[allow(clippy::too_many_arguments)]
async fn call_payment_flow(
&self,
- state: &AppState,
+ state: &SessionState,
req_state: ReqState,
merchant_account: domain::MerchantAccount,
merchant_key_store: domain::MerchantKeyStore,
@@ -1055,7 +1055,7 @@ impl PaymentRedirectFlow for PaymentRedirectSync {
#[allow(clippy::too_many_arguments)]
async fn call_payment_flow(
&self,
- state: &AppState,
+ state: &SessionState,
req_state: ReqState,
merchant_account: domain::MerchantAccount,
merchant_key_store: domain::MerchantKeyStore,
@@ -1146,7 +1146,7 @@ impl PaymentRedirectFlow for PaymentAuthenticateCompleteAuthorize {
#[allow(clippy::too_many_arguments)]
async fn call_payment_flow(
&self,
- state: &AppState,
+ state: &SessionState,
req_state: ReqState,
merchant_account: domain::MerchantAccount,
merchant_key_store: domain::MerchantKeyStore,
@@ -1378,7 +1378,7 @@ impl PaymentRedirectFlow for PaymentAuthenticateCompleteAuthorize {
#[allow(clippy::too_many_arguments)]
#[instrument(skip_all)]
pub async fn call_connector_service<F, RouterDReq, ApiRequest>(
- state: &AppState,
+ state: &SessionState,
req_state: ReqState,
merchant_account: &domain::MerchantAccount,
key_store: &domain::MerchantKeyStore,
@@ -1613,7 +1613,7 @@ where
}
async fn blocklist_guard<F, ApiRequest>(
- state: &AppState,
+ state: &SessionState,
merchant_account: &domain::MerchantAccount,
operation: &BoxedOperation<'_, F, ApiRequest>,
payment_data: &mut PaymentData<F>,
@@ -1652,7 +1652,7 @@ where
#[allow(clippy::too_many_arguments)]
pub async fn call_multiple_connectors_service<F, Op, Req>(
- state: &AppState,
+ state: &SessionState,
merchant_account: &domain::MerchantAccount,
key_store: &domain::MerchantKeyStore,
connectors: Vec<api::SessionConnectorData>,
@@ -1769,7 +1769,7 @@ where
}
pub async fn call_create_connector_customer_if_required<F, Req>(
- state: &AppState,
+ state: &SessionState,
customer: &Option<domain::Customer>,
merchant_account: &domain::MerchantAccount,
key_store: &domain::MerchantKeyStore,
@@ -1871,7 +1871,7 @@ where
}
async fn complete_preprocessing_steps_if_required<F, Req, Q>(
- state: &AppState,
+ state: &SessionState,
connector: &api::ConnectorData,
payment_data: &PaymentData<F>,
mut router_data: RouterData<F, Req, router_types::PaymentsResponseData>,
@@ -2011,7 +2011,7 @@ pub fn is_preprocessing_required_for_wallets(connector_name: String) -> bool {
#[instrument(skip_all)]
pub async fn construct_profile_id_and_get_mca<'a, F>(
- state: &'a AppState,
+ state: &'a SessionState,
merchant_account: &domain::MerchantAccount,
payment_data: &mut PaymentData<F>,
connector_name: &str,
@@ -2049,7 +2049,7 @@ where
}
fn is_payment_method_tokenization_enabled_for_connector(
- state: &AppState,
+ state: &SessionState,
connector_name: &str,
payment_method: &storage::enums::PaymentMethod,
payment_method_type: &Option<storage::enums::PaymentMethodType>,
@@ -2168,7 +2168,7 @@ fn is_payment_method_type_allowed_for_connector(
}
async fn decide_payment_method_tokenize_action(
- state: &AppState,
+ state: &SessionState,
connector_name: &str,
payment_method: &storage::enums::PaymentMethod,
pm_parent_token: Option<&String>,
@@ -2241,7 +2241,7 @@ pub enum TokenizationAction {
#[allow(clippy::too_many_arguments)]
pub async fn get_connector_tokenization_action_when_confirm_true<F, Req>(
- state: &AppState,
+ state: &SessionState,
operation: &BoxedOperation<'_, F, Req>,
payment_data: &mut PaymentData<F>,
validate_result: &operations::ValidateResult<'_>,
@@ -2365,7 +2365,7 @@ where
}
pub async fn tokenize_in_router_when_confirm_false_or_external_authentication<F, Req>(
- state: &AppState,
+ state: &SessionState,
operation: &BoxedOperation<'_, F, Req>,
payment_data: &mut PaymentData<F>,
validate_result: &operations::ValidateResult<'_>,
@@ -2616,7 +2616,7 @@ pub fn is_operation_complete_authorize<Op: Debug>(operation: &Op) -> bool {
#[cfg(feature = "olap")]
pub async fn list_payments(
- state: AppState,
+ state: SessionState,
merchant: domain::MerchantAccount,
constraints: api::PaymentListConstraints,
) -> RouterResponse<api::PaymentListResponse> {
@@ -2682,7 +2682,7 @@ pub async fn list_payments(
}
#[cfg(feature = "olap")]
pub async fn apply_filters_on_payments(
- state: AppState,
+ state: SessionState,
merchant: domain::MerchantAccount,
constraints: api::PaymentListFilterConstraints,
) -> RouterResponse<api::PaymentListResponseV2> {
@@ -2735,7 +2735,7 @@ pub async fn apply_filters_on_payments(
#[cfg(feature = "olap")]
pub async fn get_filters_for_payments(
- state: AppState,
+ state: SessionState,
merchant: domain::MerchantAccount,
time_range: api::TimeRange,
) -> RouterResponse<api::PaymentListFilters> {
@@ -2773,7 +2773,7 @@ pub async fn get_filters_for_payments(
#[cfg(feature = "olap")]
pub async fn get_payment_filters(
- state: AppState,
+ state: SessionState,
merchant: domain::MerchantAccount,
) -> RouterResponse<api::PaymentListFiltersV2> {
let merchant_connector_accounts = if let services::ApplicationResponse::Json(data) =
@@ -2931,7 +2931,7 @@ where
#[allow(clippy::too_many_arguments)]
pub async fn get_connector_choice<F, Req>(
operation: &BoxedOperation<'_, F, Req>,
- state: &AppState,
+ state: &SessionState,
req: &Req,
merchant_account: &domain::MerchantAccount,
business_profile: &storage::business_profile::BusinessProfile,
@@ -3010,7 +3010,7 @@ where
#[allow(clippy::too_many_arguments)]
pub async fn connector_selection<F>(
- state: &AppState,
+ state: &SessionState,
merchant_account: &domain::MerchantAccount,
business_profile: &storage::business_profile::BusinessProfile,
key_store: &domain::MerchantKeyStore,
@@ -3085,7 +3085,7 @@ where
#[allow(clippy::too_many_arguments)]
pub async fn decide_connector<F>(
- state: AppState,
+ state: SessionState,
merchant_account: &domain::MerchantAccount,
business_profile: &storage::business_profile::BusinessProfile,
key_store: &domain::MerchantKeyStore,
@@ -3332,7 +3332,7 @@ where
}
pub async fn decide_multiplex_connector_for_normal_or_recurring_payment<F: Clone>(
- state: &AppState,
+ state: &SessionState,
payment_data: &mut PaymentData<F>,
routing_data: &mut storage::RoutingData,
connectors: Vec<api::ConnectorData>,
@@ -3511,7 +3511,7 @@ pub async fn decide_multiplex_connector_for_normal_or_recurring_payment<F: Clone
}
pub fn is_network_transaction_id_flow(
- state: &AppState,
+ state: &SessionState,
is_connector_agnostic_mit_enabled: Option<bool>,
connector: enums::Connector,
payment_method_info: &storage::PaymentMethod,
@@ -3540,7 +3540,7 @@ pub fn should_add_task_to_process_tracker<F: Clone>(payment_data: &PaymentData<F
}
pub async fn perform_session_token_routing<F>(
- state: AppState,
+ state: SessionState,
merchant_account: &domain::MerchantAccount,
key_store: &domain::MerchantKeyStore,
payment_data: &mut PaymentData<F>,
@@ -3652,7 +3652,7 @@ where
#[allow(clippy::too_many_arguments)]
pub async fn route_connector_v1<F>(
- state: &AppState,
+ state: &SessionState,
merchant_account: &domain::MerchantAccount,
business_profile: &storage::business_profile::BusinessProfile,
key_store: &domain::MerchantKeyStore,
@@ -3775,7 +3775,7 @@ where
#[instrument(skip_all)]
pub async fn payment_external_authentication(
- state: AppState,
+ state: SessionState,
merchant_account: domain::MerchantAccount,
key_store: domain::MerchantKeyStore,
req: api_models::payments::PaymentsExternalAuthenticationRequest,
@@ -3908,15 +3908,12 @@ pub async fn payment_external_authentication(
.ok_or(errors::ApiErrorResponse::InternalServerError)
.attach_printable("missing connector in payment_attempt")?;
let return_url = Some(helpers::create_authorize_url(
- &state.conf.server.base_url,
+ &state.base_url,
&payment_attempt.clone(),
payment_connector_name,
));
- let webhook_url = helpers::create_webhook_url(
- &state.conf.server.base_url,
- merchant_id,
- &authentication_connector,
- );
+ let webhook_url =
+ helpers::create_webhook_url(&state.base_url, merchant_id, &authentication_connector);
let business_profile = state
.store
@@ -3987,7 +3984,7 @@ pub async fn payment_external_authentication(
#[instrument(skip_all)]
pub async fn get_extended_card_info(
- state: AppState,
+ state: SessionState,
merchant_id: String,
payment_id: String,
) -> RouterResponse<payments_api::ExtendedCardInfoResponse> {
diff --git a/crates/router/src/core/payments/access_token.rs b/crates/router/src/core/payments/access_token.rs
index 0c5aa13eb2..4241db6742 100644
--- a/crates/router/src/core/payments/access_token.rs
+++ b/crates/router/src/core/payments/access_token.rs
@@ -9,7 +9,7 @@ use crate::{
errors::{self, RouterResult},
payments,
},
- routes::{metrics, AppState},
+ routes::{metrics, SessionState},
services::{self, logger},
types::{self, api as api_types, domain},
};
@@ -53,7 +53,7 @@ pub async fn add_access_token<
Req: Debug + Clone + 'static,
Res: Debug + Clone + 'static,
>(
- state: &AppState,
+ state: &SessionState,
connector: &api_types::ConnectorData,
merchant_account: &domain::MerchantAccount,
router_data: &types::RouterData<F, Req, Res>,
@@ -194,7 +194,7 @@ pub async fn add_access_token<
}
pub async fn refresh_connector_auth(
- state: &AppState,
+ state: &SessionState,
connector: &api_types::ConnectorData,
_merchant_account: &domain::MerchantAccount,
router_data: &types::RouterData<
diff --git a/crates/router/src/core/payments/conditional_configs.rs b/crates/router/src/core/payments/conditional_configs.rs
index 5dc78d42e5..c73fa3659b 100644
--- a/crates/router/src/core/payments/conditional_configs.rs
+++ b/crates/router/src/core/payments/conditional_configs.rs
@@ -21,7 +21,7 @@ pub type ConditionalConfigResult<O> = errors::CustomResult<O, ConfigError>;
#[instrument(skip_all)]
pub async fn perform_decision_management<F: Clone>(
- state: &routes::AppState,
+ state: &routes::SessionState,
algorithm_ref: routing::RoutingAlgorithmRef,
merchant_id: &str,
payment_data: &mut payments::PaymentData<F>,
@@ -51,7 +51,7 @@ pub async fn perform_decision_management<F: Clone>(
#[instrument(skip_all)]
pub async fn ensure_algorithm_cached(
- state: &routes::AppState,
+ state: &routes::SessionState,
merchant_id: &str,
timestamp: i64,
algorithm_id: &str,
@@ -73,7 +73,7 @@ pub async fn ensure_algorithm_cached(
#[instrument(skip_all)]
pub async fn refresh_routing_cache(
- state: &routes::AppState,
+ state: &routes::SessionState,
key: String,
algorithm_id: &str,
timestamp: i64,
diff --git a/crates/router/src/core/payments/customers.rs b/crates/router/src/core/payments/customers.rs
index ff56eaf46e..448e5fedb8 100644
--- a/crates/router/src/core/payments/customers.rs
+++ b/crates/router/src/core/payments/customers.rs
@@ -6,14 +6,14 @@ use crate::{
payments,
},
logger,
- routes::{metrics, AppState},
+ routes::{metrics, SessionState},
services,
types::{self, api, domain, storage},
};
#[instrument(skip_all)]
pub async fn create_connector_customer<F: Clone, T: Clone>(
- state: &AppState,
+ state: &SessionState,
connector: &api::ConnectorData,
router_data: &types::RouterData<F, T, types::PaymentsResponseData>,
customer_request_data: types::ConnectorCustomerData,
@@ -88,7 +88,7 @@ pub fn get_connector_customer_details_if_present<'a>(
}
pub fn should_call_connector_create_customer<'a>(
- state: &AppState,
+ state: &SessionState,
connector: &api::ConnectorData,
customer: &'a Option<domain::Customer>,
connector_label: &str,
diff --git a/crates/router/src/core/payments/flows.rs b/crates/router/src/core/payments/flows.rs
index 158e28e696..674fa45392 100644
--- a/crates/router/src/core/payments/flows.rs
+++ b/crates/router/src/core/payments/flows.rs
@@ -19,7 +19,7 @@ use crate::{
errors::{ConnectorError, CustomResult, RouterResult},
payments::{self, helpers},
},
- routes::AppState,
+ routes::SessionState,
services,
types::{self, api, domain, storage},
};
@@ -28,7 +28,7 @@ use crate::{
pub trait ConstructFlowSpecificData<F, Req, Res> {
async fn construct_router_data<'a>(
&self,
- state: &AppState,
+ state: &SessionState,
connector_id: &str,
merchant_account: &domain::MerchantAccount,
key_store: &domain::MerchantKeyStore,
@@ -42,7 +42,7 @@ pub trait ConstructFlowSpecificData<F, Req, Res> {
pub trait Feature<F, T> {
async fn decide_flows<'a>(
self,
- state: &AppState,
+ state: &SessionState,
connector: &api::ConnectorData,
call_connector_action: payments::CallConnectorAction,
connector_request: Option<services::Request>,
@@ -55,7 +55,7 @@ pub trait Feature<F, T> {
async fn add_access_token<'a>(
&self,
- state: &AppState,
+ state: &SessionState,
connector: &api::ConnectorData,
merchant_account: &domain::MerchantAccount,
) -> RouterResult<types::AddAccessTokenResult>
@@ -66,7 +66,7 @@ pub trait Feature<F, T> {
async fn add_payment_method_token<'a>(
&mut self,
- _state: &AppState,
+ _state: &SessionState,
_connector: &api::ConnectorData,
_tokenization_action: &payments::TokenizationAction,
) -> RouterResult<Option<String>>
@@ -80,7 +80,7 @@ pub trait Feature<F, T> {
async fn preprocessing_steps<'a>(
self,
- _state: &AppState,
+ _state: &SessionState,
_connector: &api::ConnectorData,
) -> RouterResult<Self>
where
@@ -93,7 +93,7 @@ pub trait Feature<F, T> {
async fn create_connector_customer<'a>(
&self,
- _state: &AppState,
+ _state: &SessionState,
_connector: &api::ConnectorData,
) -> RouterResult<Option<String>>
where
@@ -107,7 +107,7 @@ pub trait Feature<F, T> {
/// Returns the connector request and a bool which specifies whether to proceed with further
async fn build_flow_specific_connector_request(
&mut self,
- _state: &AppState,
+ _state: &SessionState,
_connector: &api::ConnectorData,
_call_connector_action: payments::CallConnectorAction,
) -> RouterResult<(Option<services::Request>, bool)> {
diff --git a/crates/router/src/core/payments/flows/approve_flow.rs b/crates/router/src/core/payments/flows/approve_flow.rs
index 95ca0c3e31..6d4a88c0bf 100644
--- a/crates/router/src/core/payments/flows/approve_flow.rs
+++ b/crates/router/src/core/payments/flows/approve_flow.rs
@@ -6,7 +6,7 @@ use crate::{
errors::{ApiErrorResponse, NotImplementedMessage, RouterResult},
payments::{self, access_token, helpers, transformers, PaymentData},
},
- routes::AppState,
+ routes::SessionState,
services,
types::{self, api, domain, storage},
};
@@ -18,7 +18,7 @@ impl
{
async fn construct_router_data<'a>(
&self,
- state: &AppState,
+ state: &SessionState,
connector_id: &str,
merchant_account: &domain::MerchantAccount,
key_store: &domain::MerchantKeyStore,
@@ -47,7 +47,7 @@ impl Feature<api::Approve, types::PaymentsApproveData>
{
async fn decide_flows<'a>(
self,
- _state: &AppState,
+ _state: &SessionState,
_connector: &api::ConnectorData,
_call_connector_action: payments::CallConnectorAction,
_connector_request: Option<services::Request>,
@@ -61,7 +61,7 @@ impl Feature<api::Approve, types::PaymentsApproveData>
async fn add_access_token<'a>(
&self,
- state: &AppState,
+ state: &SessionState,
connector: &api::ConnectorData,
merchant_account: &domain::MerchantAccount,
) -> RouterResult<types::AddAccessTokenResult> {
@@ -70,7 +70,7 @@ impl Feature<api::Approve, types::PaymentsApproveData>
async fn build_flow_specific_connector_request(
&mut self,
- _state: &AppState,
+ _state: &SessionState,
_connector: &api::ConnectorData,
_call_connector_action: payments::CallConnectorAction,
) -> RouterResult<(Option<services::Request>, bool)> {
diff --git a/crates/router/src/core/payments/flows/authorize_flow.rs b/crates/router/src/core/payments/flows/authorize_flow.rs
index 5990b29f37..d672da9991 100644
--- a/crates/router/src/core/payments/flows/authorize_flow.rs
+++ b/crates/router/src/core/payments/flows/authorize_flow.rs
@@ -11,7 +11,7 @@ use crate::{
},
},
logger,
- routes::{metrics, AppState},
+ routes::{metrics, SessionState},
services,
types::{self, api, domain, storage},
};
@@ -26,7 +26,7 @@ impl
{
async fn construct_router_data<'a>(
&self,
- state: &AppState,
+ state: &SessionState,
connector_id: &str,
merchant_account: &domain::MerchantAccount,
key_store: &domain::MerchantKeyStore,
@@ -58,7 +58,7 @@ impl
impl Feature<api::Authorize, types::PaymentsAuthorizeData> for types::PaymentsAuthorizeRouterData {
async fn decide_flows<'a>(
mut self,
- state: &AppState,
+ state: &SessionState,
connector: &api::ConnectorData,
call_connector_action: payments::CallConnectorAction,
connector_request: Option<services::Request>,
@@ -93,7 +93,7 @@ impl Feature<api::Authorize, types::PaymentsAuthorizeData> for types::PaymentsAu
async fn add_access_token<'a>(
&self,
- state: &AppState,
+ state: &SessionState,
connector: &api::ConnectorData,
merchant_account: &domain::MerchantAccount,
) -> RouterResult<types::AddAccessTokenResult> {
@@ -102,7 +102,7 @@ impl Feature<api::Authorize, types::PaymentsAuthorizeData> for types::PaymentsAu
async fn add_payment_method_token<'a>(
&mut self,
- state: &AppState,
+ state: &SessionState,
connector: &api::ConnectorData,
tokenization_action: &payments::TokenizationAction,
) -> RouterResult<Option<String>> {
@@ -119,7 +119,7 @@ impl Feature<api::Authorize, types::PaymentsAuthorizeData> for types::PaymentsAu
async fn preprocessing_steps<'a>(
self,
- state: &AppState,
+ state: &SessionState,
connector: &api::ConnectorData,
) -> RouterResult<Self> {
authorize_preprocessing_steps(state, &self, true, connector).await
@@ -127,7 +127,7 @@ impl Feature<api::Authorize, types::PaymentsAuthorizeData> for types::PaymentsAu
async fn create_connector_customer<'a>(
&self,
- state: &AppState,
+ state: &SessionState,
connector: &api::ConnectorData,
) -> RouterResult<Option<String>> {
customers::create_connector_customer(
@@ -141,7 +141,7 @@ impl Feature<api::Authorize, types::PaymentsAuthorizeData> for types::PaymentsAu
async fn build_flow_specific_connector_request(
&mut self,
- state: &AppState,
+ state: &SessionState,
connector: &api::ConnectorData,
call_connector_action: payments::CallConnectorAction,
) -> RouterResult<(Option<services::Request>, bool)> {
@@ -266,7 +266,7 @@ impl mandate::MandateBehaviour for types::PaymentsAuthorizeData {
}
pub async fn authorize_preprocessing_steps<F: Clone>(
- state: &AppState,
+ state: &SessionState,
router_data: &types::RouterData<F, types::PaymentsAuthorizeData, types::PaymentsResponseData>,
confirm: bool,
connector: &api::ConnectorData,
diff --git a/crates/router/src/core/payments/flows/cancel_flow.rs b/crates/router/src/core/payments/flows/cancel_flow.rs
index 0e90ab40b6..d7e8cc3d9b 100644
--- a/crates/router/src/core/payments/flows/cancel_flow.rs
+++ b/crates/router/src/core/payments/flows/cancel_flow.rs
@@ -6,7 +6,7 @@ use crate::{
errors::{ConnectorErrorExt, RouterResult},
payments::{self, access_token, helpers, transformers, PaymentData},
},
- routes::{metrics, AppState},
+ routes::{metrics, SessionState},
services,
types::{self, api, domain, storage},
};
@@ -17,7 +17,7 @@ impl ConstructFlowSpecificData<api::Void, types::PaymentsCancelData, types::Paym
{
async fn construct_router_data<'a>(
&self,
- state: &AppState,
+ state: &SessionState,
connector_id: &str,
merchant_account: &domain::MerchantAccount,
key_store: &domain::MerchantKeyStore,
@@ -46,7 +46,7 @@ impl Feature<api::Void, types::PaymentsCancelData>
{
async fn decide_flows<'a>(
self,
- state: &AppState,
+ state: &SessionState,
connector: &api::ConnectorData,
call_connector_action: payments::CallConnectorAction,
connector_request: Option<services::Request>,
@@ -83,7 +83,7 @@ impl Feature<api::Void, types::PaymentsCancelData>
async fn add_access_token<'a>(
&self,
- state: &AppState,
+ state: &SessionState,
connector: &api::ConnectorData,
merchant_account: &domain::MerchantAccount,
) -> RouterResult<types::AddAccessTokenResult> {
@@ -92,7 +92,7 @@ impl Feature<api::Void, types::PaymentsCancelData>
async fn build_flow_specific_connector_request(
&mut self,
- state: &AppState,
+ state: &SessionState,
connector: &api::ConnectorData,
call_connector_action: payments::CallConnectorAction,
) -> RouterResult<(Option<services::Request>, bool)> {
diff --git a/crates/router/src/core/payments/flows/capture_flow.rs b/crates/router/src/core/payments/flows/capture_flow.rs
index b979eb2a33..268281e515 100644
--- a/crates/router/src/core/payments/flows/capture_flow.rs
+++ b/crates/router/src/core/payments/flows/capture_flow.rs
@@ -6,7 +6,7 @@ use crate::{
errors::{ConnectorErrorExt, RouterResult},
payments::{self, access_token, helpers, transformers, Feature, PaymentData},
},
- routes::AppState,
+ routes::SessionState,
services,
types::{self, api, domain, storage},
};
@@ -18,7 +18,7 @@ impl
{
async fn construct_router_data<'a>(
&self,
- state: &AppState,
+ state: &SessionState,
connector_id: &str,
merchant_account: &domain::MerchantAccount,
key_store: &domain::MerchantKeyStore,
@@ -47,7 +47,7 @@ impl Feature<api::Capture, types::PaymentsCaptureData>
{
async fn decide_flows<'a>(
self,
- state: &AppState,
+ state: &SessionState,
connector: &api::ConnectorData,
call_connector_action: payments::CallConnectorAction,
connector_request: Option<services::Request>,
@@ -75,7 +75,7 @@ impl Feature<api::Capture, types::PaymentsCaptureData>
async fn add_access_token<'a>(
&self,
- state: &AppState,
+ state: &SessionState,
connector: &api::ConnectorData,
merchant_account: &domain::MerchantAccount,
) -> RouterResult<types::AddAccessTokenResult> {
@@ -84,7 +84,7 @@ impl Feature<api::Capture, types::PaymentsCaptureData>
async fn build_flow_specific_connector_request(
&mut self,
- state: &AppState,
+ state: &SessionState,
connector: &api::ConnectorData,
call_connector_action: payments::CallConnectorAction,
) -> RouterResult<(Option<services::Request>, bool)> {
diff --git a/crates/router/src/core/payments/flows/complete_authorize_flow.rs b/crates/router/src/core/payments/flows/complete_authorize_flow.rs
index c14cf6c808..5d0cb9f9f3 100644
--- a/crates/router/src/core/payments/flows/complete_authorize_flow.rs
+++ b/crates/router/src/core/payments/flows/complete_authorize_flow.rs
@@ -6,7 +6,7 @@ use crate::{
errors::{ConnectorErrorExt, RouterResult},
payments::{self, access_token, helpers, transformers, PaymentData},
},
- routes::{metrics, AppState},
+ routes::{metrics, SessionState},
services,
types::{self, api, domain, storage},
};
@@ -21,7 +21,7 @@ impl
{
async fn construct_router_data<'a>(
&self,
- state: &AppState,
+ state: &SessionState,
connector_id: &str,
merchant_account: &domain::MerchantAccount,
key_store: &domain::MerchantKeyStore,
@@ -60,7 +60,7 @@ impl Feature<api::CompleteAuthorize, types::CompleteAuthorizeData>
{
async fn decide_flows<'a>(
mut self,
- state: &AppState,
+ state: &SessionState,
connector: &api::ConnectorData,
call_connector_action: payments::CallConnectorAction,
connector_request: Option<services::Request>,
@@ -88,7 +88,7 @@ impl Feature<api::CompleteAuthorize, types::CompleteAuthorizeData>
async fn add_access_token<'a>(
&self,
- state: &AppState,
+ state: &SessionState,
connector: &api::ConnectorData,
merchant_account: &domain::MerchantAccount,
) -> RouterResult<types::AddAccessTokenResult> {
@@ -97,7 +97,7 @@ impl Feature<api::CompleteAuthorize, types::CompleteAuthorizeData>
async fn add_payment_method_token<'a>(
&mut self,
- state: &AppState,
+ state: &SessionState,
connector: &api::ConnectorData,
_tokenization_action: &payments::TokenizationAction,
) -> RouterResult<Option<String>> {
@@ -119,7 +119,7 @@ impl Feature<api::CompleteAuthorize, types::CompleteAuthorizeData>
async fn build_flow_specific_connector_request(
&mut self,
- state: &AppState,
+ state: &SessionState,
connector: &api::ConnectorData,
call_connector_action: payments::CallConnectorAction,
) -> RouterResult<(Option<services::Request>, bool)> {
@@ -144,7 +144,7 @@ impl Feature<api::CompleteAuthorize, types::CompleteAuthorizeData>
async fn preprocessing_steps<'a>(
self,
- state: &AppState,
+ state: &SessionState,
connector: &api::ConnectorData,
) -> RouterResult<Self> {
complete_authorize_preprocessing_steps(state, &self, true, connector).await
@@ -152,7 +152,7 @@ impl Feature<api::CompleteAuthorize, types::CompleteAuthorizeData>
}
pub async fn complete_authorize_preprocessing_steps<F: Clone>(
- state: &AppState,
+ state: &SessionState,
router_data: &types::RouterData<F, types::CompleteAuthorizeData, types::PaymentsResponseData>,
confirm: bool,
connector: &api::ConnectorData,
diff --git a/crates/router/src/core/payments/flows/incremental_authorization_flow.rs b/crates/router/src/core/payments/flows/incremental_authorization_flow.rs
index 716228d73f..58e5db8fbd 100644
--- a/crates/router/src/core/payments/flows/incremental_authorization_flow.rs
+++ b/crates/router/src/core/payments/flows/incremental_authorization_flow.rs
@@ -6,7 +6,7 @@ use crate::{
errors::{ConnectorErrorExt, RouterResult},
payments::{self, access_token, helpers, transformers, Feature, PaymentData},
},
- routes::AppState,
+ routes::SessionState,
services,
types::{self, api, domain, storage},
};
@@ -21,7 +21,7 @@ impl
{
async fn construct_router_data<'a>(
&self,
- state: &AppState,
+ state: &SessionState,
connector_id: &str,
merchant_account: &domain::MerchantAccount,
key_store: &domain::MerchantKeyStore,
@@ -54,7 +54,7 @@ impl Feature<api::IncrementalAuthorization, types::PaymentsIncrementalAuthorizat
{
async fn decide_flows<'a>(
self,
- state: &AppState,
+ state: &SessionState,
connector: &api::ConnectorData,
call_connector_action: payments::CallConnectorAction,
connector_request: Option<services::Request>,
@@ -82,7 +82,7 @@ impl Feature<api::IncrementalAuthorization, types::PaymentsIncrementalAuthorizat
async fn add_access_token<'a>(
&self,
- state: &AppState,
+ state: &SessionState,
connector: &api::ConnectorData,
merchant_account: &domain::MerchantAccount,
) -> RouterResult<types::AddAccessTokenResult> {
@@ -91,7 +91,7 @@ impl Feature<api::IncrementalAuthorization, types::PaymentsIncrementalAuthorizat
async fn build_flow_specific_connector_request(
&mut self,
- state: &AppState,
+ state: &SessionState,
connector: &api::ConnectorData,
call_connector_action: payments::CallConnectorAction,
) -> RouterResult<(Option<services::Request>, bool)> {
diff --git a/crates/router/src/core/payments/flows/psync_flow.rs b/crates/router/src/core/payments/flows/psync_flow.rs
index 51627e2d68..bec29f97e9 100644
--- a/crates/router/src/core/payments/flows/psync_flow.rs
+++ b/crates/router/src/core/payments/flows/psync_flow.rs
@@ -8,7 +8,7 @@ use crate::{
errors::{ApiErrorResponse, ConnectorErrorExt, RouterResult},
payments::{self, access_token, helpers, transformers, PaymentData},
},
- routes::AppState,
+ routes::SessionState,
services::{self, logger},
types::{self, api, domain, storage},
};
@@ -19,7 +19,7 @@ impl ConstructFlowSpecificData<api::PSync, types::PaymentsSyncData, types::Payme
{
async fn construct_router_data<'a>(
&self,
- state: &AppState,
+ state: &SessionState,
connector_id: &str,
merchant_account: &domain::MerchantAccount,
key_store: &domain::MerchantKeyStore,
@@ -50,7 +50,7 @@ impl Feature<api::PSync, types::PaymentsSyncData>
{
async fn decide_flows<'a>(
mut self,
- state: &AppState,
+ state: &SessionState,
connector: &api::ConnectorData,
call_connector_action: payments::CallConnectorAction,
connector_request: Option<services::Request>,
@@ -101,7 +101,7 @@ impl Feature<api::PSync, types::PaymentsSyncData>
async fn add_access_token<'a>(
&self,
- state: &AppState,
+ state: &SessionState,
connector: &api::ConnectorData,
merchant_account: &domain::MerchantAccount,
) -> RouterResult<types::AddAccessTokenResult> {
@@ -110,7 +110,7 @@ impl Feature<api::PSync, types::PaymentsSyncData>
async fn build_flow_specific_connector_request(
&mut self,
- state: &AppState,
+ state: &SessionState,
connector: &api::ConnectorData,
call_connector_action: payments::CallConnectorAction,
) -> RouterResult<(Option<services::Request>, bool)> {
@@ -152,7 +152,7 @@ where
{
async fn execute_connector_processing_step_for_each_capture(
&self,
- _state: &AppState,
+ _state: &SessionState,
_pending_connector_capture_id_list: Vec<String>,
_call_connector_action: payments::CallConnectorAction,
_connector_integration: services::BoxedConnectorIntegration<
@@ -170,7 +170,7 @@ impl RouterDataPSync
{
async fn execute_connector_processing_step_for_each_capture(
&self,
- state: &AppState,
+ state: &SessionState,
pending_connector_capture_id_list: Vec<String>,
call_connector_action: payments::CallConnectorAction,
connector_integration: services::BoxedConnectorIntegration<
diff --git a/crates/router/src/core/payments/flows/reject_flow.rs b/crates/router/src/core/payments/flows/reject_flow.rs
index 638efa054e..865c6ea201 100644
--- a/crates/router/src/core/payments/flows/reject_flow.rs
+++ b/crates/router/src/core/payments/flows/reject_flow.rs
@@ -6,7 +6,7 @@ use crate::{
errors::{ApiErrorResponse, NotImplementedMessage, RouterResult},
payments::{self, access_token, helpers, transformers, PaymentData},
},
- routes::AppState,
+ routes::SessionState,
services,
types::{self, api, domain, storage},
};
@@ -17,7 +17,7 @@ impl ConstructFlowSpecificData<api::Reject, types::PaymentsRejectData, types::Pa
{
async fn construct_router_data<'a>(
&self,
- state: &AppState,
+ state: &SessionState,
connector_id: &str,
merchant_account: &domain::MerchantAccount,
key_store: &domain::MerchantKeyStore,
@@ -46,7 +46,7 @@ impl Feature<api::Reject, types::PaymentsRejectData>
{
async fn decide_flows<'a>(
self,
- _state: &AppState,
+ _state: &SessionState,
_connector: &api::ConnectorData,
_call_connector_action: payments::CallConnectorAction,
_connector_request: Option<services::Request>,
@@ -60,7 +60,7 @@ impl Feature<api::Reject, types::PaymentsRejectData>
async fn add_access_token<'a>(
&self,
- state: &AppState,
+ state: &SessionState,
connector: &api::ConnectorData,
merchant_account: &domain::MerchantAccount,
) -> RouterResult<types::AddAccessTokenResult> {
@@ -69,7 +69,7 @@ impl Feature<api::Reject, types::PaymentsRejectData>
async fn build_flow_specific_connector_request(
&mut self,
- _state: &AppState,
+ _state: &SessionState,
_connector: &api::ConnectorData,
_call_connector_action: payments::CallConnectorAction,
) -> RouterResult<(Option<services::Request>, bool)> {
diff --git a/crates/router/src/core/payments/flows/session_flow.rs b/crates/router/src/core/payments/flows/session_flow.rs
index c74ed4bae1..76441f4075 100644
--- a/crates/router/src/core/payments/flows/session_flow.rs
+++ b/crates/router/src/core/payments/flows/session_flow.rs
@@ -28,7 +28,7 @@ impl
{
async fn construct_router_data<'a>(
&self,
- state: &routes::AppState,
+ state: &routes::SessionState,
connector_id: &str,
merchant_account: &domain::MerchantAccount,
key_store: &domain::MerchantKeyStore,
@@ -55,7 +55,7 @@ impl
impl Feature<api::Session, types::PaymentsSessionData> for types::PaymentsSessionRouterData {
async fn decide_flows<'a>(
self,
- state: &routes::AppState,
+ state: &routes::SessionState,
connector: &api::ConnectorData,
call_connector_action: payments::CallConnectorAction,
_connector_request: Option<services::Request>,
@@ -81,7 +81,7 @@ impl Feature<api::Session, types::PaymentsSessionData> for types::PaymentsSessio
async fn add_access_token<'a>(
&self,
- state: &routes::AppState,
+ state: &routes::SessionState,
connector: &api::ConnectorData,
merchant_account: &domain::MerchantAccount,
) -> RouterResult<types::AddAccessTokenResult> {
@@ -123,7 +123,7 @@ fn is_dynamic_fields_required(
}
fn build_apple_pay_session_request(
- state: &routes::AppState,
+ state: &routes::SessionState,
request: payment_types::ApplepaySessionRequest,
apple_pay_merchant_cert: masking::Secret<String>,
apple_pay_merchant_cert_key: masking::Secret<String>,
@@ -147,7 +147,7 @@ fn build_apple_pay_session_request(
}
async fn create_applepay_session_token(
- state: &routes::AppState,
+ state: &routes::SessionState,
router_data: &types::PaymentsSessionRouterData,
connector: &api::ConnectorData,
business_profile: &storage::business_profile::BusinessProfile,
@@ -467,7 +467,7 @@ fn create_apple_pay_session_response(
}
fn create_gpay_session_token(
- state: &routes::AppState,
+ state: &routes::SessionState,
router_data: &types::PaymentsSessionRouterData,
connector: &api::ConnectorData,
business_profile: &storage::business_profile::BusinessProfile,
@@ -598,7 +598,10 @@ fn create_gpay_session_token(
}
}
-fn is_session_response_delayed(state: &routes::AppState, connector: &api::ConnectorData) -> bool {
+fn is_session_response_delayed(
+ state: &routes::SessionState,
+ connector: &api::ConnectorData,
+) -> bool {
let connectors_with_delayed_response = &state
.conf
.delayed_session_response
@@ -626,7 +629,7 @@ where
{
async fn decide_flow<'a, 'b>(
&'b self,
- state: &'a routes::AppState,
+ state: &'a routes::SessionState,
connector: &api::ConnectorData,
_confirm: Option<bool>,
call_connector_action: payments::CallConnectorAction,
@@ -635,7 +638,7 @@ where
}
fn create_paypal_sdk_session_token(
- _state: &routes::AppState,
+ _state: &routes::SessionState,
router_data: &types::PaymentsSessionRouterData,
connector: &api::ConnectorData,
_business_profile: &storage::business_profile::BusinessProfile,
@@ -674,7 +677,7 @@ fn create_paypal_sdk_session_token(
impl RouterDataSession for types::PaymentsSessionRouterData {
async fn decide_flow<'a, 'b>(
&'b self,
- state: &'a routes::AppState,
+ state: &'a routes::SessionState,
connector: &api::ConnectorData,
_confirm: Option<bool>,
call_connector_action: payments::CallConnectorAction,
diff --git a/crates/router/src/core/payments/flows/setup_mandate_flow.rs b/crates/router/src/core/payments/flows/setup_mandate_flow.rs
index b0fa39d525..987d3f3380 100644
--- a/crates/router/src/core/payments/flows/setup_mandate_flow.rs
+++ b/crates/router/src/core/payments/flows/setup_mandate_flow.rs
@@ -9,7 +9,7 @@ use crate::{
self, access_token, customers, helpers, tokenization, transformers, PaymentData,
},
},
- routes::AppState,
+ routes::SessionState,
services,
types::{self, api, domain, storage},
};
@@ -24,7 +24,7 @@ impl
{
async fn construct_router_data<'a>(
&self,
- state: &AppState,
+ state: &SessionState,
connector_id: &str,
merchant_account: &domain::MerchantAccount,
key_store: &domain::MerchantKeyStore,
@@ -51,7 +51,7 @@ impl
impl Feature<api::SetupMandate, types::SetupMandateRequestData> for types::SetupMandateRouterData {
async fn decide_flows<'a>(
self,
- state: &AppState,
+ state: &SessionState,
connector: &api::ConnectorData,
call_connector_action: payments::CallConnectorAction,
connector_request: Option<services::Request>,
@@ -78,7 +78,7 @@ impl Feature<api::SetupMandate, types::SetupMandateRequestData> for types::Setup
async fn add_access_token<'a>(
&self,
- state: &AppState,
+ state: &SessionState,
connector: &api::ConnectorData,
merchant_account: &domain::MerchantAccount,
) -> RouterResult<types::AddAccessTokenResult> {
@@ -87,7 +87,7 @@ impl Feature<api::SetupMandate, types::SetupMandateRequestData> for types::Setup
async fn add_payment_method_token<'a>(
&mut self,
- state: &AppState,
+ state: &SessionState,
connector: &api::ConnectorData,
tokenization_action: &payments::TokenizationAction,
) -> RouterResult<Option<String>> {
@@ -104,7 +104,7 @@ impl Feature<api::SetupMandate, types::SetupMandateRequestData> for types::Setup
async fn create_connector_customer<'a>(
&self,
- state: &AppState,
+ state: &SessionState,
connector: &api::ConnectorData,
) -> RouterResult<Option<String>> {
customers::create_connector_customer(
@@ -118,7 +118,7 @@ impl Feature<api::SetupMandate, types::SetupMandateRequestData> for types::Setup
async fn build_flow_specific_connector_request(
&mut self,
- state: &AppState,
+ state: &SessionState,
connector: &api::ConnectorData,
call_connector_action: payments::CallConnectorAction,
) -> RouterResult<(Option<services::Request>, bool)> {
diff --git a/crates/router/src/core/payments/helpers.rs b/crates/router/src/core/payments/helpers.rs
index 8f7ed4da25..a58a6ae32b 100644
--- a/crates/router/src/core/payments/helpers.rs
+++ b/crates/router/src/core/payments/helpers.rs
@@ -34,7 +34,7 @@ use super::{
CustomerDetails, PaymentData,
};
use crate::{
- configs::settings::{ConnectorRequestReferenceIdConfig, Server, TempLockerEnableConfig},
+ configs::settings::{ConnectorRequestReferenceIdConfig, TempLockerEnableConfig},
connector,
consts::{self, BASE64_ENGINE},
core::{
@@ -46,7 +46,7 @@ use crate::{
pm_auth::retrieve_payment_method_from_auth_service,
},
db::StorageInterface,
- routes::{metrics, payment_methods as payment_methods_handler, AppState},
+ routes::{metrics, payment_methods as payment_methods_handler, SessionState},
services,
types::{
api::{self, admin, enums as api_enums, MandateValidationFieldsExt},
@@ -427,7 +427,7 @@ pub async fn get_address_by_id(
}
pub async fn get_token_pm_type_mandate_details(
- state: &AppState,
+ state: &SessionState,
request: &api::PaymentsRequest,
mandate_type: Option<api::MandateTransactionType>,
merchant_account: &domain::MerchantAccount,
@@ -579,7 +579,7 @@ pub async fn get_token_pm_type_mandate_details(
}
pub async fn get_token_for_recurring_mandate(
- state: &AppState,
+ state: &SessionState,
req: &api::PaymentsRequest,
merchant_account: &domain::MerchantAccount,
merchant_key_store: &domain::MerchantKeyStore,
@@ -1023,16 +1023,13 @@ pub fn validate_customer_id_mandatory_cases(
}
pub fn create_startpay_url(
- server: &Server,
+ base_url: &str,
payment_attempt: &PaymentAttempt,
payment_intent: &PaymentIntent,
) -> String {
format!(
"{}/payments/redirect/{}/{}/{}",
- server.base_url,
- payment_intent.payment_id,
- payment_intent.merchant_id,
- payment_attempt.attempt_id
+ base_url, payment_intent.payment_id, payment_intent.merchant_id, payment_attempt.attempt_id
)
}
@@ -1050,7 +1047,7 @@ pub fn create_redirect_url(
}
pub fn create_authentication_url(
- router_base_url: &String,
+ router_base_url: &str,
payment_attempt: &PaymentAttempt,
) -> String {
format!(
@@ -1060,7 +1057,7 @@ pub fn create_authentication_url(
}
pub fn create_authorize_url(
- router_base_url: &String,
+ router_base_url: &str,
payment_attempt: &PaymentAttempt,
connector_name: &String,
) -> String {
@@ -1205,7 +1202,7 @@ pub fn payment_intent_status_fsm(
}
pub async fn add_domain_task_to_pt<Op>(
operation: &Op,
- state: &AppState,
+ state: &SessionState,
payment_attempt: &PaymentAttempt,
requeue: bool,
schedule_time: Option<time::PrimitiveDateTime>,
@@ -1494,7 +1491,7 @@ pub fn get_customer_details_from_request(
}
pub async fn get_connector_default(
- _state: &AppState,
+ _state: &SessionState,
request_connector: Option<serde_json::Value>,
) -> CustomResult<api::ConnectorChoice, errors::ApiErrorResponse> {
Ok(request_connector.map_or(
@@ -1676,7 +1673,7 @@ pub async fn create_customer_if_not_exist<'a, F: Clone, R>(
}
pub async fn retrieve_payment_method_with_temporary_token(
- state: &AppState,
+ state: &SessionState,
token: &str,
payment_intent: &PaymentIntent,
merchant_key_store: &domain::MerchantKeyStore,
@@ -1773,7 +1770,7 @@ pub async fn retrieve_payment_method_with_temporary_token(
}
pub async fn retrieve_card_with_permanent_token(
- state: &AppState,
+ state: &SessionState,
locker_id: &str,
payment_method_id: &str,
payment_intent: &PaymentIntent,
@@ -1838,7 +1835,7 @@ pub async fn retrieve_card_with_permanent_token(
}
pub async fn retrieve_payment_method_from_db_with_token_data(
- state: &AppState,
+ state: &SessionState,
token_data: &storage::PaymentTokenData,
storage_scheme: storage::enums::MerchantStorageScheme,
) -> RouterResult<Option<storage::PaymentMethod>> {
@@ -1873,7 +1870,7 @@ pub async fn retrieve_payment_method_from_db_with_token_data(
}
pub async fn retrieve_payment_token_data(
- state: &AppState,
+ state: &SessionState,
token: String,
payment_method: Option<storage_enums::PaymentMethod>,
) -> RouterResult<storage::PaymentTokenData> {
@@ -1924,7 +1921,7 @@ pub async fn retrieve_payment_token_data(
pub async fn make_pm_data<'a, F: Clone, R>(
operation: BoxedOperation<'a, F, R>,
- state: &'a AppState,
+ state: &'a SessionState,
payment_data: &mut PaymentData<F>,
merchant_key_store: &domain::MerchantKeyStore,
customer: &Option<domain::Customer>,
@@ -2021,7 +2018,7 @@ pub async fn make_pm_data<'a, F: Clone, R>(
}
pub async fn store_in_vault_and_generate_ppmt(
- state: &AppState,
+ state: &SessionState,
payment_method_data: &api_models::payments::PaymentMethodData,
payment_intent: &PaymentIntent,
payment_attempt: &PaymentAttempt,
@@ -2057,7 +2054,7 @@ pub async fn store_in_vault_and_generate_ppmt(
}
pub async fn store_payment_method_data_in_vault(
- state: &AppState,
+ state: &SessionState,
payment_attempt: &PaymentAttempt,
payment_intent: &PaymentIntent,
payment_method: enums::PaymentMethod,
@@ -2541,7 +2538,7 @@ pub fn make_merchant_url_with_response(
}
pub async fn make_ephemeral_key(
- state: AppState,
+ state: SessionState,
customer_id: id_type::CustomerId,
merchant_id: String,
) -> errors::RouterResponse<ephemeral_key::EphemeralKey> {
@@ -2563,7 +2560,7 @@ pub async fn make_ephemeral_key(
}
pub async fn delete_ephemeral_key(
- state: AppState,
+ state: SessionState,
ek_id: String,
) -> errors::RouterResponse<ephemeral_key::EphemeralKey> {
let db = state.store.as_ref();
@@ -3207,7 +3204,7 @@ impl MerchantConnectorAccountType {
/// If profile_id is passed use it, or use connector_label to query merchant connector account
#[instrument(skip_all)]
pub async fn get_merchant_connector_account(
- state: &AppState,
+ state: &SessionState,
merchant_id: &str,
creds_identifier: Option<String>,
key_store: &domain::MerchantKeyStore,
@@ -3962,7 +3959,7 @@ pub fn get_applepay_metadata(
}
pub async fn get_apple_pay_retryable_connectors<F>(
- state: AppState,
+ state: SessionState,
merchant_account: &domain::MerchantAccount,
payment_data: &mut PaymentData<F>,
key_store: &domain::MerchantKeyStore,
@@ -4067,7 +4064,7 @@ impl ApplePayData {
pub async fn decrypt(
&self,
- state: &AppState,
+ state: &SessionState,
) -> CustomResult<serde_json::Value, errors::ApplePayDecryptionError> {
let merchant_id = self.merchant_id(state).await?;
let shared_secret = self.shared_secret(state).await?;
@@ -4080,7 +4077,7 @@ impl ApplePayData {
pub async fn merchant_id(
&self,
- state: &AppState,
+ state: &SessionState,
) -> CustomResult<String, errors::ApplePayDecryptionError> {
let cert_data = state
.conf
@@ -4125,7 +4122,7 @@ impl ApplePayData {
pub async fn shared_secret(
&self,
- state: &AppState,
+ state: &SessionState,
) -> CustomResult<Vec<u8>, errors::ApplePayDecryptionError> {
let public_ec_bytes = BASE64_ENGINE
.decode(self.header.ephemeral_public_key.peek().as_bytes())
@@ -4301,7 +4298,7 @@ pub fn validate_payment_link_request(
}
pub async fn get_gsm_record(
- state: &AppState,
+ state: &SessionState,
error_code: Option<String>,
error_message: Option<String>,
connector_name: String,
@@ -4438,7 +4435,7 @@ pub fn update_additional_payment_data_with_connector_response_pm_data(
}
pub async fn get_payment_method_details_from_payment_token(
- state: &AppState,
+ state: &SessionState,
payment_attempt: &PaymentAttempt,
payment_intent: &PaymentIntent,
key_store: &domain::MerchantKeyStore,
@@ -4589,7 +4586,7 @@ pub enum PaymentExternalAuthenticationFlow {
}
pub async fn get_payment_external_authentication_flow_during_confirm<F: Clone>(
- state: &AppState,
+ state: &SessionState,
key_store: &domain::MerchantKeyStore,
business_profile: &storage::BusinessProfile,
payment_data: &mut PaymentData<F>,
diff --git a/crates/router/src/core/payments/operations.rs b/crates/router/src/core/payments/operations.rs
index 35fc2897ea..45e45bbe9c 100644
--- a/crates/router/src/core/payments/operations.rs
+++ b/crates/router/src/core/payments/operations.rs
@@ -29,7 +29,7 @@ use super::{helpers, CustomerDetails, PaymentData};
use crate::{
core::errors::{self, CustomResult, RouterResult},
db::StorageInterface,
- routes::{app::ReqState, AppState},
+ routes::{app::ReqState, SessionState},
services,
types::{
self,
@@ -102,7 +102,7 @@ pub trait GetTracker<F: Clone, D, R>: Send {
#[allow(clippy::too_many_arguments)]
async fn get_trackers<'a>(
&'a self,
- state: &'a AppState,
+ state: &'a SessionState,
payment_id: &api::PaymentIdType,
request: &R,
merchant_account: &domain::MerchantAccount,
@@ -127,7 +127,7 @@ pub trait Domain<F: Clone, R>: Send + Sync {
#[allow(clippy::too_many_arguments)]
async fn make_pm_data<'a>(
&'a self,
- state: &'a AppState,
+ state: &'a SessionState,
payment_data: &mut PaymentData<F>,
storage_scheme: enums::MerchantStorageScheme,
merchant_key_store: &domain::MerchantKeyStore,
@@ -140,7 +140,7 @@ pub trait Domain<F: Clone, R>: Send + Sync {
async fn add_task_to_process_tracker<'a>(
&'a self,
- _db: &'a AppState,
+ _db: &'a SessionState,
_payment_attempt: &storage::PaymentAttempt,
_requeue: bool,
_schedule_time: Option<time::PrimitiveDateTime>,
@@ -151,7 +151,7 @@ pub trait Domain<F: Clone, R>: Send + Sync {
async fn get_connector<'a>(
&'a self,
merchant_account: &domain::MerchantAccount,
- state: &AppState,
+ state: &SessionState,
request: &R,
payment_intent: &storage::PaymentIntent,
mechant_key_store: &domain::MerchantKeyStore,
@@ -159,7 +159,7 @@ pub trait Domain<F: Clone, R>: Send + Sync {
async fn populate_payment_data<'a>(
&'a self,
- _state: &AppState,
+ _state: &SessionState,
_payment_data: &mut PaymentData<F>,
_merchant_account: &domain::MerchantAccount,
) -> CustomResult<(), errors::ApiErrorResponse> {
@@ -168,7 +168,7 @@ pub trait Domain<F: Clone, R>: Send + Sync {
async fn call_external_three_ds_authentication_if_eligible<'a>(
&'a self,
- _state: &AppState,
+ _state: &SessionState,
_payment_data: &mut PaymentData<F>,
_should_continue_confirm_transaction: &mut bool,
_connector_call_type: &ConnectorCallType,
@@ -181,7 +181,7 @@ pub trait Domain<F: Clone, R>: Send + Sync {
#[instrument(skip_all)]
async fn guard_payment_against_blocklist<'a>(
&'a self,
- _state: &AppState,
+ _state: &SessionState,
_merchant_account: &domain::MerchantAccount,
_payment_data: &mut PaymentData<F>,
) -> CustomResult<bool, errors::ApiErrorResponse> {
@@ -190,7 +190,7 @@ pub trait Domain<F: Clone, R>: Send + Sync {
async fn store_extended_card_info_temporarily<'a>(
&'a self,
- _state: &AppState,
+ _state: &SessionState,
_payment_id: &str,
_business_profile: &storage::BusinessProfile,
_payment_method_data: &Option<api::PaymentMethodData>,
@@ -204,7 +204,7 @@ pub trait Domain<F: Clone, R>: Send + Sync {
pub trait UpdateTracker<F, D, Req>: Send {
async fn update_trackers<'b>(
&'b self,
- db: &'b AppState,
+ db: &'b SessionState,
req_state: ReqState,
payment_data: D,
customer: Option<domain::Customer>,
@@ -222,7 +222,7 @@ pub trait UpdateTracker<F, D, Req>: Send {
pub trait PostUpdateTracker<F, D, R: Send>: Send {
async fn update_tracker<'b>(
&'b self,
- db: &'b AppState,
+ db: &'b SessionState,
payment_id: &api::PaymentIdType,
payment_data: D,
response: types::RouterData<F, R, PaymentsResponseData>,
@@ -233,7 +233,7 @@ pub trait PostUpdateTracker<F, D, R: Send>: Send {
async fn save_pm_and_mandate<'b>(
&self,
- _state: &AppState,
+ _state: &SessionState,
_resp: &types::RouterData<F, R, PaymentsResponseData>,
_merchant_account: &domain::MerchantAccount,
_key_store: &domain::MerchantKeyStore,
@@ -285,7 +285,7 @@ where
async fn get_connector<'a>(
&'a self,
_merchant_account: &domain::MerchantAccount,
- state: &AppState,
+ state: &SessionState,
_request: &api::PaymentsRetrieveRequest,
_payment_intent: &storage::PaymentIntent,
_merchant_key_store: &domain::MerchantKeyStore,
@@ -296,7 +296,7 @@ where
#[instrument(skip_all)]
async fn make_pm_data<'a>(
&'a self,
- state: &'a AppState,
+ state: &'a SessionState,
payment_data: &mut PaymentData<F>,
storage_scheme: enums::MerchantStorageScheme,
merchant_key_store: &domain::MerchantKeyStore,
@@ -320,7 +320,7 @@ where
#[instrument(skip_all)]
async fn guard_payment_against_blocklist<'a>(
&'a self,
- _state: &AppState,
+ _state: &SessionState,
_merchant_account: &domain::MerchantAccount,
_payment_data: &mut PaymentData<F>,
) -> CustomResult<bool, errors::ApiErrorResponse> {
@@ -365,7 +365,7 @@ where
#[instrument(skip_all)]
async fn make_pm_data<'a>(
&'a self,
- _state: &'a AppState,
+ _state: &'a SessionState,
_payment_data: &mut PaymentData<F>,
_storage_scheme: enums::MerchantStorageScheme,
_merchant_key_store: &domain::MerchantKeyStore,
@@ -381,7 +381,7 @@ where
async fn get_connector<'a>(
&'a self,
_merchant_account: &domain::MerchantAccount,
- state: &AppState,
+ state: &SessionState,
_request: &api::PaymentsCaptureRequest,
_payment_intent: &storage::PaymentIntent,
_merchant_key_store: &domain::MerchantKeyStore,
@@ -392,7 +392,7 @@ where
#[instrument(skip_all)]
async fn guard_payment_against_blocklist<'a>(
&'a self,
- _state: &AppState,
+ _state: &SessionState,
_merchant_account: &domain::MerchantAccount,
_payment_data: &mut PaymentData<F>,
) -> CustomResult<bool, errors::ApiErrorResponse> {
@@ -438,7 +438,7 @@ where
#[instrument(skip_all)]
async fn make_pm_data<'a>(
&'a self,
- _state: &'a AppState,
+ _state: &'a SessionState,
_payment_data: &mut PaymentData<F>,
_storage_scheme: enums::MerchantStorageScheme,
_merchant_key_store: &domain::MerchantKeyStore,
@@ -454,7 +454,7 @@ where
async fn get_connector<'a>(
&'a self,
_merchant_account: &domain::MerchantAccount,
- state: &AppState,
+ state: &SessionState,
_request: &api::PaymentsCancelRequest,
_payment_intent: &storage::PaymentIntent,
_merchant_key_store: &domain::MerchantKeyStore,
@@ -465,7 +465,7 @@ where
#[instrument(skip_all)]
async fn guard_payment_against_blocklist<'a>(
&'a self,
- _state: &AppState,
+ _state: &SessionState,
_merchant_account: &domain::MerchantAccount,
_payment_data: &mut PaymentData<F>,
) -> CustomResult<bool, errors::ApiErrorResponse> {
@@ -500,7 +500,7 @@ where
#[instrument(skip_all)]
async fn make_pm_data<'a>(
&'a self,
- _state: &'a AppState,
+ _state: &'a SessionState,
_payment_data: &mut PaymentData<F>,
_storage_scheme: enums::MerchantStorageScheme,
_merchant_key_store: &domain::MerchantKeyStore,
@@ -516,7 +516,7 @@ where
async fn get_connector<'a>(
&'a self,
_merchant_account: &domain::MerchantAccount,
- state: &AppState,
+ state: &SessionState,
_request: &api::PaymentsRejectRequest,
_payment_intent: &storage::PaymentIntent,
_merchant_key_store: &domain::MerchantKeyStore,
@@ -527,7 +527,7 @@ where
#[instrument(skip_all)]
async fn guard_payment_against_blocklist<'a>(
&'a self,
- _state: &AppState,
+ _state: &SessionState,
_merchant_account: &domain::MerchantAccount,
_payment_data: &mut PaymentData<F>,
) -> CustomResult<bool, errors::ApiErrorResponse> {
diff --git a/crates/router/src/core/payments/operations/payment_approve.rs b/crates/router/src/core/payments/operations/payment_approve.rs
index 52325db753..a492cb7603 100644
--- a/crates/router/src/core/payments/operations/payment_approve.rs
+++ b/crates/router/src/core/payments/operations/payment_approve.rs
@@ -12,7 +12,7 @@ use crate::{
errors::{self, RouterResult, StorageErrorExt},
payments::{helpers, operations, PaymentData},
},
- routes::{app::ReqState, AppState},
+ routes::{app::ReqState, SessionState},
services,
types::{
api::{self, PaymentIdTypeExt},
@@ -34,7 +34,7 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsCaptureRequest>
#[instrument(skip_all)]
async fn get_trackers<'a>(
&'a self,
- state: &'a AppState,
+ state: &'a SessionState,
payment_id: &api::PaymentIdType,
_request: &api::PaymentsCaptureRequest,
merchant_account: &domain::MerchantAccount,
@@ -194,7 +194,7 @@ impl<F: Clone> UpdateTracker<F, PaymentData<F>, api::PaymentsCaptureRequest> for
#[instrument(skip_all)]
async fn update_trackers<'b>(
&'b self,
- db: &'b AppState,
+ db: &'b SessionState,
_req_state: ReqState,
mut payment_data: PaymentData<F>,
_customer: Option<domain::Customer>,
diff --git a/crates/router/src/core/payments/operations/payment_cancel.rs b/crates/router/src/core/payments/operations/payment_cancel.rs
index 64114fc40e..ce79f9392c 100644
--- a/crates/router/src/core/payments/operations/payment_cancel.rs
+++ b/crates/router/src/core/payments/operations/payment_cancel.rs
@@ -14,7 +14,7 @@ use crate::{
payments::{helpers, operations, PaymentData},
},
events::audit_events::{AuditEvent, AuditEventType},
- routes::{app::ReqState, AppState},
+ routes::{app::ReqState, SessionState},
services,
types::{
self as core_types,
@@ -34,7 +34,7 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsCancelRequest>
#[instrument(skip_all)]
async fn get_trackers<'a>(
&'a self,
- state: &'a AppState,
+ state: &'a SessionState,
payment_id: &api::PaymentIdType,
request: &api::PaymentsCancelRequest,
merchant_account: &domain::MerchantAccount,
@@ -207,7 +207,7 @@ impl<F: Clone> UpdateTracker<F, PaymentData<F>, api::PaymentsCancelRequest> for
#[instrument(skip_all)]
async fn update_trackers<'b>(
&'b self,
- db: &'b AppState,
+ db: &'b SessionState,
req_state: ReqState,
mut payment_data: PaymentData<F>,
_customer: Option<domain::Customer>,
diff --git a/crates/router/src/core/payments/operations/payment_capture.rs b/crates/router/src/core/payments/operations/payment_capture.rs
index ec86d1d172..447f7b9290 100644
--- a/crates/router/src/core/payments/operations/payment_capture.rs
+++ b/crates/router/src/core/payments/operations/payment_capture.rs
@@ -12,7 +12,7 @@ use crate::{
errors::{self, RouterResult, StorageErrorExt},
payments::{self, helpers, operations, types::MultipleCaptureData},
},
- routes::{app::ReqState, AppState},
+ routes::{app::ReqState, SessionState},
services,
types::{
self as core_types,
@@ -34,7 +34,7 @@ impl<F: Send + Clone> GetTracker<F, payments::PaymentData<F>, api::PaymentsCaptu
#[instrument(skip_all)]
async fn get_trackers<'a>(
&'a self,
- state: &'a AppState,
+ state: &'a SessionState,
payment_id: &api::PaymentIdType,
request: &api::PaymentsCaptureRequest,
merchant_account: &domain::MerchantAccount,
@@ -254,7 +254,7 @@ impl<F: Clone> UpdateTracker<F, payments::PaymentData<F>, api::PaymentsCaptureRe
#[instrument(skip_all)]
async fn update_trackers<'b>(
&'b self,
- db: &'b AppState,
+ db: &'b SessionState,
_req_state: ReqState,
mut payment_data: payments::PaymentData<F>,
_customer: Option<domain::Customer>,
diff --git a/crates/router/src/core/payments/operations/payment_complete_authorize.rs b/crates/router/src/core/payments/operations/payment_complete_authorize.rs
index 49fe8ce201..1ff95c37f6 100644
--- a/crates/router/src/core/payments/operations/payment_complete_authorize.rs
+++ b/crates/router/src/core/payments/operations/payment_complete_authorize.rs
@@ -15,7 +15,7 @@ use crate::{
utils as core_utils,
},
db::StorageInterface,
- routes::{app::ReqState, AppState},
+ routes::{app::ReqState, SessionState},
services,
types::{
api::{self, PaymentIdTypeExt},
@@ -34,7 +34,7 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsRequest> for Co
#[instrument(skip_all)]
async fn get_trackers<'a>(
&'a self,
- state: &'a AppState,
+ state: &'a SessionState,
payment_id: &api::PaymentIdType,
request: &api::PaymentsRequest,
merchant_account: &domain::MerchantAccount,
@@ -367,7 +367,7 @@ impl<F: Clone + Send> Domain<F, api::PaymentsRequest> for CompleteAuthorize {
#[instrument(skip_all)]
async fn make_pm_data<'a>(
&'a self,
- state: &'a AppState,
+ state: &'a SessionState,
payment_data: &mut PaymentData<F>,
storage_scheme: storage_enums::MerchantStorageScheme,
merchant_key_store: &domain::MerchantKeyStore,
@@ -392,7 +392,7 @@ impl<F: Clone + Send> Domain<F, api::PaymentsRequest> for CompleteAuthorize {
#[instrument(skip_all)]
async fn add_task_to_process_tracker<'a>(
&'a self,
- _state: &'a AppState,
+ _state: &'a SessionState,
_payment_attempt: &storage::PaymentAttempt,
_requeue: bool,
_schedule_time: Option<time::PrimitiveDateTime>,
@@ -403,7 +403,7 @@ impl<F: Clone + Send> Domain<F, api::PaymentsRequest> for CompleteAuthorize {
async fn get_connector<'a>(
&'a self,
_merchant_account: &domain::MerchantAccount,
- state: &AppState,
+ state: &SessionState,
request: &api::PaymentsRequest,
_payment_intent: &storage::PaymentIntent,
_key_store: &domain::MerchantKeyStore,
@@ -416,7 +416,7 @@ impl<F: Clone + Send> Domain<F, api::PaymentsRequest> for CompleteAuthorize {
#[instrument(skip_all)]
async fn guard_payment_against_blocklist<'a>(
&'a self,
- _state: &AppState,
+ _state: &SessionState,
_merchant_account: &domain::MerchantAccount,
_payment_data: &mut PaymentData<F>,
) -> CustomResult<bool, errors::ApiErrorResponse> {
@@ -429,7 +429,7 @@ impl<F: Clone> UpdateTracker<F, PaymentData<F>, api::PaymentsRequest> for Comple
#[instrument(skip_all)]
async fn update_trackers<'b>(
&'b self,
- state: &'b AppState,
+ state: &'b SessionState,
_req_state: ReqState,
mut payment_data: PaymentData<F>,
_customer: Option<domain::Customer>,
diff --git a/crates/router/src/core/payments/operations/payment_confirm.rs b/crates/router/src/core/payments/operations/payment_confirm.rs
index edda62d79f..ea5f2c0ecb 100644
--- a/crates/router/src/core/payments/operations/payment_confirm.rs
+++ b/crates/router/src/core/payments/operations/payment_confirm.rs
@@ -29,7 +29,7 @@ use crate::{
utils as core_utils,
},
db::StorageInterface,
- routes::{app::ReqState, AppState},
+ routes::{app::ReqState, SessionState},
services,
types::{
self,
@@ -48,7 +48,7 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsRequest> for Pa
#[instrument(skip_all)]
async fn get_trackers<'a>(
&'a self,
- state: &'a AppState,
+ state: &'a SessionState,
payment_id: &api::PaymentIdType,
request: &api::PaymentsRequest,
merchant_account: &domain::MerchantAccount,
@@ -687,7 +687,7 @@ impl<F: Clone + Send> Domain<F, api::PaymentsRequest> for PaymentConfirm {
#[instrument(skip_all)]
async fn make_pm_data<'a>(
&'a self,
- state: &'a AppState,
+ state: &'a SessionState,
payment_data: &mut PaymentData<F>,
storage_scheme: storage_enums::MerchantStorageScheme,
key_store: &domain::MerchantKeyStore,
@@ -717,7 +717,7 @@ impl<F: Clone + Send> Domain<F, api::PaymentsRequest> for PaymentConfirm {
#[instrument(skip_all)]
async fn add_task_to_process_tracker<'a>(
&'a self,
- state: &'a AppState,
+ state: &'a SessionState,
payment_attempt: &storage::PaymentAttempt,
requeue: bool,
schedule_time: Option<time::PrimitiveDateTime>,
@@ -732,7 +732,7 @@ impl<F: Clone + Send> Domain<F, api::PaymentsRequest> for PaymentConfirm {
async move {
helpers::add_domain_task_to_pt(
&m_self,
- m_state.as_ref(),
+ &m_state,
&m_payment_attempt,
requeue,
schedule_time,
@@ -748,7 +748,7 @@ impl<F: Clone + Send> Domain<F, api::PaymentsRequest> for PaymentConfirm {
async fn get_connector<'a>(
&'a self,
_merchant_account: &domain::MerchantAccount,
- state: &AppState,
+ state: &SessionState,
request: &api::PaymentsRequest,
_payment_intent: &storage::PaymentIntent,
_key_store: &domain::MerchantKeyStore,
@@ -761,7 +761,7 @@ impl<F: Clone + Send> Domain<F, api::PaymentsRequest> for PaymentConfirm {
#[instrument(skip_all)]
async fn populate_payment_data<'a>(
&'a self,
- state: &AppState,
+ state: &SessionState,
payment_data: &mut PaymentData<F>,
_merchant_account: &domain::MerchantAccount,
) -> CustomResult<(), errors::ApiErrorResponse> {
@@ -770,7 +770,7 @@ impl<F: Clone + Send> Domain<F, api::PaymentsRequest> for PaymentConfirm {
async fn call_external_three_ds_authentication_if_eligible<'a>(
&'a self,
- state: &AppState,
+ state: &SessionState,
payment_data: &mut PaymentData<F>,
should_continue_confirm_transaction: &mut bool,
connector_call_type: &ConnectorCallType,
@@ -857,7 +857,7 @@ impl<F: Clone + Send> Domain<F, api::PaymentsRequest> for PaymentConfirm {
#[instrument(skip_all)]
async fn guard_payment_against_blocklist<'a>(
&'a self,
- state: &AppState,
+ state: &SessionState,
merchant_account: &domain::MerchantAccount,
payment_data: &mut PaymentData<F>,
) -> CustomResult<bool, errors::ApiErrorResponse> {
@@ -867,7 +867,7 @@ impl<F: Clone + Send> Domain<F, api::PaymentsRequest> for PaymentConfirm {
#[instrument(skip_all)]
async fn store_extended_card_info_temporarily<'a>(
&'a self,
- state: &AppState,
+ state: &SessionState,
payment_id: &str,
business_profile: &storage::BusinessProfile,
payment_method_data: &Option<api::PaymentMethodData>,
@@ -934,7 +934,7 @@ impl<F: Clone> UpdateTracker<F, PaymentData<F>, api::PaymentsRequest> for Paymen
#[instrument(skip_all)]
async fn update_trackers<'b>(
&'b self,
- state: &'b AppState,
+ state: &'b SessionState,
_req_state: ReqState,
mut payment_data: PaymentData<F>,
customer: Option<domain::Customer>,
diff --git a/crates/router/src/core/payments/operations/payment_create.rs b/crates/router/src/core/payments/operations/payment_create.rs
index 9a4e878905..bb249e9a9c 100644
--- a/crates/router/src/core/payments/operations/payment_create.rs
+++ b/crates/router/src/core/payments/operations/payment_create.rs
@@ -30,7 +30,7 @@ use crate::{
utils as core_utils,
},
db::StorageInterface,
- routes::{app::ReqState, AppState},
+ routes::{app::ReqState, SessionState},
services,
types::{
api::{self, PaymentIdTypeExt},
@@ -54,7 +54,7 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsRequest> for Pa
#[instrument(skip_all)]
async fn get_trackers<'a>(
&'a self,
- state: &'a AppState,
+ state: &'a SessionState,
payment_id: &api::PaymentIdType,
request: &api::PaymentsRequest,
merchant_account: &domain::MerchantAccount,
@@ -215,7 +215,7 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsRequest> for Pa
.map(|merchant_name| merchant_name.into_inner().peek().to_owned())
.unwrap_or_default();
- let default_domain_name = state.conf.server.base_url.clone();
+ let default_domain_name = state.base_url.clone();
let (payment_link_config, domain_name) =
payment_link::get_payment_link_config_based_on_priority(
@@ -497,7 +497,7 @@ impl<F: Clone + Send> Domain<F, api::PaymentsRequest> for PaymentCreate {
#[instrument(skip_all)]
async fn make_pm_data<'a>(
&'a self,
- state: &'a AppState,
+ state: &'a SessionState,
payment_data: &mut PaymentData<F>,
storage_scheme: enums::MerchantStorageScheme,
merchant_key_store: &domain::MerchantKeyStore,
@@ -521,7 +521,7 @@ impl<F: Clone + Send> Domain<F, api::PaymentsRequest> for PaymentCreate {
#[instrument(skip_all)]
async fn add_task_to_process_tracker<'a>(
&'a self,
- _state: &'a AppState,
+ _state: &'a SessionState,
_payment_attempt: &PaymentAttempt,
_requeue: bool,
_schedule_time: Option<PrimitiveDateTime>,
@@ -532,7 +532,7 @@ impl<F: Clone + Send> Domain<F, api::PaymentsRequest> for PaymentCreate {
async fn get_connector<'a>(
&'a self,
_merchant_account: &domain::MerchantAccount,
- state: &AppState,
+ state: &SessionState,
request: &api::PaymentsRequest,
_payment_intent: &storage::PaymentIntent,
_merchant_key_store: &domain::MerchantKeyStore,
@@ -543,7 +543,7 @@ impl<F: Clone + Send> Domain<F, api::PaymentsRequest> for PaymentCreate {
#[instrument(skip_all)]
async fn guard_payment_against_blocklist<'a>(
&'a self,
- _state: &AppState,
+ _state: &SessionState,
_merchant_account: &domain::MerchantAccount,
_payment_data: &mut PaymentData<F>,
) -> CustomResult<bool, errors::ApiErrorResponse> {
@@ -556,7 +556,7 @@ impl<F: Clone> UpdateTracker<F, PaymentData<F>, api::PaymentsRequest> for Paymen
#[instrument(skip_all)]
async fn update_trackers<'b>(
&'b self,
- state: &'b AppState,
+ state: &'b SessionState,
_req_state: ReqState,
mut payment_data: PaymentData<F>,
_customer: Option<domain::Customer>,
@@ -771,7 +771,7 @@ impl PaymentCreate {
payment_method_type: Option<enums::PaymentMethodType>,
request: &api::PaymentsRequest,
browser_info: Option<serde_json::Value>,
- state: &AppState,
+ state: &SessionState,
payment_method_billing_address_id: Option<String>,
payment_method_info: &Option<PaymentMethod>,
key_store: &domain::MerchantKeyStore,
@@ -1074,7 +1074,7 @@ impl PaymentCreate {
#[instrument(skip_all)]
pub async fn get_ephemeral_key(
request: &api::PaymentsRequest,
- state: &AppState,
+ state: &SessionState,
merchant_account: &domain::MerchantAccount,
) -> Option<ephemeral_key::EphemeralKey> {
match request.customer_id.clone() {
diff --git a/crates/router/src/core/payments/operations/payment_reject.rs b/crates/router/src/core/payments/operations/payment_reject.rs
index 60061d655c..cf8217718c 100644
--- a/crates/router/src/core/payments/operations/payment_reject.rs
+++ b/crates/router/src/core/payments/operations/payment_reject.rs
@@ -12,7 +12,7 @@ use crate::{
errors::{self, RouterResult, StorageErrorExt},
payments::{helpers, operations, PaymentAddress, PaymentData},
},
- routes::{app::ReqState, AppState},
+ routes::{app::ReqState, SessionState},
services,
types::{
api::{self, PaymentIdTypeExt},
@@ -31,7 +31,7 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, PaymentsCancelRequest> for P
#[instrument(skip_all)]
async fn get_trackers<'a>(
&'a self,
- state: &'a AppState,
+ state: &'a SessionState,
payment_id: &api::PaymentIdType,
_request: &PaymentsCancelRequest,
merchant_account: &domain::MerchantAccount,
@@ -191,7 +191,7 @@ impl<F: Clone> UpdateTracker<F, PaymentData<F>, PaymentsCancelRequest> for Payme
#[instrument(skip_all)]
async fn update_trackers<'b>(
&'b self,
- state: &'b AppState,
+ state: &'b SessionState,
_req_state: ReqState,
mut payment_data: PaymentData<F>,
_customer: Option<domain::Customer>,
diff --git a/crates/router/src/core/payments/operations/payment_response.rs b/crates/router/src/core/payments/operations/payment_response.rs
index 3b5bd9fd43..4843d1145d 100644
--- a/crates/router/src/core/payments/operations/payment_response.rs
+++ b/crates/router/src/core/payments/operations/payment_response.rs
@@ -28,7 +28,7 @@ use crate::{
},
utils as core_utils,
},
- routes::{metrics, AppState},
+ routes::{metrics, SessionState},
types::{
self, api, domain,
storage::{self, enums},
@@ -51,7 +51,7 @@ impl<F: Send + Clone> PostUpdateTracker<F, PaymentData<F>, types::PaymentsAuthor
{
async fn update_tracker<'b>(
&'b self,
- db: &'b AppState,
+ db: &'b SessionState,
payment_id: &api::PaymentIdType,
mut payment_data: PaymentData<F>,
router_data: types::RouterData<
@@ -82,7 +82,7 @@ impl<F: Send + Clone> PostUpdateTracker<F, PaymentData<F>, types::PaymentsAuthor
async fn save_pm_and_mandate<'b>(
&self,
- state: &AppState,
+ state: &SessionState,
resp: &types::RouterData<F, types::PaymentsAuthorizeData, types::PaymentsResponseData>,
merchant_account: &domain::MerchantAccount,
key_store: &domain::MerchantKeyStore,
@@ -237,7 +237,7 @@ impl<F: Clone> PostUpdateTracker<F, PaymentData<F>, types::PaymentsIncrementalAu
{
async fn update_tracker<'b>(
&'b self,
- db: &'b AppState,
+ db: &'b SessionState,
_payment_id: &api::PaymentIdType,
mut payment_data: PaymentData<F>,
router_data: types::RouterData<
@@ -368,7 +368,7 @@ impl<F: Clone> PostUpdateTracker<F, PaymentData<F>, types::PaymentsIncrementalAu
impl<F: Clone> PostUpdateTracker<F, PaymentData<F>, types::PaymentsSyncData> for PaymentResponse {
async fn update_tracker<'b>(
&'b self,
- db: &'b AppState,
+ db: &'b SessionState,
payment_id: &api::PaymentIdType,
payment_data: PaymentData<F>,
router_data: types::RouterData<F, types::PaymentsSyncData, types::PaymentsResponseData>,
@@ -389,7 +389,7 @@ impl<F: Clone> PostUpdateTracker<F, PaymentData<F>, types::PaymentsSyncData> for
async fn save_pm_and_mandate<'b>(
&self,
- state: &AppState,
+ state: &SessionState,
resp: &types::RouterData<F, types::PaymentsSyncData, types::PaymentsResponseData>,
merchant_account: &domain::MerchantAccount,
_key_store: &domain::MerchantKeyStore,
@@ -418,7 +418,7 @@ impl<F: Clone> PostUpdateTracker<F, PaymentData<F>, types::PaymentsSessionData>
{
async fn update_tracker<'b>(
&'b self,
- db: &'b AppState,
+ db: &'b SessionState,
payment_id: &api::PaymentIdType,
mut payment_data: PaymentData<F>,
router_data: types::RouterData<F, types::PaymentsSessionData, types::PaymentsResponseData>,
@@ -446,7 +446,7 @@ impl<F: Clone> PostUpdateTracker<F, PaymentData<F>, types::PaymentsCaptureData>
{
async fn update_tracker<'b>(
&'b self,
- db: &'b AppState,
+ db: &'b SessionState,
payment_id: &api::PaymentIdType,
mut payment_data: PaymentData<F>,
router_data: types::RouterData<F, types::PaymentsCaptureData, types::PaymentsResponseData>,
@@ -472,7 +472,7 @@ impl<F: Clone> PostUpdateTracker<F, PaymentData<F>, types::PaymentsCaptureData>
impl<F: Clone> PostUpdateTracker<F, PaymentData<F>, types::PaymentsCancelData> for PaymentResponse {
async fn update_tracker<'b>(
&'b self,
- db: &'b AppState,
+ db: &'b SessionState,
payment_id: &api::PaymentIdType,
mut payment_data: PaymentData<F>,
router_data: types::RouterData<F, types::PaymentsCancelData, types::PaymentsResponseData>,
@@ -501,7 +501,7 @@ impl<F: Clone> PostUpdateTracker<F, PaymentData<F>, types::PaymentsApproveData>
{
async fn update_tracker<'b>(
&'b self,
- db: &'b AppState,
+ db: &'b SessionState,
payment_id: &api::PaymentIdType,
mut payment_data: PaymentData<F>,
router_data: types::RouterData<F, types::PaymentsApproveData, types::PaymentsResponseData>,
@@ -528,7 +528,7 @@ impl<F: Clone> PostUpdateTracker<F, PaymentData<F>, types::PaymentsApproveData>
impl<F: Clone> PostUpdateTracker<F, PaymentData<F>, types::PaymentsRejectData> for PaymentResponse {
async fn update_tracker<'b>(
&'b self,
- db: &'b AppState,
+ db: &'b SessionState,
payment_id: &api::PaymentIdType,
mut payment_data: PaymentData<F>,
router_data: types::RouterData<F, types::PaymentsRejectData, types::PaymentsResponseData>,
@@ -557,7 +557,7 @@ impl<F: Clone> PostUpdateTracker<F, PaymentData<F>, types::SetupMandateRequestDa
{
async fn update_tracker<'b>(
&'b self,
- db: &'b AppState,
+ db: &'b SessionState,
payment_id: &api::PaymentIdType,
mut payment_data: PaymentData<F>,
router_data: types::RouterData<
@@ -590,7 +590,7 @@ impl<F: Clone> PostUpdateTracker<F, PaymentData<F>, types::SetupMandateRequestDa
async fn save_pm_and_mandate<'b>(
&self,
- state: &AppState,
+ state: &SessionState,
resp: &types::RouterData<F, types::SetupMandateRequestData, types::PaymentsResponseData>,
merchant_account: &domain::MerchantAccount,
key_store: &domain::MerchantKeyStore,
@@ -658,7 +658,7 @@ impl<F: Clone> PostUpdateTracker<F, PaymentData<F>, types::CompleteAuthorizeData
{
async fn update_tracker<'b>(
&'b self,
- db: &'b AppState,
+ db: &'b SessionState,
payment_id: &api::PaymentIdType,
payment_data: PaymentData<F>,
response: types::RouterData<F, types::CompleteAuthorizeData, types::PaymentsResponseData>,
@@ -679,7 +679,7 @@ impl<F: Clone> PostUpdateTracker<F, PaymentData<F>, types::CompleteAuthorizeData
async fn save_pm_and_mandate<'b>(
&self,
- state: &AppState,
+ state: &SessionState,
resp: &types::RouterData<F, types::CompleteAuthorizeData, types::PaymentsResponseData>,
merchant_account: &domain::MerchantAccount,
_key_store: &domain::MerchantKeyStore,
@@ -704,7 +704,7 @@ impl<F: Clone> PostUpdateTracker<F, PaymentData<F>, types::CompleteAuthorizeData
#[instrument(skip_all)]
async fn payment_response_update_tracker<F: Clone, T: types::Capturable>(
- state: &AppState,
+ state: &SessionState,
_payment_id: &api::PaymentIdType,
mut payment_data: PaymentData<F>,
router_data: types::RouterData<F, T, types::PaymentsResponseData>,
@@ -1235,7 +1235,7 @@ async fn payment_response_update_tracker<F: Clone, T: types::Capturable>(
}
async fn update_payment_method_status_and_ntid<F: Clone>(
- state: &AppState,
+ state: &SessionState,
payment_data: &mut PaymentData<F>,
attempt_status: common_enums::AttemptStatus,
payment_response: Result<types::PaymentsResponseData, ErrorResponse>,
diff --git a/crates/router/src/core/payments/operations/payment_session.rs b/crates/router/src/core/payments/operations/payment_session.rs
index 2aa01cd587..4d81914aca 100644
--- a/crates/router/src/core/payments/operations/payment_session.rs
+++ b/crates/router/src/core/payments/operations/payment_session.rs
@@ -14,7 +14,7 @@ use crate::{
payments::{self, helpers, operations, PaymentData},
},
db::StorageInterface,
- routes::{app::ReqState, AppState},
+ routes::{app::ReqState, SessionState},
services,
types::{
api::{self, PaymentIdTypeExt},
@@ -35,7 +35,7 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsSessionRequest>
#[instrument(skip_all)]
async fn get_trackers<'a>(
&'a self,
- state: &'a AppState,
+ state: &'a SessionState,
payment_id: &api::PaymentIdType,
request: &api::PaymentsSessionRequest,
merchant_account: &domain::MerchantAccount,
@@ -218,7 +218,7 @@ impl<F: Clone> UpdateTracker<F, PaymentData<F>, api::PaymentsSessionRequest> for
#[instrument(skip_all)]
async fn update_trackers<'b>(
&'b self,
- state: &'b AppState,
+ state: &'b SessionState,
_req_state: ReqState,
mut payment_data: PaymentData<F>,
_customer: Option<domain::Customer>,
@@ -316,7 +316,7 @@ where
#[instrument(skip_all)]
async fn make_pm_data<'b>(
&'b self,
- _state: &'b AppState,
+ _state: &'b SessionState,
_payment_data: &mut PaymentData<F>,
_storage_scheme: storage_enums::MerchantStorageScheme,
_merchant_key_store: &domain::MerchantKeyStore,
@@ -342,7 +342,7 @@ where
async fn get_connector<'a>(
&'a self,
merchant_account: &domain::MerchantAccount,
- state: &AppState,
+ state: &SessionState,
request: &api::PaymentsSessionRequest,
payment_intent: &storage::PaymentIntent,
key_store: &domain::MerchantKeyStore,
@@ -458,7 +458,7 @@ where
#[instrument(skip_all)]
async fn guard_payment_against_blocklist<'a>(
&'a self,
- _state: &AppState,
+ _state: &SessionState,
_merchant_account: &domain::MerchantAccount,
_payment_data: &mut PaymentData<F>,
) -> errors::CustomResult<bool, errors::ApiErrorResponse> {
diff --git a/crates/router/src/core/payments/operations/payment_start.rs b/crates/router/src/core/payments/operations/payment_start.rs
index e5567e5b47..7c1c117a72 100644
--- a/crates/router/src/core/payments/operations/payment_start.rs
+++ b/crates/router/src/core/payments/operations/payment_start.rs
@@ -13,7 +13,7 @@ use crate::{
payments::{helpers, operations, CustomerDetails, PaymentAddress, PaymentData},
},
db::StorageInterface,
- routes::{app::ReqState, AppState},
+ routes::{app::ReqState, SessionState},
services,
types::{
api::{self, PaymentIdTypeExt},
@@ -32,7 +32,7 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsStartRequest> f
#[instrument(skip_all)]
async fn get_trackers<'a>(
&'a self,
- state: &'a AppState,
+ state: &'a SessionState,
payment_id: &api::PaymentIdType,
_request: &api::PaymentsStartRequest,
merchant_account: &domain::MerchantAccount,
@@ -203,7 +203,7 @@ impl<F: Clone> UpdateTracker<F, PaymentData<F>, api::PaymentsStartRequest> for P
#[instrument(skip_all)]
async fn update_trackers<'b>(
&'b self,
- _state: &'b AppState,
+ _state: &'b SessionState,
_req_state: ReqState,
payment_data: PaymentData<F>,
_customer: Option<domain::Customer>,
@@ -290,7 +290,7 @@ where
#[instrument(skip_all)]
async fn make_pm_data<'a>(
&'a self,
- state: &'a AppState,
+ state: &'a SessionState,
payment_data: &mut PaymentData<F>,
storage_scheme: storage_enums::MerchantStorageScheme,
merchant_key_store: &domain::MerchantKeyStore,
@@ -324,7 +324,7 @@ where
async fn get_connector<'a>(
&'a self,
_merchant_account: &domain::MerchantAccount,
- state: &AppState,
+ state: &SessionState,
_request: &api::PaymentsStartRequest,
_payment_intent: &storage::PaymentIntent,
_mechant_key_store: &domain::MerchantKeyStore,
@@ -335,7 +335,7 @@ where
#[instrument(skip_all)]
async fn guard_payment_against_blocklist<'a>(
&'a self,
- _state: &AppState,
+ _state: &SessionState,
_merchant_account: &domain::MerchantAccount,
_payment_data: &mut PaymentData<F>,
) -> CustomResult<bool, errors::ApiErrorResponse> {
diff --git a/crates/router/src/core/payments/operations/payment_status.rs b/crates/router/src/core/payments/operations/payment_status.rs
index 0bedd70b92..9971ea76aa 100644
--- a/crates/router/src/core/payments/operations/payment_status.rs
+++ b/crates/router/src/core/payments/operations/payment_status.rs
@@ -17,7 +17,7 @@ use crate::{
},
},
db::StorageInterface,
- routes::{app::ReqState, AppState},
+ routes::{app::ReqState, SessionState},
services,
types::{
api, domain,
@@ -85,7 +85,7 @@ impl<F: Clone + Send> Domain<F, api::PaymentsRequest> for PaymentStatus {
#[instrument(skip_all)]
async fn make_pm_data<'a>(
&'a self,
- state: &'a AppState,
+ state: &'a SessionState,
payment_data: &mut PaymentData<F>,
storage_scheme: enums::MerchantStorageScheme,
merchant_key_store: &domain::MerchantKeyStore,
@@ -109,7 +109,7 @@ impl<F: Clone + Send> Domain<F, api::PaymentsRequest> for PaymentStatus {
#[instrument(skip_all)]
async fn add_task_to_process_tracker<'a>(
&'a self,
- state: &'a AppState,
+ state: &'a SessionState,
payment_attempt: &storage::PaymentAttempt,
requeue: bool,
schedule_time: Option<time::PrimitiveDateTime>,
@@ -120,7 +120,7 @@ impl<F: Clone + Send> Domain<F, api::PaymentsRequest> for PaymentStatus {
async fn get_connector<'a>(
&'a self,
_merchant_account: &domain::MerchantAccount,
- state: &AppState,
+ state: &SessionState,
request: &api::PaymentsRequest,
_payment_intent: &storage::PaymentIntent,
_key_store: &domain::MerchantKeyStore,
@@ -131,7 +131,7 @@ impl<F: Clone + Send> Domain<F, api::PaymentsRequest> for PaymentStatus {
#[instrument(skip_all)]
async fn guard_payment_against_blocklist<'a>(
&'a self,
- _state: &AppState,
+ _state: &SessionState,
_merchant_account: &domain::MerchantAccount,
_payment_data: &mut PaymentData<F>,
) -> CustomResult<bool, errors::ApiErrorResponse> {
@@ -143,7 +143,7 @@ impl<F: Clone + Send> Domain<F, api::PaymentsRequest> for PaymentStatus {
impl<F: Clone> UpdateTracker<F, PaymentData<F>, api::PaymentsRequest> for PaymentStatus {
async fn update_trackers<'b>(
&'b self,
- _state: &'b AppState,
+ _state: &'b SessionState,
_req_state: ReqState,
payment_data: PaymentData<F>,
_customer: Option<domain::Customer>,
@@ -164,7 +164,7 @@ impl<F: Clone> UpdateTracker<F, PaymentData<F>, api::PaymentsRequest> for Paymen
impl<F: Clone> UpdateTracker<F, PaymentData<F>, api::PaymentsRetrieveRequest> for PaymentStatus {
async fn update_trackers<'b>(
&'b self,
- _state: &'b AppState,
+ _state: &'b SessionState,
_req_state: ReqState,
payment_data: PaymentData<F>,
_customer: Option<domain::Customer>,
@@ -191,7 +191,7 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsRetrieveRequest
#[instrument(skip_all)]
async fn get_trackers<'a>(
&'a self,
- state: &'a AppState,
+ state: &'a SessionState,
payment_id: &api::PaymentIdType,
request: &api::PaymentsRetrieveRequest,
merchant_account: &domain::MerchantAccount,
diff --git a/crates/router/src/core/payments/operations/payment_update.rs b/crates/router/src/core/payments/operations/payment_update.rs
index e44dc0c1f2..ffa122e54a 100644
--- a/crates/router/src/core/payments/operations/payment_update.rs
+++ b/crates/router/src/core/payments/operations/payment_update.rs
@@ -18,7 +18,7 @@ use crate::{
utils as core_utils,
},
db::StorageInterface,
- routes::{app::ReqState, AppState},
+ routes::{app::ReqState, SessionState},
services,
types::{
api::{self, PaymentIdTypeExt},
@@ -37,7 +37,7 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsRequest> for Pa
#[instrument(skip_all)]
async fn get_trackers<'a>(
&'a self,
- state: &'a AppState,
+ state: &'a SessionState,
payment_id: &api::PaymentIdType,
request: &api::PaymentsRequest,
merchant_account: &domain::MerchantAccount,
@@ -500,7 +500,7 @@ impl<F: Clone + Send> Domain<F, api::PaymentsRequest> for PaymentUpdate {
#[instrument(skip_all)]
async fn make_pm_data<'a>(
&'a self,
- state: &'a AppState,
+ state: &'a SessionState,
payment_data: &mut PaymentData<F>,
storage_scheme: storage_enums::MerchantStorageScheme,
merchant_key_store: &domain::MerchantKeyStore,
@@ -524,7 +524,7 @@ impl<F: Clone + Send> Domain<F, api::PaymentsRequest> for PaymentUpdate {
#[instrument(skip_all)]
async fn add_task_to_process_tracker<'a>(
&'a self,
- _state: &'a AppState,
+ _state: &'a SessionState,
_payment_attempt: &storage::PaymentAttempt,
_requeue: bool,
_schedule_time: Option<time::PrimitiveDateTime>,
@@ -535,7 +535,7 @@ impl<F: Clone + Send> Domain<F, api::PaymentsRequest> for PaymentUpdate {
async fn get_connector<'a>(
&'a self,
_merchant_account: &domain::MerchantAccount,
- state: &AppState,
+ state: &SessionState,
request: &api::PaymentsRequest,
_payment_intent: &storage::PaymentIntent,
_key_store: &domain::MerchantKeyStore,
@@ -546,7 +546,7 @@ impl<F: Clone + Send> Domain<F, api::PaymentsRequest> for PaymentUpdate {
#[instrument(skip_all)]
async fn guard_payment_against_blocklist<'a>(
&'a self,
- _state: &AppState,
+ _state: &SessionState,
_merchant_account: &domain::MerchantAccount,
_payment_data: &mut PaymentData<F>,
) -> CustomResult<bool, errors::ApiErrorResponse> {
@@ -559,7 +559,7 @@ impl<F: Clone> UpdateTracker<F, PaymentData<F>, api::PaymentsRequest> for Paymen
#[instrument(skip_all)]
async fn update_trackers<'b>(
&'b self,
- state: &'b AppState,
+ state: &'b SessionState,
_req_state: ReqState,
mut payment_data: PaymentData<F>,
customer: Option<domain::Customer>,
diff --git a/crates/router/src/core/payments/operations/payments_incremental_authorization.rs b/crates/router/src/core/payments/operations/payments_incremental_authorization.rs
index 56665d65a3..26ffd65035 100644
--- a/crates/router/src/core/payments/operations/payments_incremental_authorization.rs
+++ b/crates/router/src/core/payments/operations/payments_incremental_authorization.rs
@@ -18,7 +18,7 @@ use crate::{
},
routes::{
app::{ReqState, StorageInterface},
- AppState,
+ SessionState,
},
services,
types::{
@@ -41,7 +41,7 @@ impl<F: Send + Clone>
#[instrument(skip_all)]
async fn get_trackers<'a>(
&'a self,
- state: &'a AppState,
+ state: &'a SessionState,
payment_id: &api::PaymentIdType,
request: &PaymentsIncrementalAuthorizationRequest,
merchant_account: &domain::MerchantAccount,
@@ -174,7 +174,7 @@ impl<F: Clone> UpdateTracker<F, payments::PaymentData<F>, PaymentsIncrementalAut
#[instrument(skip_all)]
async fn update_trackers<'b>(
&'b self,
- db: &'b AppState,
+ db: &'b SessionState,
_req_state: ReqState,
mut payment_data: payments::PaymentData<F>,
_customer: Option<domain::Customer>,
@@ -307,7 +307,7 @@ impl<F: Clone + Send> Domain<F, PaymentsIncrementalAuthorizationRequest>
#[instrument(skip_all)]
async fn make_pm_data<'a>(
&'a self,
- _state: &'a AppState,
+ _state: &'a SessionState,
_payment_data: &mut payments::PaymentData<F>,
_storage_scheme: enums::MerchantStorageScheme,
_merchant_key_store: &domain::MerchantKeyStore,
@@ -323,7 +323,7 @@ impl<F: Clone + Send> Domain<F, PaymentsIncrementalAuthorizationRequest>
async fn get_connector<'a>(
&'a self,
_merchant_account: &domain::MerchantAccount,
- state: &AppState,
+ state: &SessionState,
_request: &PaymentsIncrementalAuthorizationRequest,
_payment_intent: &storage::PaymentIntent,
_merchant_key_store: &domain::MerchantKeyStore,
@@ -334,7 +334,7 @@ impl<F: Clone + Send> Domain<F, PaymentsIncrementalAuthorizationRequest>
#[instrument(skip_all)]
async fn guard_payment_against_blocklist<'a>(
&'a self,
- _state: &AppState,
+ _state: &SessionState,
_merchant_account: &domain::MerchantAccount,
_payment_data: &mut payments::PaymentData<F>,
) -> CustomResult<bool, errors::ApiErrorResponse> {
diff --git a/crates/router/src/core/payments/retry.rs b/crates/router/src/core/payments/retry.rs
index 3bafd77740..af41e3e489 100644
--- a/crates/router/src/core/payments/retry.rs
+++ b/crates/router/src/core/payments/retry.rs
@@ -31,7 +31,7 @@ use crate::{
#[instrument(skip_all)]
#[allow(clippy::too_many_arguments)]
pub async fn do_gsm_actions<F, ApiRequest, FData>(
- state: &app::AppState,
+ state: &app::SessionState,
req_state: ReqState,
payment_data: &mut payments::PaymentData<F>,
mut connectors: IntoIter<api::ConnectorData>,
@@ -165,7 +165,7 @@ where
#[instrument(skip_all)]
pub async fn is_step_up_enabled_for_merchant_connector(
- state: &app::AppState,
+ state: &app::SessionState,
merchant_id: &str,
connector_name: types::Connector,
) -> bool {
@@ -189,7 +189,7 @@ pub async fn is_step_up_enabled_for_merchant_connector(
#[instrument(skip_all)]
pub async fn get_retries(
- state: &app::AppState,
+ state: &app::SessionState,
retries: Option<i32>,
merchant_id: &str,
) -> Option<i32> {
@@ -219,7 +219,7 @@ pub async fn get_retries(
#[instrument(skip_all)]
pub async fn get_gsm<F, FData>(
- state: &app::AppState,
+ state: &app::SessionState,
router_data: &types::RouterData<F, FData, types::PaymentsResponseData>,
) -> RouterResult<Option<storage::gsm::GatewayStatusMap>> {
let error_response = router_data.response.as_ref().err();
@@ -269,7 +269,7 @@ fn get_flow_name<F>() -> RouterResult<String> {
#[allow(clippy::too_many_arguments)]
#[instrument(skip_all)]
pub async fn do_retry<F, ApiRequest, FData>(
- state: &routes::AppState,
+ state: &routes::SessionState,
req_state: ReqState,
connector: api::ConnectorData,
operation: &operations::BoxedOperation<'_, F, ApiRequest>,
@@ -326,7 +326,7 @@ where
#[instrument(skip_all)]
pub async fn modify_trackers<F, FData>(
- state: &routes::AppState,
+ state: &routes::SessionState,
connector: String,
payment_data: &mut payments::PaymentData<F>,
storage_scheme: storage_enums::MerchantStorageScheme,
diff --git a/crates/router/src/core/payments/routing.rs b/crates/router/src/core/payments/routing.rs
index d45f804268..145800ebc6 100644
--- a/crates/router/src/core/payments/routing.rs
+++ b/crates/router/src/core/payments/routing.rs
@@ -32,7 +32,7 @@ use rand::{
SeedableRng,
};
use rustc_hash::FxHashMap;
-use storage_impl::redis::cache::{CGRAPH_CACHE, ROUTING_CACHE};
+use storage_impl::redis::cache::{CacheKey, CGRAPH_CACHE, ROUTING_CACHE};
#[cfg(feature = "payouts")]
use crate::core::payouts;
@@ -50,7 +50,7 @@ use crate::{
transformers::{ForeignFrom, ForeignInto},
},
utils::{OptionExt, ValueExt},
- AppState,
+ SessionState,
};
pub enum CachedAlgorithm {
@@ -61,7 +61,7 @@ pub enum CachedAlgorithm {
}
pub struct SessionFlowRoutingInput<'a> {
- pub state: &'a AppState,
+ pub state: &'a SessionState,
pub country: Option<CountryAlpha2>,
pub key_store: &'a domain::MerchantKeyStore,
pub merchant_account: &'a domain::MerchantAccount,
@@ -71,7 +71,7 @@ pub struct SessionFlowRoutingInput<'a> {
}
pub struct SessionRoutingPmTypeInput<'a> {
- state: &'a AppState,
+ state: &'a SessionState,
key_store: &'a domain::MerchantKeyStore,
attempt_id: &'a str,
routing_algorithm: &'a MerchantAccountRoutingAlgorithm,
@@ -262,7 +262,7 @@ where
}
pub async fn perform_static_routing_v1<F: Clone>(
- state: &AppState,
+ state: &SessionState,
merchant_id: &str,
algorithm_ref: routing_types::RoutingAlgorithmRef,
transaction_data: &routing::TransactionData<'_, F>,
@@ -330,7 +330,7 @@ pub async fn perform_static_routing_v1<F: Clone>(
}
async fn ensure_algorithm_cached_v1(
- state: &AppState,
+ state: &SessionState,
merchant_id: &str,
algorithm_id: &str,
#[cfg(feature = "business_profile_routing")] profile_id: Option<String>,
@@ -366,7 +366,10 @@ async fn ensure_algorithm_cached_v1(
};
let cached_algorithm = ROUTING_CACHE
- .get_val::<Arc<CachedAlgorithm>>(key.as_str())
+ .get_val::<Arc<CachedAlgorithm>>(CacheKey {
+ key: key.clone(),
+ prefix: state.tenant.clone(),
+ })
.await;
let algorithm = if let Some(algo) = cached_algorithm {
@@ -428,7 +431,7 @@ fn execute_dsl_and_get_connector_v1(
}
pub async fn refresh_routing_cache_v1(
- state: &AppState,
+ state: &SessionState,
key: String,
algorithm_id: &str,
#[cfg(feature = "business_profile_routing")] profile_id: Option<String>,
@@ -483,7 +486,15 @@ pub async fn refresh_routing_cache_v1(
let arc_cached_algorithm = Arc::new(cached_algorithm);
- ROUTING_CACHE.push(key, arc_cached_algorithm.clone()).await;
+ ROUTING_CACHE
+ .push(
+ CacheKey {
+ key,
+ prefix: state.tenant.clone(),
+ },
+ arc_cached_algorithm.clone(),
+ )
+ .await;
Ok(arc_cached_algorithm)
}
@@ -523,7 +534,7 @@ pub fn perform_volume_split(
}
pub async fn get_merchant_cgraph<'a>(
- state: &AppState,
+ state: &SessionState,
key_store: &domain::MerchantKeyStore,
#[cfg(feature = "business_profile_routing")] profile_id: Option<String>,
transaction_type: &api_enums::TransactionType,
@@ -554,7 +565,10 @@ pub async fn get_merchant_cgraph<'a>(
let cached_cgraph = CGRAPH_CACHE
.get_val::<Arc<hyperswitch_constraint_graph::ConstraintGraph<'_, euclid_dir::DirValue>>>(
- key.as_str(),
+ CacheKey {
+ key: key.clone(),
+ prefix: state.tenant.clone(),
+ },
)
.await;
@@ -576,7 +590,7 @@ pub async fn get_merchant_cgraph<'a>(
}
pub async fn refresh_cgraph_cache<'a>(
- state: &AppState,
+ state: &SessionState,
key_store: &domain::MerchantKeyStore,
key: String,
#[cfg(feature = "business_profile_routing")] profile_id: Option<String>,
@@ -650,14 +664,22 @@ pub async fn refresh_cgraph_cache<'a>(
.attach_printable("when construction cgraph")?,
);
- CGRAPH_CACHE.push(key, Arc::clone(&cgraph)).await;
+ CGRAPH_CACHE
+ .push(
+ CacheKey {
+ key,
+ prefix: state.tenant.clone(),
+ },
+ Arc::clone(&cgraph),
+ )
+ .await;
Ok(cgraph)
}
#[allow(clippy::too_many_arguments)]
async fn perform_cgraph_filtering(
- state: &AppState,
+ state: &SessionState,
key_store: &domain::MerchantKeyStore,
chosen: Vec<routing_types::RoutableConnectorChoice>,
backend_input: dsl_inputs::BackendInput,
@@ -708,7 +730,7 @@ async fn perform_cgraph_filtering(
}
pub async fn perform_eligibility_analysis<F: Clone>(
- state: &AppState,
+ state: &SessionState,
key_store: &domain::MerchantKeyStore,
chosen: Vec<routing_types::RoutableConnectorChoice>,
transaction_data: &routing::TransactionData<'_, F>,
@@ -735,7 +757,7 @@ pub async fn perform_eligibility_analysis<F: Clone>(
}
pub async fn perform_fallback_routing<F: Clone>(
- state: &AppState,
+ state: &SessionState,
key_store: &domain::MerchantKeyStore,
transaction_data: &routing::TransactionData<'_, F>,
eligible_connectors: Option<&Vec<api_enums::RoutableConnectors>>,
@@ -781,7 +803,7 @@ pub async fn perform_fallback_routing<F: Clone>(
}
pub async fn perform_eligibility_analysis_with_fallback<F: Clone>(
- state: &AppState,
+ state: &SessionState,
key_store: &domain::MerchantKeyStore,
chosen: Vec<routing_types::RoutableConnectorChoice>,
transaction_data: &routing::TransactionData<'_, F>,
diff --git a/crates/router/src/core/payments/tokenization.rs b/crates/router/src/core/payments/tokenization.rs
index c19c8c4575..48637a0d2b 100644
--- a/crates/router/src/core/payments/tokenization.rs
+++ b/crates/router/src/core/payments/tokenization.rs
@@ -18,7 +18,7 @@ use crate::{
mandate, payment_methods, payments,
},
logger,
- routes::{metrics, AppState},
+ routes::{metrics, SessionState},
services,
types::{
self,
@@ -54,7 +54,7 @@ impl<F, Req: Clone> From<&types::RouterData<F, Req, types::PaymentsResponseData>
#[instrument(skip_all)]
#[allow(clippy::too_many_arguments)]
pub async fn save_payment_method<FData>(
- state: &AppState,
+ state: &SessionState,
connector_name: String,
merchant_connector_id: Option<String>,
save_payment_method_data: SavePaymentMethodData<FData>,
@@ -646,7 +646,7 @@ async fn skip_saving_card_in_locker(
}
pub async fn save_in_locker(
- state: &AppState,
+ state: &SessionState,
merchant_account: &domain::MerchantAccount,
payment_method_request: api::PaymentMethodCreate,
) -> RouterResult<(
@@ -719,7 +719,7 @@ pub fn create_payment_method_metadata(
}
pub async fn add_payment_method_token<F: Clone, T: types::Tokenizable + Clone>(
- state: &AppState,
+ state: &SessionState,
connector: &api::ConnectorData,
tokenization_action: &payments::TokenizationAction,
router_data: &mut types::RouterData<F, T, types::PaymentsResponseData>,
diff --git a/crates/router/src/core/payments/transformers.rs b/crates/router/src/core/payments/transformers.rs
index a5859ea6dc..8eca589ca2 100644
--- a/crates/router/src/core/payments/transformers.rs
+++ b/crates/router/src/core/payments/transformers.rs
@@ -15,7 +15,7 @@ use router_env::{instrument, tracing};
use super::{flows::Feature, types::AuthenticationData, PaymentData};
use crate::{
- configs::settings::{ConnectorRequestReferenceIdConfig, Server},
+ configs::settings::ConnectorRequestReferenceIdConfig,
connector::{Helcim, Nexinets},
core::{
errors::{self, RouterResponse, RouterResult},
@@ -23,7 +23,7 @@ use crate::{
utils as core_utils,
},
headers::X_PAYMENT_CONFIRM_SOURCE,
- routes::{metrics, AppState},
+ routes::{metrics, SessionState},
services::{self, RedirectForm},
types::{
self, api, domain,
@@ -36,7 +36,7 @@ use crate::{
#[instrument(skip_all)]
pub async fn construct_payment_router_data<'a, F, T>(
- state: &'a AppState,
+ state: &'a SessionState,
payment_data: PaymentData<F>,
connector_id: &str,
merchant_account: &domain::MerchantAccount,
@@ -93,7 +93,7 @@ where
});
let additional_data = PaymentAdditionalData {
- router_base_url: state.conf.server.base_url.clone(),
+ router_base_url: state.base_url.clone(),
connector_name: connector_id.to_string(),
payment_data: payment_data.clone(),
state,
@@ -204,7 +204,7 @@ where
data: D,
customer: Option<domain::Customer>,
auth_flow: services::AuthFlow,
- server: &Server,
+ base_url: &str,
operation: Op,
connector_request_reference_id_config: &ConnectorRequestReferenceIdConfig,
connector_http_status_code: Option<u16>,
@@ -223,7 +223,7 @@ where
payment_data: PaymentData<F>,
customer: Option<domain::Customer>,
auth_flow: services::AuthFlow,
- server: &Server,
+ base_url: &str,
operation: Op,
connector_request_reference_id_config: &ConnectorRequestReferenceIdConfig,
connector_http_status_code: Option<u16>,
@@ -253,7 +253,7 @@ where
captures,
customer,
auth_flow,
- server,
+ base_url,
&operation,
connector_request_reference_id_config,
connector_http_status_code,
@@ -273,7 +273,7 @@ where
payment_data: PaymentData<F>,
_customer: Option<domain::Customer>,
_auth_flow: services::AuthFlow,
- _server: &Server,
+ _base_url: &str,
_operation: Op,
_connector_request_reference_id_config: &ConnectorRequestReferenceIdConfig,
_connector_http_status_code: Option<u16>,
@@ -305,7 +305,7 @@ where
data: PaymentData<F>,
customer: Option<domain::Customer>,
_auth_flow: services::AuthFlow,
- _server: &Server,
+ _base_url: &str,
_operation: Op,
_connector_request_reference_id_config: &ConnectorRequestReferenceIdConfig,
_connector_http_status_code: Option<u16>,
@@ -361,7 +361,7 @@ pub fn payments_to_payments_response<Op, F: Clone>(
captures: Option<Vec<storage::Capture>>,
customer: Option<domain::Customer>,
auth_flow: services::AuthFlow,
- server: &Server,
+ base_url: &str,
operation: &Op,
connector_request_reference_id_config: &ConnectorRequestReferenceIdConfig,
connector_http_status_code: Option<u16>,
@@ -589,7 +589,7 @@ where
.or(payment_attempt.authentication_data.as_ref().map(|_| {
api_models::payments::NextActionData::RedirectToUrl {
redirect_to_url: helpers::create_startpay_url(
- server,
+ base_url,
&payment_attempt,
&payment_intent,
),
@@ -606,9 +606,9 @@ where
.get_required_value("connector")?;
Some(api_models::payments::NextActionData::ThreeDsInvoke {
three_ds_data: api_models::payments::ThreeDsData {
- three_ds_authentication_url: helpers::create_authentication_url(&server.base_url, &payment_attempt),
+ three_ds_authentication_url: helpers::create_authentication_url(base_url, &payment_attempt),
three_ds_authorize_url: helpers::create_authorize_url(
- &server.base_url,
+ base_url,
&payment_attempt,
payment_connector_name,
),
@@ -1144,7 +1144,7 @@ where
router_base_url: String,
connector_name: String,
payment_data: PaymentData<F>,
- state: &'a AppState,
+ state: &'a SessionState,
customer_data: &'a Option<domain::Customer>,
}
impl<F: Clone> TryFrom<PaymentAdditionalData<'_, F>> for types::PaymentsAuthorizeData {
diff --git a/crates/router/src/core/payments/types.rs b/crates/router/src/core/payments/types.rs
index 92c9eec5ff..1f16c4d667 100644
--- a/crates/router/src/core/payments/types.rs
+++ b/crates/router/src/core/payments/types.rs
@@ -18,7 +18,7 @@ use router_env::{instrument, tracing};
use crate::{
consts as router_consts,
core::errors::{self, RouterResult},
- routes::AppState,
+ routes::SessionState,
types::{
storage::{self, enums as storage_enums},
transformers::ForeignTryFrom,
@@ -290,7 +290,7 @@ impl SurchargeMetadata {
#[instrument(skip_all)]
pub async fn persist_individual_surcharge_details_in_redis(
&self,
- state: &AppState,
+ state: &SessionState,
business_profile: &BusinessProfile,
) -> RouterResult<()> {
if !self.is_empty_result() {
@@ -325,7 +325,7 @@ impl SurchargeMetadata {
#[instrument(skip_all)]
pub async fn get_individual_surcharge_detail_from_redis(
- state: &AppState,
+ state: &SessionState,
surcharge_key: SurchargeKey,
payment_attempt_id: &str,
) -> CustomResult<SurchargeDetails, RedisError> {
diff --git a/crates/router/src/core/payouts.rs b/crates/router/src/core/payouts.rs
index 7aaf215ab5..93c634b07f 100644
--- a/crates/router/src/core/payouts.rs
+++ b/crates/router/src/core/payouts.rs
@@ -34,7 +34,7 @@ use crate::{
utils as core_utils,
},
db::StorageInterface,
- routes::AppState,
+ routes::SessionState,
services,
types::{
self,
@@ -71,7 +71,7 @@ pub fn get_next_connector(
#[cfg(feature = "payouts")]
pub async fn get_connector_choice(
- state: &AppState,
+ state: &SessionState,
merchant_account: &domain::MerchantAccount,
key_store: &domain::MerchantKeyStore,
connector: Option<String>,
@@ -152,7 +152,7 @@ pub async fn get_connector_choice(
#[instrument(skip_all)]
pub async fn make_connector_decision(
- state: &AppState,
+ state: &SessionState,
merchant_account: &domain::MerchantAccount,
key_store: &domain::MerchantKeyStore,
connector_call_type: api::ConnectorCallType,
@@ -254,7 +254,7 @@ pub async fn make_connector_decision(
#[instrument(skip_all)]
pub async fn payouts_core(
- state: &AppState,
+ state: &SessionState,
merchant_account: &domain::MerchantAccount,
key_store: &domain::MerchantKeyStore,
payout_data: &mut PayoutData,
@@ -288,7 +288,7 @@ pub async fn payouts_core(
#[instrument(skip_all)]
pub async fn payouts_create_core(
- state: AppState,
+ state: SessionState,
merchant_account: domain::MerchantAccount,
key_store: domain::MerchantKeyStore,
req: payouts::PayoutCreateRequest,
@@ -339,7 +339,7 @@ pub async fn payouts_create_core(
}
pub async fn payouts_update_core(
- state: AppState,
+ state: SessionState,
merchant_account: domain::MerchantAccount,
key_store: domain::MerchantKeyStore,
req: payouts::PayoutCreateRequest,
@@ -470,7 +470,7 @@ pub async fn payouts_update_core(
#[instrument(skip_all)]
pub async fn payouts_retrieve_core(
- state: AppState,
+ state: SessionState,
merchant_account: domain::MerchantAccount,
key_store: domain::MerchantKeyStore,
req: payouts::PayoutRetrieveRequest,
@@ -488,7 +488,7 @@ pub async fn payouts_retrieve_core(
#[instrument(skip_all)]
pub async fn payouts_cancel_core(
- state: AppState,
+ state: SessionState,
merchant_account: domain::MerchantAccount,
key_store: domain::MerchantKeyStore,
req: payouts::PayoutActionRequest,
@@ -584,7 +584,7 @@ pub async fn payouts_cancel_core(
#[instrument(skip_all)]
pub async fn payouts_fulfill_core(
- state: AppState,
+ state: SessionState,
merchant_account: domain::MerchantAccount,
key_store: domain::MerchantKeyStore,
req: payouts::PayoutActionRequest,
@@ -670,7 +670,7 @@ pub async fn payouts_fulfill_core(
#[cfg(feature = "olap")]
pub async fn payouts_list_core(
- state: AppState,
+ state: SessionState,
merchant_account: domain::MerchantAccount,
key_store: domain::MerchantKeyStore,
constraints: payouts::PayoutListConstraints,
@@ -767,7 +767,7 @@ pub async fn payouts_list_core(
#[cfg(feature = "olap")]
pub async fn payouts_filtered_list_core(
- state: AppState,
+ state: SessionState,
merchant_account: domain::MerchantAccount,
key_store: domain::MerchantKeyStore,
filters: payouts::PayoutListFilterConstraints,
@@ -817,7 +817,7 @@ pub async fn payouts_filtered_list_core(
#[cfg(feature = "olap")]
pub async fn payouts_list_available_filters_core(
- state: AppState,
+ state: SessionState,
merchant_account: domain::MerchantAccount,
time_range: api::TimeRange,
) -> RouterResponse<api::PayoutListFilters> {
@@ -852,7 +852,7 @@ pub async fn payouts_list_available_filters_core(
// ********************************************** HELPERS **********************************************
pub async fn call_connector_payout(
- state: &AppState,
+ state: &SessionState,
merchant_account: &domain::MerchantAccount,
key_store: &domain::MerchantKeyStore,
connector_data: &api::ConnectorData,
@@ -962,7 +962,7 @@ pub async fn call_connector_payout(
}
pub async fn complete_create_recipient(
- state: &AppState,
+ state: &SessionState,
merchant_account: &domain::MerchantAccount,
key_store: &domain::MerchantKeyStore,
connector_data: &api::ConnectorData,
@@ -989,7 +989,7 @@ pub async fn complete_create_recipient(
}
pub async fn create_recipient(
- state: &AppState,
+ state: &SessionState,
merchant_account: &domain::MerchantAccount,
key_store: &domain::MerchantKeyStore,
connector_data: &api::ConnectorData,
@@ -1124,7 +1124,7 @@ pub async fn create_recipient(
}
pub async fn complete_payout_eligibility(
- state: &AppState,
+ state: &SessionState,
merchant_account: &domain::MerchantAccount,
key_store: &domain::MerchantKeyStore,
connector_data: &api::ConnectorData,
@@ -1167,7 +1167,7 @@ pub async fn complete_payout_eligibility(
}
pub async fn check_payout_eligibility(
- state: &AppState,
+ state: &SessionState,
merchant_account: &domain::MerchantAccount,
key_store: &domain::MerchantKeyStore,
connector_data: &api::ConnectorData,
@@ -1281,7 +1281,7 @@ pub async fn check_payout_eligibility(
}
pub async fn complete_create_payout(
- state: &AppState,
+ state: &SessionState,
merchant_account: &domain::MerchantAccount,
key_store: &domain::MerchantKeyStore,
connector_data: &api::ConnectorData,
@@ -1343,7 +1343,7 @@ pub async fn complete_create_payout(
}
pub async fn create_payout(
- state: &AppState,
+ state: &SessionState,
merchant_account: &domain::MerchantAccount,
key_store: &domain::MerchantKeyStore,
connector_data: &api::ConnectorData,
@@ -1473,7 +1473,7 @@ pub async fn create_payout(
}
pub async fn complete_create_recipient_disburse_account(
- state: &AppState,
+ state: &SessionState,
merchant_account: &domain::MerchantAccount,
key_store: &domain::MerchantKeyStore,
connector_data: &api::ConnectorData,
@@ -1500,7 +1500,7 @@ pub async fn complete_create_recipient_disburse_account(
}
pub async fn create_recipient_disburse_account(
- state: &AppState,
+ state: &SessionState,
merchant_account: &domain::MerchantAccount,
key_store: &domain::MerchantKeyStore,
connector_data: &api::ConnectorData,
@@ -1586,7 +1586,7 @@ pub async fn create_recipient_disburse_account(
}
pub async fn cancel_payout(
- state: &AppState,
+ state: &SessionState,
merchant_account: &domain::MerchantAccount,
key_store: &domain::MerchantKeyStore,
connector_data: &api::ConnectorData,
@@ -1692,7 +1692,7 @@ pub async fn cancel_payout(
}
pub async fn fulfill_payout(
- state: &AppState,
+ state: &SessionState,
merchant_account: &domain::MerchantAccount,
key_store: &domain::MerchantKeyStore,
connector_data: &api::ConnectorData,
@@ -1904,7 +1904,7 @@ pub async fn response_handler(
// DB entries
#[allow(clippy::too_many_arguments)]
pub async fn payout_create_db_entries(
- state: &AppState,
+ state: &SessionState,
merchant_account: &domain::MerchantAccount,
key_store: &domain::MerchantKeyStore,
req: &payouts::PayoutCreateRequest,
@@ -2061,7 +2061,7 @@ pub async fn payout_create_db_entries(
}
pub async fn make_payout_data(
- state: &AppState,
+ state: &SessionState,
merchant_account: &domain::MerchantAccount,
key_store: &domain::MerchantKeyStore,
req: &payouts::PayoutRequest,
@@ -2169,7 +2169,7 @@ pub async fn add_external_account_addition_task(
}
async fn validate_and_get_business_profile(
- state: &AppState,
+ state: &SessionState,
profile_id: &String,
merchant_id: &str,
) -> RouterResult<storage::BusinessProfile> {
diff --git a/crates/router/src/core/payouts/access_token.rs b/crates/router/src/core/payouts/access_token.rs
index 8dddc0c570..af4f9e5f28 100644
--- a/crates/router/src/core/payouts/access_token.rs
+++ b/crates/router/src/core/payouts/access_token.rs
@@ -7,7 +7,7 @@ use crate::{
errors::{self, RouterResult},
payments,
},
- routes::{metrics, AppState},
+ routes::{metrics, SessionState},
services,
types::{self, api as api_types, domain, storage::enums},
};
@@ -17,7 +17,7 @@ use crate::{
/// There was an error, cannot proceed further
#[cfg(feature = "payouts")]
pub async fn create_access_token<F: Clone + 'static>(
- state: &AppState,
+ state: &SessionState,
connector_data: &api_types::ConnectorData,
merchant_account: &domain::MerchantAccount,
router_data: &mut types::PayoutsRouterData<F>,
@@ -48,7 +48,7 @@ pub async fn create_access_token<F: Clone + 'static>(
#[cfg(feature = "payouts")]
pub async fn add_access_token_for_payout<F: Clone + 'static>(
- state: &AppState,
+ state: &SessionState,
connector: &api_types::ConnectorData,
merchant_account: &domain::MerchantAccount,
router_data: &types::PayoutsRouterData<F>,
@@ -132,7 +132,7 @@ pub async fn add_access_token_for_payout<F: Clone + 'static>(
#[cfg(feature = "payouts")]
pub async fn refresh_connector_auth(
- state: &AppState,
+ state: &SessionState,
connector: &api_types::ConnectorData,
_merchant_account: &domain::MerchantAccount,
router_data: &types::RouterData<
diff --git a/crates/router/src/core/payouts/helpers.rs b/crates/router/src/core/payouts/helpers.rs
index 3059d3a416..6f8a7784ae 100644
--- a/crates/router/src/core/payouts/helpers.rs
+++ b/crates/router/src/core/payouts/helpers.rs
@@ -25,7 +25,7 @@ use crate::{
routing::TransactionData,
},
db::StorageInterface,
- routes::{metrics, AppState},
+ routes::{metrics, SessionState},
services,
types::{
api::{self, enums as api_enums},
@@ -41,7 +41,7 @@ use crate::{
#[allow(clippy::too_many_arguments)]
pub async fn make_payout_method_data<'a>(
- state: &'a AppState,
+ state: &'a SessionState,
payout_method_data: Option<&api::PayoutMethodData>,
payout_token: Option<&str>,
customer_id: &id_type::CustomerId,
@@ -186,7 +186,7 @@ pub async fn make_payout_method_data<'a>(
}
pub async fn save_payout_data_to_locker(
- state: &AppState,
+ state: &SessionState,
payout_data: &mut PayoutData,
payout_method_data: &api::PayoutMethodData,
merchant_account: &domain::MerchantAccount,
@@ -574,7 +574,7 @@ pub async fn save_payout_data_to_locker(
}
pub async fn get_or_create_customer_details(
- state: &AppState,
+ state: &SessionState,
customer_details: &CustomerDetails,
merchant_account: &domain::MerchantAccount,
key_store: &domain::MerchantKeyStore,
@@ -638,7 +638,7 @@ pub async fn get_or_create_customer_details(
}
pub async fn decide_payout_connector(
- state: &AppState,
+ state: &SessionState,
merchant_account: &domain::MerchantAccount,
key_store: &domain::MerchantKeyStore,
request_straight_through: Option<api::routing::StraightThroughAlgorithm>,
@@ -795,7 +795,7 @@ pub async fn decide_payout_connector(
}
pub async fn get_default_payout_connector(
- _state: &AppState,
+ _state: &SessionState,
request_connector: Option<serde_json::Value>,
) -> CustomResult<api::ConnectorChoice, errors::ApiErrorResponse> {
Ok(request_connector.map_or(
@@ -805,7 +805,7 @@ pub async fn get_default_payout_connector(
}
pub fn should_call_payout_connector_create_customer<'a>(
- state: &AppState,
+ state: &SessionState,
connector: &api::ConnectorData,
customer: &'a Option<domain::Customer>,
connector_label: &str,
@@ -834,7 +834,7 @@ pub fn should_call_payout_connector_create_customer<'a>(
}
pub async fn get_gsm_record(
- state: &AppState,
+ state: &SessionState,
error_code: Option<String>,
error_message: Option<String>,
connector_name: Option<String>,
diff --git a/crates/router/src/core/payouts/retry.rs b/crates/router/src/core/payouts/retry.rs
index 7cb929db94..792309920c 100644
--- a/crates/router/src/core/payouts/retry.rs
+++ b/crates/router/src/core/payouts/retry.rs
@@ -28,7 +28,7 @@ pub enum PayoutRetryType {
#[instrument(skip_all)]
#[allow(clippy::too_many_arguments)]
pub async fn do_gsm_multiple_connector_actions(
- state: &app::AppState,
+ state: &app::SessionState,
mut connectors: IntoIter<api::ConnectorData>,
original_connector_data: api::ConnectorData,
payout_data: &mut PayoutData,
@@ -95,7 +95,7 @@ pub async fn do_gsm_multiple_connector_actions(
#[instrument(skip_all)]
#[allow(clippy::too_many_arguments)]
pub async fn do_gsm_single_connector_actions(
- state: &app::AppState,
+ state: &app::SessionState,
original_connector_data: api::ConnectorData,
payout_data: &mut PayoutData,
merchant_account: &domain::MerchantAccount,
@@ -158,7 +158,7 @@ pub async fn do_gsm_single_connector_actions(
#[instrument(skip_all)]
pub async fn get_retries(
- state: &app::AppState,
+ state: &app::SessionState,
retries: Option<i32>,
merchant_id: &str,
retry_type: PayoutRetryType,
@@ -196,7 +196,7 @@ pub async fn get_retries(
#[instrument(skip_all)]
pub async fn get_gsm(
- state: &app::AppState,
+ state: &app::SessionState,
original_connector_data: &api::ConnectorData,
payout_data: &PayoutData,
) -> RouterResult<Option<storage::gsm::GatewayStatusMap>> {
@@ -236,7 +236,7 @@ pub fn get_gsm_decision(
#[allow(clippy::too_many_arguments)]
#[instrument(skip_all)]
pub async fn do_retry(
- state: &routes::AppState,
+ state: &routes::SessionState,
connector: api::ConnectorData,
merchant_account: &domain::MerchantAccount,
key_store: &domain::MerchantKeyStore,
@@ -251,7 +251,7 @@ pub async fn do_retry(
#[instrument(skip_all)]
pub async fn modify_trackers(
- state: &routes::AppState,
+ state: &routes::SessionState,
connector: &api::ConnectorData,
merchant_account: &domain::MerchantAccount,
payout_data: &mut PayoutData,
diff --git a/crates/router/src/core/payouts/validator.rs b/crates/router/src/core/payouts/validator.rs
index 1819c5152e..58972cf427 100644
--- a/crates/router/src/core/payouts/validator.rs
+++ b/crates/router/src/core/payouts/validator.rs
@@ -11,7 +11,7 @@ use crate::{
utils as core_utils,
},
db::StorageInterface,
- routes::AppState,
+ routes::SessionState,
types::{api::payouts, domain, storage},
utils,
};
@@ -45,7 +45,7 @@ pub async fn validate_uniqueness_of_payout_id_against_merchant_id(
/// - payout_id is unique against merchant_id
/// - payout_token provided is legitimate
pub async fn validate_create_request(
- state: &AppState,
+ state: &SessionState,
merchant_account: &domain::MerchantAccount,
req: &payouts::PayoutCreateRequest,
merchant_key_store: &domain::MerchantKeyStore,
diff --git a/crates/router/src/core/pm_auth.rs b/crates/router/src/core/pm_auth.rs
index f184e166e2..09d18963a2 100644
--- a/crates/router/src/core/pm_auth.rs
+++ b/crates/router/src/core/pm_auth.rs
@@ -36,15 +36,12 @@ use crate::{
errors::{self, ApiErrorResponse, RouterResponse, RouterResult, StorageErrorExt},
payment_methods::cards,
payments::helpers as oss_helpers,
- pm_auth::helpers::{self as pm_auth_helpers},
+ pm_auth::helpers as pm_auth_helpers,
},
db::StorageInterface,
logger,
- routes::AppState,
- services::{
- pm_auth::{self as pm_auth_services},
- ApplicationResponse,
- },
+ routes::SessionState,
+ services::{pm_auth as pm_auth_services, ApplicationResponse},
types::{
self,
domain::{self, types::decrypt},
@@ -55,7 +52,7 @@ use crate::{
};
pub async fn create_link_token(
- state: AppState,
+ state: SessionState,
merchant_account: domain::MerchantAccount,
key_store: domain::MerchantKeyStore,
payload: api_models::pm_auth::LinkTokenCreateRequest,
@@ -160,7 +157,7 @@ pub async fn create_link_token(
};
let connector_resp = pm_auth_services::execute_connector_processing_step(
- state.as_ref(),
+ &state,
connector_integration,
&router_data,
&connector.connector_name,
@@ -205,7 +202,7 @@ impl ForeignTryFrom<&types::ConnectorAuthType> for PlaidAuthType {
}
pub async fn exchange_token_core(
- state: AppState,
+ state: SessionState,
merchant_account: domain::MerchantAccount,
key_store: domain::MerchantKeyStore,
payload: api_models::pm_auth::ExchangeTokenCreateRequest,
@@ -270,7 +267,7 @@ async fn store_bank_details_in_payment_methods(
key_store: domain::MerchantKeyStore,
payload: api_models::pm_auth::ExchangeTokenCreateRequest,
merchant_account: domain::MerchantAccount,
- state: AppState,
+ state: SessionState,
bank_account_details_resp: pm_auth_types::BankAccountCredentialsResponse,
connector_details: (&str, Secret<String>),
mca_id: String,
@@ -523,7 +520,7 @@ pub async fn get_bank_account_creds(
connector_name: &str,
access_token: &Secret<String>,
auth_type: pm_auth_types::ConnectorAuthType,
- state: &AppState,
+ state: &SessionState,
bank_account_id: Option<Secret<String>>,
) -> RouterResult<pm_auth_types::BankAccountCredentialsResponse> {
let connector_integration_bank_details: BoxedConnectorIntegration<
@@ -578,7 +575,7 @@ async fn get_access_token_from_exchange_api(
connector_name: &str,
payload: &api_models::pm_auth::ExchangeTokenCreateRequest,
auth_type: &pm_auth_types::ConnectorAuthType,
- state: &AppState,
+ state: &SessionState,
) -> RouterResult<Secret<String>> {
let connector_integration: BoxedConnectorIntegration<
'_,
@@ -662,7 +659,7 @@ async fn get_selected_config_from_redis(
}
pub async fn retrieve_payment_method_from_auth_service(
- state: &AppState,
+ state: &SessionState,
key_store: &domain::MerchantKeyStore,
auth_token: &payment_methods::BankAccountTokenData,
payment_intent: &PaymentIntent,
diff --git a/crates/router/src/core/poll.rs b/crates/router/src/core/poll.rs
index 32a7b0f547..53b4b02e61 100644
--- a/crates/router/src/core/poll.rs
+++ b/crates/router/src/core/poll.rs
@@ -4,11 +4,13 @@ use error_stack::ResultExt;
use router_env::{instrument, tracing};
use super::errors;
-use crate::{core::errors::RouterResponse, services::ApplicationResponse, types::domain, AppState};
+use crate::{
+ core::errors::RouterResponse, services::ApplicationResponse, types::domain, SessionState,
+};
#[instrument(skip_all)]
pub async fn retrieve_poll_status(
- state: AppState,
+ state: SessionState,
req: crate::types::api::PollId,
merchant_account: domain::MerchantAccount,
) -> RouterResponse<PollResponse> {
diff --git a/crates/router/src/core/refunds.rs b/crates/router/src/core/refunds.rs
index d2d2db71ef..0d441e9538 100644
--- a/crates/router/src/core/refunds.rs
+++ b/crates/router/src/core/refunds.rs
@@ -24,7 +24,7 @@ use crate::{
utils as core_utils,
},
db, logger,
- routes::{metrics, AppState},
+ routes::{metrics, SessionState},
services,
types::{
self,
@@ -42,7 +42,7 @@ use crate::{
#[instrument(skip_all)]
pub async fn refund_create_core(
- state: AppState,
+ state: SessionState,
merchant_account: domain::MerchantAccount,
key_store: domain::MerchantKeyStore,
req: refunds::RefundRequest,
@@ -134,7 +134,7 @@ pub async fn refund_create_core(
#[allow(clippy::too_many_arguments)]
#[instrument(skip_all)]
pub async fn trigger_refund_to_gateway(
- state: &AppState,
+ state: &SessionState,
refund: &storage::Refund,
merchant_account: &domain::MerchantAccount,
key_store: &domain::MerchantKeyStore,
@@ -317,14 +317,14 @@ pub async fn trigger_refund_to_gateway(
// ********************************************** REFUND SYNC **********************************************
pub async fn refund_response_wrapper<'a, F, Fut, T, Req>(
- state: AppState,
+ state: SessionState,
merchant_account: domain::MerchantAccount,
key_store: domain::MerchantKeyStore,
request: Req,
f: F,
) -> RouterResponse<refunds::RefundResponse>
where
- F: Fn(AppState, domain::MerchantAccount, domain::MerchantKeyStore, Req) -> Fut,
+ F: Fn(SessionState, domain::MerchantAccount, domain::MerchantKeyStore, Req) -> Fut,
Fut: futures::Future<Output = RouterResult<T>>,
T: ForeignInto<refunds::RefundResponse>,
{
@@ -337,7 +337,7 @@ where
#[instrument(skip_all)]
pub async fn refund_retrieve_core(
- state: AppState,
+ state: SessionState,
merchant_account: domain::MerchantAccount,
key_store: domain::MerchantKeyStore,
request: refunds::RefundsRetrieveRequest,
@@ -432,7 +432,7 @@ fn should_call_refund(refund: &diesel_models::refund::Refund, force_sync: bool)
#[instrument(skip_all)]
pub async fn sync_refund_with_gateway(
- state: &AppState,
+ state: &SessionState,
merchant_account: &domain::MerchantAccount,
key_store: &domain::MerchantKeyStore,
payment_attempt: &storage::PaymentAttempt,
@@ -546,7 +546,7 @@ pub async fn sync_refund_with_gateway(
// ********************************************** REFUND UPDATE **********************************************
pub async fn refund_update_core(
- state: AppState,
+ state: SessionState,
merchant_account: domain::MerchantAccount,
req: refunds::RefundUpdateRequest,
) -> RouterResponse<refunds::RefundResponse> {
@@ -584,7 +584,7 @@ pub async fn refund_update_core(
#[instrument(skip_all)]
#[allow(clippy::too_many_arguments)]
pub async fn validate_and_create_refund(
- state: &AppState,
+ state: &SessionState,
merchant_account: &domain::MerchantAccount,
key_store: &domain::MerchantKeyStore,
payment_attempt: &storage::PaymentAttempt,
@@ -767,7 +767,7 @@ pub async fn validate_and_create_refund(
#[instrument(skip_all)]
#[cfg(feature = "olap")]
pub async fn refund_list(
- state: AppState,
+ state: SessionState,
merchant_account: domain::MerchantAccount,
req: api_models::refunds::RefundListRequest,
) -> RouterResponse<api_models::refunds::RefundListResponse> {
@@ -812,7 +812,7 @@ pub async fn refund_list(
#[instrument(skip_all)]
#[cfg(feature = "olap")]
pub async fn refund_filter_list(
- state: AppState,
+ state: SessionState,
merchant_account: domain::MerchantAccount,
req: api_models::payments::TimeRange,
) -> RouterResponse<api_models::refunds::RefundListMetaData> {
@@ -832,7 +832,7 @@ pub async fn refund_filter_list(
#[instrument(skip_all)]
#[cfg(feature = "olap")]
pub async fn get_filters_for_refunds(
- state: AppState,
+ state: SessionState,
merchant_account: domain::MerchantAccount,
) -> RouterResponse<api_models::refunds::RefundListFilters> {
let merchant_connector_accounts = if let services::ApplicationResponse::Json(data) =
@@ -900,7 +900,7 @@ impl ForeignFrom<storage::Refund> for api::RefundResponse {
#[instrument(skip_all)]
#[allow(clippy::too_many_arguments)]
pub async fn schedule_refund_execution(
- state: &AppState,
+ state: &SessionState,
refund: storage::Refund,
refund_type: api_models::refunds::RefundType,
merchant_account: &domain::MerchantAccount,
@@ -979,7 +979,7 @@ pub async fn schedule_refund_execution(
#[instrument(skip_all)]
pub async fn sync_refund_with_gateway_workflow(
- state: &AppState,
+ state: &SessionState,
refund_tracker: &storage::ProcessTracker,
) -> Result<(), errors::ProcessTrackerError> {
let refund_core =
@@ -1048,7 +1048,7 @@ pub async fn sync_refund_with_gateway_workflow(
#[instrument(skip_all)]
pub async fn start_refund_workflow(
- state: &AppState,
+ state: &SessionState,
refund_tracker: &storage::ProcessTracker,
) -> Result<(), errors::ProcessTrackerError> {
match refund_tracker.name.as_deref() {
@@ -1064,7 +1064,7 @@ pub async fn start_refund_workflow(
#[instrument(skip_all)]
pub async fn trigger_refund_execute_workflow(
- state: &AppState,
+ state: &SessionState,
refund_tracker: &storage::ProcessTracker,
) -> Result<(), errors::ProcessTrackerError> {
let db = &*state.store;
diff --git a/crates/router/src/core/routing.rs b/crates/router/src/core/routing.rs
index 3182561739..a64dadaa35 100644
--- a/crates/router/src/core/routing.rs
+++ b/crates/router/src/core/routing.rs
@@ -27,7 +27,7 @@ use crate::{
errors::{RouterResponse, StorageErrorExt},
metrics, utils as core_utils,
},
- routes::AppState,
+ routes::SessionState,
types::domain,
utils::{self, OptionExt, ValueExt},
};
@@ -46,7 +46,7 @@ where
}
pub async fn retrieve_merchant_routing_dictionary(
- state: AppState,
+ state: SessionState,
merchant_account: domain::MerchantAccount,
#[cfg(feature = "business_profile_routing")] query_params: RoutingRetrieveQuery,
#[cfg(feature = "business_profile_routing")] transaction_type: &enums::TransactionType,
@@ -93,7 +93,7 @@ pub async fn retrieve_merchant_routing_dictionary(
}
pub async fn create_routing_config(
- state: AppState,
+ state: SessionState,
merchant_account: domain::MerchantAccount,
key_store: domain::MerchantKeyStore,
request: routing_types::RoutingConfigRequest,
@@ -248,7 +248,7 @@ pub async fn create_routing_config(
}
pub async fn link_routing_config(
- state: AppState,
+ state: SessionState,
merchant_account: domain::MerchantAccount,
#[cfg(not(feature = "business_profile_routing"))] key_store: domain::MerchantKeyStore,
algorithm_id: String,
@@ -371,7 +371,7 @@ pub async fn link_routing_config(
}
pub async fn retrieve_routing_config(
- state: AppState,
+ state: SessionState,
merchant_account: domain::MerchantAccount,
algorithm_id: RoutingAlgorithmId,
) -> RouterResponse<routing_types::MerchantRoutingAlgorithm> {
@@ -445,7 +445,7 @@ pub async fn retrieve_routing_config(
}
}
pub async fn unlink_routing_config(
- state: AppState,
+ state: SessionState,
merchant_account: domain::MerchantAccount,
#[cfg(not(feature = "business_profile_routing"))] key_store: domain::MerchantKeyStore,
#[cfg(feature = "business_profile_routing")] request: routing_types::RoutingConfigRequest,
@@ -630,7 +630,7 @@ pub async fn unlink_routing_config(
}
pub async fn update_default_routing_config(
- state: AppState,
+ state: SessionState,
merchant_account: domain::MerchantAccount,
updated_config: Vec<routing_types::RoutableConnectorChoice>,
transaction_type: &enums::TransactionType,
@@ -679,7 +679,7 @@ pub async fn update_default_routing_config(
}
pub async fn retrieve_default_routing_config(
- state: AppState,
+ state: SessionState,
merchant_account: domain::MerchantAccount,
transaction_type: &enums::TransactionType,
) -> RouterResponse<Vec<routing_types::RoutableConnectorChoice>> {
@@ -699,7 +699,7 @@ pub async fn retrieve_default_routing_config(
}
pub async fn retrieve_linked_routing_config(
- state: AppState,
+ state: SessionState,
merchant_account: domain::MerchantAccount,
#[cfg(feature = "business_profile_routing")] query_params: RoutingRetrieveLinkQuery,
#[cfg(feature = "business_profile_routing")] transaction_type: &enums::TransactionType,
@@ -808,7 +808,7 @@ pub async fn retrieve_linked_routing_config(
}
pub async fn retrieve_default_routing_config_for_profiles(
- state: AppState,
+ state: SessionState,
merchant_account: domain::MerchantAccount,
transaction_type: &enums::TransactionType,
) -> RouterResponse<Vec<routing_types::ProfileDefaultRoutingConfig>> {
@@ -847,7 +847,7 @@ pub async fn retrieve_default_routing_config_for_profiles(
}
pub async fn update_default_routing_config_for_profile(
- state: AppState,
+ state: SessionState,
merchant_account: domain::MerchantAccount,
updated_config: Vec<routing_types::RoutableConnectorChoice>,
profile_id: String,
diff --git a/crates/router/src/core/surcharge_decision_config.rs b/crates/router/src/core/surcharge_decision_config.rs
index b489b92cdf..7f451e6008 100644
--- a/crates/router/src/core/surcharge_decision_config.rs
+++ b/crates/router/src/core/surcharge_decision_config.rs
@@ -15,14 +15,14 @@ use super::routing::helpers::{
};
use crate::{
core::errors::{self, RouterResponse},
- routes::AppState,
+ routes::SessionState,
services::api as service_api,
types::domain,
utils::OptionExt,
};
pub async fn upsert_surcharge_decision_config(
- state: AppState,
+ state: SessionState,
key_store: domain::MerchantKeyStore,
merchant_account: domain::MerchantAccount,
request: SurchargeDecisionConfigReq,
@@ -139,7 +139,7 @@ pub async fn upsert_surcharge_decision_config(
}
pub async fn delete_surcharge_decision_config(
- state: AppState,
+ state: SessionState,
key_store: domain::MerchantKeyStore,
merchant_account: domain::MerchantAccount,
) -> RouterResponse<()> {
@@ -167,7 +167,7 @@ pub async fn delete_surcharge_decision_config(
}
pub async fn retrieve_surcharge_decision_config(
- state: AppState,
+ state: SessionState,
merchant_account: domain::MerchantAccount,
) -> RouterResponse<SurchargeDecisionManagerResponse> {
let db = state.store.as_ref();
diff --git a/crates/router/src/core/user.rs b/crates/router/src/core/user.rs
index 9db47b74dc..c259e87c93 100644
--- a/crates/router/src/core/user.rs
+++ b/crates/router/src/core/user.rs
@@ -21,7 +21,7 @@ use super::errors::{StorageErrorExt, UserErrors, UserResponse, UserResult};
use crate::services::email::types as email_types;
use crate::{
consts,
- routes::{app::ReqState, AppState},
+ routes::{app::ReqState, SessionState},
services::{authentication as auth, authorization::roles, ApplicationResponse},
types::{domain, transformers::ForeignInto},
utils::{self, user::two_factor_auth as tfa_utils},
@@ -33,7 +33,7 @@ pub mod sample_data;
#[cfg(feature = "email")]
pub async fn signup_with_merchant_id(
- state: AppState,
+ state: SessionState,
request: user_api::SignUpWithMerchantIdRequest,
) -> UserResponse<user_api::SignUpWithMerchantIdResponse> {
let new_user = domain::NewUser::try_from(request.clone())?;
@@ -79,7 +79,7 @@ pub async fn signup_with_merchant_id(
}
pub async fn get_user_details(
- state: AppState,
+ state: SessionState,
user_from_token: auth::UserFromToken,
) -> UserResponse<user_api::GetUserDetailsResponse> {
let user = user_from_token.get_user_from_db(&state).await?;
@@ -99,7 +99,7 @@ pub async fn get_user_details(
}
pub async fn signup(
- state: AppState,
+ state: SessionState,
request: user_api::SignUpRequest,
) -> UserResponse<user_api::TokenOrPayloadResponse<user_api::SignUpResponse>> {
let new_user = domain::NewUser::try_from(request)?;
@@ -128,7 +128,7 @@ pub async fn signup(
}
pub async fn signup_token_only_flow(
- state: AppState,
+ state: SessionState,
request: user_api::SignUpRequest,
) -> UserResponse<user_api::TokenOrPayloadResponse<user_api::SignUpResponse>> {
let new_user = domain::NewUser::try_from(request)?;
@@ -163,7 +163,7 @@ pub async fn signup_token_only_flow(
}
pub async fn signin(
- state: AppState,
+ state: SessionState,
request: user_api::SignInRequest,
) -> UserResponse<user_api::TokenOrPayloadResponse<user_api::SignInResponse>> {
let user_from_db: domain::UserFromStorage = state
@@ -207,7 +207,7 @@ pub async fn signin(
}
pub async fn signin_token_only_flow(
- state: AppState,
+ state: SessionState,
request: user_api::SignInRequest,
) -> UserResponse<user_api::TokenOrPayloadResponse<user_api::SignInResponse>> {
let user_from_db: domain::UserFromStorage = state
@@ -233,7 +233,7 @@ pub async fn signin_token_only_flow(
#[cfg(feature = "email")]
pub async fn connect_account(
- state: AppState,
+ state: SessionState,
request: user_api::ConnectAccountRequest,
) -> UserResponse<user_api::ConnectAccountResponse> {
let find_user = state.store.find_user_by_email(&request.email).await;
@@ -324,13 +324,16 @@ pub async fn connect_account(
}
}
-pub async fn signout(state: AppState, user_from_token: auth::UserFromToken) -> UserResponse<()> {
+pub async fn signout(
+ state: SessionState,
+ user_from_token: auth::UserFromToken,
+) -> UserResponse<()> {
auth::blacklist::insert_user_in_blacklist(&state, &user_from_token.user_id).await?;
auth::cookies::remove_cookie_response()
}
pub async fn change_password(
- state: AppState,
+ state: SessionState,
request: user_api::ChangePasswordRequest,
user_from_token: auth::UserFromToken,
) -> UserResponse<()> {
@@ -386,7 +389,7 @@ pub async fn change_password(
#[cfg(feature = "email")]
pub async fn forgot_password(
- state: AppState,
+ state: SessionState,
request: user_api::ForgotPasswordRequest,
) -> UserResponse<()> {
let user_email = domain::UserEmail::from_pii_email(request.email)?;
@@ -424,7 +427,7 @@ pub async fn forgot_password(
}
pub async fn rotate_password(
- state: AppState,
+ state: SessionState,
user_token: auth::UserFromSinglePurposeToken,
request: user_api::RotatePasswordRequest,
_req_state: ReqState,
@@ -463,7 +466,7 @@ pub async fn rotate_password(
#[cfg(feature = "email")]
pub async fn reset_password_token_only_flow(
- state: AppState,
+ state: SessionState,
user_token: auth::UserFromSinglePurposeToken,
request: user_api::ResetPasswordRequest,
) -> UserResponse<()> {
@@ -517,7 +520,7 @@ pub async fn reset_password_token_only_flow(
#[cfg(feature = "email")]
pub async fn reset_password(
- state: AppState,
+ state: SessionState,
request: user_api::ResetPasswordRequest,
) -> UserResponse<()> {
let token = request.token.expose();
@@ -569,7 +572,7 @@ pub async fn reset_password(
}
pub async fn invite_multiple_user(
- state: AppState,
+ state: SessionState,
user_from_token: auth::UserFromToken,
requests: Vec<user_api::InviteUserRequest>,
req_state: ReqState,
@@ -598,7 +601,7 @@ pub async fn invite_multiple_user(
}
async fn handle_invitation(
- state: &AppState,
+ state: &SessionState,
user_from_token: &auth::UserFromToken,
request: &user_api::InviteUserRequest,
req_state: &ReqState,
@@ -656,7 +659,7 @@ async fn handle_invitation(
//TODO: send email
async fn handle_existing_user_invitation(
- state: &AppState,
+ state: &SessionState,
user_from_token: &auth::UserFromToken,
request: &user_api::InviteUserRequest,
invitee_user_from_db: domain::UserFromStorage,
@@ -727,7 +730,7 @@ async fn handle_existing_user_invitation(
}
async fn handle_new_user_invitation(
- state: &AppState,
+ state: &SessionState,
user_from_token: &auth::UserFromToken,
request: &user_api::InviteUserRequest,
req_state: ReqState,
@@ -839,7 +842,7 @@ async fn handle_new_user_invitation(
#[cfg(feature = "email")]
pub async fn resend_invite(
- state: AppState,
+ state: SessionState,
user_from_token: auth::UserFromToken,
request: user_api::ReInviteUserRequest,
_req_state: ReqState,
@@ -901,7 +904,7 @@ pub async fn resend_invite(
#[cfg(feature = "email")]
pub async fn accept_invite_from_email(
- state: AppState,
+ state: SessionState,
request: user_api::AcceptInviteFromEmailRequest,
) -> UserResponse<user_api::DashboardEntryResponse> {
let token = request.token.expose();
@@ -968,7 +971,7 @@ pub async fn accept_invite_from_email(
#[cfg(feature = "email")]
pub async fn accept_invite_from_email_token_only_flow(
- state: AppState,
+ state: SessionState,
user_token: auth::UserFromSinglePurposeToken,
request: user_api::AcceptInviteFromEmailRequest,
) -> UserResponse<user_api::TokenOrPayloadResponse<user_api::DashboardEntryResponse>> {
@@ -1034,7 +1037,7 @@ pub async fn accept_invite_from_email_token_only_flow(
}
pub async fn create_internal_user(
- state: AppState,
+ state: SessionState,
request: user_api::CreateInternalUserRequest,
) -> UserResponse<()> {
let new_user = domain::NewUser::try_from(request)?;
@@ -1097,7 +1100,7 @@ pub async fn create_internal_user(
}
pub async fn switch_merchant_id(
- state: AppState,
+ state: SessionState,
request: user_api::SwitchMerchantIdRequest,
user_from_token: auth::UserFromToken,
) -> UserResponse<user_api::DashboardEntryResponse> {
@@ -1196,7 +1199,7 @@ pub async fn switch_merchant_id(
}
pub async fn create_merchant_account(
- state: AppState,
+ state: SessionState,
user_from_token: auth::UserFromToken,
req: user_api::UserMerchantCreate,
) -> UserResponse<()> {
@@ -1227,7 +1230,7 @@ pub async fn create_merchant_account(
}
pub async fn list_merchants_for_user(
- state: AppState,
+ state: SessionState,
user_from_token: Box<dyn auth::GetUserIdFromAuth>,
) -> UserResponse<Vec<user_api::UserMerchantAccount>> {
let user_roles = state
@@ -1260,7 +1263,7 @@ pub async fn list_merchants_for_user(
}
pub async fn get_user_details_in_merchant_account(
- state: AppState,
+ state: SessionState,
user_from_token: auth::UserFromToken,
request: user_api::GetUserRoleDetailsRequest,
_req_state: ReqState,
@@ -1304,7 +1307,7 @@ pub async fn get_user_details_in_merchant_account(
}
pub async fn list_users_for_merchant_account(
- state: AppState,
+ state: SessionState,
user_from_token: auth::UserFromToken,
) -> UserResponse<user_api::ListUsersResponse> {
let users_and_user_roles = state
@@ -1352,7 +1355,7 @@ pub async fn list_users_for_merchant_account(
#[cfg(feature = "email")]
pub async fn verify_email(
- state: AppState,
+ state: SessionState,
req: user_api::VerifyEmailRequest,
) -> UserResponse<user_api::SignInResponse> {
let token = req.token.clone().expose();
@@ -1411,7 +1414,7 @@ pub async fn verify_email(
#[cfg(feature = "email")]
pub async fn verify_email_token_only_flow(
- state: AppState,
+ state: SessionState,
user_token: auth::UserFromSinglePurposeToken,
req: user_api::VerifyEmailRequest,
) -> UserResponse<user_api::TokenOrPayloadResponse<user_api::SignInResponse>> {
@@ -1469,7 +1472,7 @@ pub async fn verify_email_token_only_flow(
#[cfg(feature = "email")]
pub async fn send_verification_mail(
- state: AppState,
+ state: SessionState,
req: user_api::SendVerifyEmailRequest,
) -> UserResponse<()> {
let user_email = domain::UserEmail::try_from(req.email)?;
@@ -1509,7 +1512,7 @@ pub async fn send_verification_mail(
#[cfg(feature = "recon")]
pub async fn verify_token(
- state: AppState,
+ state: SessionState,
req: auth::ReconUser,
) -> UserResponse<user_api::VerifyTokenResponse> {
let user = state
@@ -1537,7 +1540,7 @@ pub async fn verify_token(
}
pub async fn update_user_details(
- state: AppState,
+ state: SessionState,
user_token: auth::UserFromToken,
req: user_api::UpdateUserAccountDetailsRequest,
_req_state: ReqState,
@@ -1582,7 +1585,7 @@ pub async fn update_user_details(
#[cfg(feature = "email")]
pub async fn user_from_email(
- state: AppState,
+ state: SessionState,
req: user_api::UserFromEmailRequest,
) -> UserResponse<user_api::TokenResponse> {
let token = req.token.expose();
@@ -1616,7 +1619,7 @@ pub async fn user_from_email(
}
pub async fn begin_totp(
- state: AppState,
+ state: SessionState,
user_token: auth::UserFromSinglePurposeToken,
) -> UserResponse<user_api::BeginTotpResponse> {
let user_from_db: domain::UserFromStorage = state
@@ -1645,7 +1648,7 @@ pub async fn begin_totp(
}
pub async fn reset_totp(
- state: AppState,
+ state: SessionState,
user_token: auth::UserFromToken,
) -> UserResponse<user_api::BeginTotpResponse> {
let user_from_db: domain::UserFromStorage = state
@@ -1678,7 +1681,7 @@ pub async fn reset_totp(
}
pub async fn verify_totp(
- state: AppState,
+ state: SessionState,
user_token: auth::UserFromSinglePurposeToken,
req: user_api::VerifyTotpRequest,
) -> UserResponse<user_api::TokenResponse> {
@@ -1714,7 +1717,7 @@ pub async fn verify_totp(
}
pub async fn update_totp(
- state: AppState,
+ state: SessionState,
user_token: auth::UserFromSinglePurposeToken,
req: user_api::VerifyTotpRequest,
) -> UserResponse<()> {
@@ -1779,7 +1782,7 @@ pub async fn update_totp(
}
pub async fn generate_recovery_codes(
- state: AppState,
+ state: SessionState,
user_token: auth::UserFromSinglePurposeToken,
) -> UserResponse<user_api::RecoveryCodes> {
if !tfa_utils::check_totp_in_redis(&state, &user_token.user_id).await? {
@@ -1811,7 +1814,7 @@ pub async fn generate_recovery_codes(
}
pub async fn verify_recovery_code(
- state: AppState,
+ state: SessionState,
user_token: auth::UserFromSinglePurposeToken,
req: user_api::VerifyRecoveryCodeRequest,
) -> UserResponse<user_api::TokenResponse> {
@@ -1856,7 +1859,7 @@ pub async fn verify_recovery_code(
}
pub async fn terminate_two_factor_auth(
- state: AppState,
+ state: SessionState,
user_token: auth::UserFromSinglePurposeToken,
skip_two_factor_auth: bool,
) -> UserResponse<user_api::TokenResponse> {
@@ -1908,7 +1911,7 @@ pub async fn terminate_two_factor_auth(
}
pub async fn check_two_factor_auth_status(
- state: AppState,
+ state: SessionState,
user_token: auth::UserFromToken,
) -> UserResponse<user_api::TwoFactorAuthStatusResponse> {
Ok(ApplicationResponse::Json(
diff --git a/crates/router/src/core/user/dashboard_metadata.rs b/crates/router/src/core/user/dashboard_metadata.rs
index ee1693b0c9..3648984629 100644
--- a/crates/router/src/core/user/dashboard_metadata.rs
+++ b/crates/router/src/core/user/dashboard_metadata.rs
@@ -12,14 +12,14 @@ use router_env::logger;
use crate::services::email::types as email_types;
use crate::{
core::errors::{UserErrors, UserResponse, UserResult},
- routes::{app::ReqState, AppState},
+ routes::{app::ReqState, SessionState},
services::{authentication::UserFromToken, ApplicationResponse},
types::domain::{self, user::dashboard_metadata as types, MerchantKeyStore},
utils::user::dashboard_metadata as utils,
};
pub async fn set_metadata(
- state: AppState,
+ state: SessionState,
user: UserFromToken,
request: api::SetMetaDataRequest,
_req_state: ReqState,
@@ -33,7 +33,7 @@ pub async fn set_metadata(
}
pub async fn get_multiple_metadata(
- state: AppState,
+ state: SessionState,
user: UserFromToken,
request: GetMultipleMetaDataPayload,
_req_state: ReqState,
@@ -230,7 +230,7 @@ fn into_response(
}
async fn insert_metadata(
- state: &AppState,
+ state: &SessionState,
user: UserFromToken,
metadata_key: DBEnum,
metadata_value: types::MetaData,
@@ -571,7 +571,7 @@ async fn insert_metadata(
}
async fn fetch_metadata(
- state: &AppState,
+ state: &SessionState,
user: &UserFromToken,
metadata_keys: Vec<DBEnum>,
) -> UserResult<Vec<DashboardMetadata>> {
@@ -606,7 +606,7 @@ async fn fetch_metadata(
}
pub async fn backfill_metadata(
- state: &AppState,
+ state: &SessionState,
user: &UserFromToken,
key: &DBEnum,
) -> UserResult<Option<DashboardMetadata>> {
@@ -705,7 +705,7 @@ pub async fn backfill_metadata(
}
pub async fn get_merchant_connector_account_by_name(
- state: &AppState,
+ state: &SessionState,
merchant_id: &str,
connector_name: &str,
key_store: &MerchantKeyStore,
diff --git a/crates/router/src/core/user/sample_data.rs b/crates/router/src/core/user/sample_data.rs
index e1bde65230..bab620620f 100644
--- a/crates/router/src/core/user/sample_data.rs
+++ b/crates/router/src/core/user/sample_data.rs
@@ -7,13 +7,13 @@ pub type SampleDataApiResponse<T> = SampleDataResult<ApplicationResponse<T>>;
use crate::{
core::errors::sample_data::SampleDataResult,
- routes::{app::ReqState, AppState},
+ routes::{app::ReqState, SessionState},
services::{authentication::UserFromToken, ApplicationResponse},
utils::user::sample_data::generate_sample_data,
};
pub async fn generate_sample_data_for_user(
- state: AppState,
+ state: SessionState,
user_from_token: UserFromToken,
req: SampleDataRequest,
_req_state: ReqState,
@@ -57,7 +57,7 @@ pub async fn generate_sample_data_for_user(
}
pub async fn delete_sample_data_for_user(
- state: AppState,
+ state: SessionState,
user_from_token: UserFromToken,
_req: SampleDataRequest,
_req_state: ReqState,
diff --git a/crates/router/src/core/user_role.rs b/crates/router/src/core/user_role.rs
index 0d196e1c4a..8b636f9935 100644
--- a/crates/router/src/core/user_role.rs
+++ b/crates/router/src/core/user_role.rs
@@ -6,7 +6,7 @@ use router_env::logger;
use crate::{
consts,
core::errors::{StorageErrorExt, UserErrors, UserResponse},
- routes::{app::ReqState, AppState},
+ routes::{app::ReqState, SessionState},
services::{
authentication as auth,
authorization::{info, roles},
@@ -20,7 +20,7 @@ pub mod role;
// TODO: To be deprecated once groups are stable
pub async fn get_authorization_info_with_modules(
- _state: AppState,
+ _state: SessionState,
) -> UserResponse<user_role_api::AuthorizationInfoResponse> {
Ok(ApplicationResponse::Json(
user_role_api::AuthorizationInfoResponse(
@@ -33,7 +33,7 @@ pub async fn get_authorization_info_with_modules(
}
pub async fn get_authorization_info_with_groups(
- _state: AppState,
+ _state: SessionState,
) -> UserResponse<user_role_api::AuthorizationInfoResponse> {
Ok(ApplicationResponse::Json(
user_role_api::AuthorizationInfoResponse(
@@ -46,7 +46,7 @@ pub async fn get_authorization_info_with_groups(
}
pub async fn update_user_role(
- state: AppState,
+ state: SessionState,
user_from_token: auth::UserFromToken,
req: user_role_api::UpdateUserRoleRequest,
_req_state: ReqState,
@@ -117,7 +117,7 @@ pub async fn update_user_role(
}
pub async fn transfer_org_ownership(
- state: AppState,
+ state: SessionState,
user_from_token: auth::UserFromToken,
req: user_role_api::TransferOrgOwnershipRequest,
_req_state: ReqState,
@@ -169,7 +169,7 @@ pub async fn transfer_org_ownership(
}
pub async fn accept_invitation(
- state: AppState,
+ state: SessionState,
user_token: auth::UserFromToken,
req: user_role_api::AcceptInvitationRequest,
) -> UserResponse<()> {
@@ -199,7 +199,7 @@ pub async fn accept_invitation(
}
pub async fn merchant_select(
- state: AppState,
+ state: SessionState,
user_token: auth::UserFromSinglePurposeToken,
req: user_role_api::MerchantSelectRequest,
) -> UserResponse<user_api::TokenOrPayloadResponse<user_api::DashboardEntryResponse>> {
@@ -253,7 +253,7 @@ pub async fn merchant_select(
}
pub async fn merchant_select_token_only_flow(
- state: AppState,
+ state: SessionState,
user_token: auth::UserFromSinglePurposeToken,
req: user_role_api::MerchantSelectRequest,
) -> UserResponse<user_api::TokenOrPayloadResponse<user_api::DashboardEntryResponse>> {
@@ -303,7 +303,7 @@ pub async fn merchant_select_token_only_flow(
}
pub async fn delete_user_role(
- state: AppState,
+ state: SessionState,
user_from_token: auth::UserFromToken,
request: user_role_api::DeleteUserRoleRequest,
_req_state: ReqState,
diff --git a/crates/router/src/core/user_role/role.rs b/crates/router/src/core/user_role/role.rs
index 504d5dd632..386156f58e 100644
--- a/crates/router/src/core/user_role/role.rs
+++ b/crates/router/src/core/user_role/role.rs
@@ -7,7 +7,7 @@ use error_stack::{report, ResultExt};
use crate::{
consts,
core::errors::{StorageErrorExt, UserErrors, UserResponse},
- routes::{app::ReqState, AppState},
+ routes::{app::ReqState, SessionState},
services::{
authentication::{blacklist, UserFromToken},
authorization::roles::{self, predefined_roles::PREDEFINED_ROLES},
@@ -18,7 +18,7 @@ use crate::{
};
pub async fn get_role_from_token_with_permissions(
- state: AppState,
+ state: SessionState,
user_from_token: UserFromToken,
) -> UserResponse<role_api::GetRoleFromTokenResponse> {
let role_info = user_from_token
@@ -38,7 +38,7 @@ pub async fn get_role_from_token_with_permissions(
}
pub async fn get_role_from_token_with_groups(
- state: AppState,
+ state: SessionState,
user_from_token: UserFromToken,
) -> UserResponse<role_api::GetRoleFromTokenResponse> {
let role_info = user_from_token
@@ -54,7 +54,7 @@ pub async fn get_role_from_token_with_groups(
}
pub async fn create_role(
- state: AppState,
+ state: SessionState,
user_from_token: UserFromToken,
req: role_api::CreateRoleRequest,
_req_state: ReqState,
@@ -107,7 +107,7 @@ pub async fn create_role(
// TODO: To be deprecated once groups are stable
pub async fn list_invitable_roles_with_permissions(
- state: AppState,
+ state: SessionState,
user_from_token: UserFromToken,
) -> UserResponse<role_api::ListRolesResponse> {
let predefined_roles_map = PREDEFINED_ROLES
@@ -156,7 +156,7 @@ pub async fn list_invitable_roles_with_permissions(
}
pub async fn list_invitable_roles_with_groups(
- state: AppState,
+ state: SessionState,
user_from_token: UserFromToken,
) -> UserResponse<role_api::ListRolesResponse> {
let predefined_roles_map = PREDEFINED_ROLES
@@ -198,7 +198,7 @@ pub async fn list_invitable_roles_with_groups(
// TODO: To be deprecated once groups are stable
pub async fn get_role_with_permissions(
- state: AppState,
+ state: SessionState,
user_from_token: UserFromToken,
role: role_api::GetRoleRequest,
) -> UserResponse<role_api::RoleInfoResponse> {
@@ -232,7 +232,7 @@ pub async fn get_role_with_permissions(
}
pub async fn get_role_with_groups(
- state: AppState,
+ state: SessionState,
user_from_token: UserFromToken,
role: role_api::GetRoleRequest,
) -> UserResponse<role_api::RoleInfoResponse> {
@@ -260,7 +260,7 @@ pub async fn get_role_with_groups(
}
pub async fn update_role(
- state: AppState,
+ state: SessionState,
user_from_token: UserFromToken,
req: role_api::UpdateRoleRequest,
role_id: &str,
diff --git a/crates/router/src/core/utils.rs b/crates/router/src/core/utils.rs
index e585724e96..679838a6dd 100644
--- a/crates/router/src/core/utils.rs
+++ b/crates/router/src/core/utils.rs
@@ -25,7 +25,7 @@ use crate::{
consts,
core::errors::{self, RouterResult, StorageErrorExt},
db::StorageInterface,
- routes::AppState,
+ routes::SessionState,
types::{
self, domain,
storage::{self, enums},
@@ -45,7 +45,7 @@ const IRRELEVANT_ATTEMPT_ID_IN_DISPUTE_FLOW: &str = "irrelevant_attempt_id_in_di
#[cfg(feature = "payouts")]
#[instrument(skip_all)]
pub async fn get_mca_for_payout<'a>(
- state: &'a AppState,
+ state: &'a SessionState,
connector_id: &str,
merchant_account: &domain::MerchantAccount,
key_store: &domain::MerchantKeyStore,
@@ -72,7 +72,7 @@ pub async fn get_mca_for_payout<'a>(
#[cfg(feature = "payouts")]
#[instrument(skip_all)]
pub async fn construct_payout_router_data<'a, F>(
- state: &'a AppState,
+ state: &'a SessionState,
connector_name: &api_models::enums::Connector,
merchant_account: &domain::MerchantAccount,
key_store: &domain::MerchantKeyStore,
@@ -214,7 +214,7 @@ pub async fn construct_payout_router_data<'a, F>(
#[instrument(skip_all)]
#[allow(clippy::too_many_arguments)]
pub async fn construct_refund_router_data<'a, F>(
- state: &'a AppState,
+ state: &'a SessionState,
connector_id: &str,
merchant_account: &domain::MerchantAccount,
key_store: &domain::MerchantKeyStore,
@@ -263,7 +263,7 @@ pub async fn construct_refund_router_data<'a, F>(
.change_context(errors::ApiErrorResponse::InternalServerError)?;
let webhook_url = Some(helpers::create_webhook_url(
- &state.conf.server.base_url.clone(),
+ &state.base_url.clone(),
&merchant_account.merchant_id,
&connector_id.to_string(),
));
@@ -513,7 +513,7 @@ pub fn validate_dispute_stage_and_dispute_status(
#[instrument(skip_all)]
pub async fn construct_accept_dispute_router_data<'a>(
- state: &'a AppState,
+ state: &'a SessionState,
payment_intent: &'a storage::PaymentIntent,
payment_attempt: &storage::PaymentAttempt,
merchant_account: &domain::MerchantAccount,
@@ -607,7 +607,7 @@ pub async fn construct_accept_dispute_router_data<'a>(
#[instrument(skip_all)]
pub async fn construct_submit_evidence_router_data<'a>(
- state: &'a AppState,
+ state: &'a SessionState,
payment_intent: &'a storage::PaymentIntent,
payment_attempt: &storage::PaymentAttempt,
merchant_account: &domain::MerchantAccount,
@@ -701,7 +701,7 @@ pub async fn construct_submit_evidence_router_data<'a>(
#[instrument(skip_all)]
#[allow(clippy::too_many_arguments)]
pub async fn construct_upload_file_router_data<'a>(
- state: &'a AppState,
+ state: &'a SessionState,
payment_intent: &'a storage::PaymentIntent,
payment_attempt: &storage::PaymentAttempt,
merchant_account: &domain::MerchantAccount,
@@ -799,7 +799,7 @@ pub async fn construct_upload_file_router_data<'a>(
#[instrument(skip_all)]
pub async fn construct_defend_dispute_router_data<'a>(
- state: &'a AppState,
+ state: &'a SessionState,
payment_intent: &'a storage::PaymentIntent,
payment_attempt: &storage::PaymentAttempt,
merchant_account: &domain::MerchantAccount,
@@ -895,7 +895,7 @@ pub async fn construct_defend_dispute_router_data<'a>(
#[instrument(skip_all)]
pub async fn construct_retrieve_file_router_data<'a>(
- state: &'a AppState,
+ state: &'a SessionState,
merchant_account: &domain::MerchantAccount,
key_store: &domain::MerchantKeyStore,
file_metadata: &diesel_models::file::FileMetadata,
diff --git a/crates/router/src/core/verification.rs b/crates/router/src/core/verification.rs
index 802a4ec3c6..b6e71b2828 100644
--- a/crates/router/src/core/verification.rs
+++ b/crates/router/src/core/verification.rs
@@ -4,12 +4,12 @@ use common_utils::{errors::CustomResult, request::RequestContent};
use error_stack::ResultExt;
use masking::ExposeInterface;
-use crate::{core::errors, headers, logger, routes::AppState, services};
+use crate::{core::errors, headers, logger, routes::SessionState, services};
const APPLEPAY_INTERNAL_MERCHANT_NAME: &str = "Applepay_merchant";
pub async fn verify_merchant_creds_for_applepay(
- state: AppState,
+ state: SessionState,
body: verifications::ApplepayMerchantVerificationRequest,
merchant_id: String,
) -> CustomResult<services::ApplicationResponse<ApplepayMerchantResponse>, errors::ApiErrorResponse>
@@ -83,7 +83,7 @@ pub async fn verify_merchant_creds_for_applepay(
}
pub async fn get_verified_apple_domains_with_mid_mca_id(
- state: AppState,
+ state: SessionState,
merchant_id: String,
merchant_connector_id: String,
) -> CustomResult<
diff --git a/crates/router/src/core/verification/utils.rs b/crates/router/src/core/verification/utils.rs
index 56960d3cb4..7518091ee8 100644
--- a/crates/router/src/core/verification/utils.rs
+++ b/crates/router/src/core/verification/utils.rs
@@ -4,13 +4,13 @@ use error_stack::{Report, ResultExt};
use crate::{
core::errors::{self, utils::StorageErrorExt},
logger,
- routes::AppState,
+ routes::SessionState,
types,
types::storage,
};
pub async fn check_existence_and_add_domain_to_db(
- state: &AppState,
+ state: &SessionState,
merchant_id: String,
merchant_connector_id: String,
domain_from_req: Vec<String>,
diff --git a/crates/router/src/core/verify_connector.rs b/crates/router/src/core/verify_connector.rs
index 8a8b0a14f7..f42f9336a1 100644
--- a/crates/router/src/core/verify_connector.rs
+++ b/crates/router/src/core/verify_connector.rs
@@ -13,11 +13,11 @@ use crate::{
transformers::ForeignInto,
},
utils::verify_connector as utils,
- AppState,
+ SessionState,
};
pub async fn verify_connector_credentials(
- state: AppState,
+ state: SessionState,
req: VerifyConnectorRequest,
) -> errors::RouterResponse<()> {
let boxed_connector = api::ConnectorData::get_connector_by_name(
diff --git a/crates/router/src/core/webhooks.rs b/crates/router/src/core/webhooks.rs
index c5055d4c8c..7962e86e12 100644
--- a/crates/router/src/core/webhooks.rs
+++ b/crates/router/src/core/webhooks.rs
@@ -39,10 +39,10 @@ use crate::{
},
logger,
routes::{
- app::{AppStateInfo, ReqState},
+ app::{ReqState, SessionStateInfo},
lock_utils,
metrics::request::add_attributes,
- AppState,
+ SessionState,
},
services::{self, authentication as auth},
types::{
@@ -59,7 +59,7 @@ const OUTGOING_WEBHOOK_TIMEOUT_SECS: u64 = 5;
const MERCHANT_ID: &str = "merchant_id";
pub async fn payments_incoming_webhook_flow(
- state: AppState,
+ state: SessionState,
req_state: ReqState,
merchant_account: domain::MerchantAccount,
business_profile: diesel_models::business_profile::BusinessProfile,
@@ -204,7 +204,7 @@ pub async fn payments_incoming_webhook_flow(
#[instrument(skip_all)]
#[allow(clippy::too_many_arguments)]
pub async fn refunds_incoming_webhook_flow(
- state: AppState,
+ state: SessionState,
merchant_account: domain::MerchantAccount,
business_profile: diesel_models::business_profile::BusinessProfile,
key_store: domain::MerchantKeyStore,
@@ -302,7 +302,7 @@ pub async fn refunds_incoming_webhook_flow(
}
pub async fn get_payment_attempt_from_object_reference_id(
- state: &AppState,
+ state: &SessionState,
object_reference_id: webhooks::ObjectReferenceId,
merchant_account: &domain::MerchantAccount,
) -> CustomResult<
@@ -342,7 +342,7 @@ pub async fn get_payment_attempt_from_object_reference_id(
#[allow(clippy::too_many_arguments)]
pub async fn get_or_update_dispute_object(
- state: AppState,
+ state: SessionState,
option_dispute: Option<diesel_models::dispute::Dispute>,
dispute_details: api::disputes::DisputePayload,
merchant_id: &str,
@@ -418,7 +418,7 @@ pub async fn get_or_update_dispute_object(
#[allow(clippy::too_many_arguments)]
pub async fn external_authentication_incoming_webhook_flow(
- state: AppState,
+ state: SessionState,
req_state: ReqState,
merchant_account: domain::MerchantAccount,
key_store: domain::MerchantKeyStore,
@@ -592,7 +592,7 @@ pub async fn external_authentication_incoming_webhook_flow(
}
pub async fn mandates_incoming_webhook_flow(
- state: AppState,
+ state: SessionState,
merchant_account: domain::MerchantAccount,
business_profile: diesel_models::business_profile::BusinessProfile,
key_store: domain::MerchantKeyStore,
@@ -680,7 +680,7 @@ pub async fn mandates_incoming_webhook_flow(
#[allow(clippy::too_many_arguments)]
#[instrument(skip_all)]
pub(crate) async fn frm_incoming_webhook_flow(
- state: AppState,
+ state: SessionState,
req_state: ReqState,
merchant_account: domain::MerchantAccount,
key_store: domain::MerchantKeyStore,
@@ -792,7 +792,7 @@ pub(crate) async fn frm_incoming_webhook_flow(
#[allow(clippy::too_many_arguments)]
#[instrument(skip_all)]
pub async fn disputes_incoming_webhook_flow(
- state: AppState,
+ state: SessionState,
merchant_account: domain::MerchantAccount,
business_profile: diesel_models::business_profile::BusinessProfile,
key_store: domain::MerchantKeyStore,
@@ -862,7 +862,7 @@ pub async fn disputes_incoming_webhook_flow(
}
async fn bank_transfer_webhook_flow(
- state: AppState,
+ state: SessionState,
req_state: ReqState,
merchant_account: domain::MerchantAccount,
business_profile: diesel_models::business_profile::BusinessProfile,
@@ -951,7 +951,7 @@ async fn bank_transfer_webhook_flow(
#[allow(clippy::too_many_arguments)]
#[instrument(skip_all)]
pub(crate) async fn create_event_and_trigger_outgoing_webhook(
- state: AppState,
+ state: SessionState,
merchant_account: domain::MerchantAccount,
business_profile: diesel_models::business_profile::BusinessProfile,
merchant_key_store: &domain::MerchantKeyStore,
@@ -1091,7 +1091,7 @@ pub(crate) async fn create_event_and_trigger_outgoing_webhook(
#[allow(clippy::too_many_arguments)]
#[instrument(skip_all)]
pub(crate) async fn trigger_webhook_and_raise_event(
- state: AppState,
+ state: SessionState,
business_profile: diesel_models::business_profile::BusinessProfile,
merchant_key_store: &domain::MerchantKeyStore,
event: domain::Event,
@@ -1123,7 +1123,7 @@ pub(crate) async fn trigger_webhook_and_raise_event(
}
async fn trigger_webhook_to_merchant(
- state: AppState,
+ state: SessionState,
business_profile: diesel_models::business_profile::BusinessProfile,
merchant_key_store: &domain::MerchantKeyStore,
event: domain::Event,
@@ -1189,7 +1189,7 @@ async fn trigger_webhook_to_merchant(
logger::debug!(outgoing_webhook_response=?response);
let update_event_if_client_error =
- |state: AppState,
+ |state: SessionState,
merchant_key_store: domain::MerchantKeyStore,
merchant_id: String,
event_id: String,
@@ -1234,7 +1234,7 @@ async fn trigger_webhook_to_merchant(
};
let api_client_error_handler =
- |state: AppState,
+ |state: SessionState,
merchant_key_store: domain::MerchantKeyStore,
merchant_id: String,
event_id: String,
@@ -1261,7 +1261,7 @@ async fn trigger_webhook_to_merchant(
Ok::<_, error_stack::Report<errors::WebhooksFlowError>>(())
};
- let update_event_in_storage = |state: AppState,
+ let update_event_in_storage = |state: SessionState,
merchant_key_store: domain::MerchantKeyStore,
merchant_id: String,
event_id: String,
@@ -1339,7 +1339,7 @@ async fn trigger_webhook_to_merchant(
)
};
let success_response_handler =
- |state: AppState,
+ |state: SessionState,
merchant_id: String,
process_tracker: Option<storage::ProcessTracker>,
business_status: &'static str| async move {
@@ -1521,7 +1521,7 @@ async fn trigger_webhook_to_merchant(
}
fn raise_webhooks_analytics_event(
- state: AppState,
+ state: SessionState,
trigger_webhook_result: CustomResult<(), errors::WebhooksFlowError>,
content: Option<api::OutgoingWebhookContent>,
merchant_id: String,
@@ -1558,7 +1558,7 @@ fn raise_webhooks_analytics_event(
#[allow(clippy::too_many_arguments)]
pub async fn webhooks_wrapper<W: types::OutgoingWebhookType>(
flow: &impl router_env::types::FlowMetric,
- state: AppState,
+ state: SessionState,
req_state: ReqState,
req: &actix_web::HttpRequest,
merchant_account: domain::MerchantAccount,
@@ -1622,7 +1622,7 @@ pub async fn webhooks_wrapper<W: types::OutgoingWebhookType>(
#[instrument(skip_all)]
pub async fn webhooks_core<W: types::OutgoingWebhookType>(
- state: AppState,
+ state: SessionState,
req_state: ReqState,
req: &actix_web::HttpRequest,
merchant_account: domain::MerchantAccount,
@@ -2019,7 +2019,7 @@ pub async fn get_payment_id(
}
fn get_connector_by_connector_name(
- state: &AppState,
+ state: &SessionState,
connector_name: &str,
merchant_connector_id: Option<String>,
) -> CustomResult<(&'static (dyn api::Connector + Sync), String), errors::ApiErrorResponse> {
@@ -2067,7 +2067,7 @@ fn get_connector_by_connector_name(
/// This function fetches the merchant connector account ( if the url used is /{merchant_connector_id})
/// if merchant connector id is not passed in the request, then this will return None for mca
async fn fetch_optional_mca_and_connector(
- state: &AppState,
+ state: &SessionState,
merchant_account: &domain::MerchantAccount,
connector_name_or_mca_id: &str,
key_store: &domain::MerchantKeyStore,
diff --git a/crates/router/src/core/webhooks/webhook_events.rs b/crates/router/src/core/webhooks/webhook_events.rs
index f248edd652..2cb16a53b3 100644
--- a/crates/router/src/core/webhooks/webhook_events.rs
+++ b/crates/router/src/core/webhooks/webhook_events.rs
@@ -4,7 +4,7 @@ use router_env::{instrument, tracing};
use crate::{
core::errors::{self, RouterResponse, StorageErrorExt},
- routes::AppState,
+ routes::SessionState,
services::ApplicationResponse,
types::{api, domain, storage, transformers::ForeignTryFrom},
utils::{OptionExt, StringExt},
@@ -20,7 +20,7 @@ enum MerchantAccountOrBusinessProfile {
#[instrument(skip(state))]
pub async fn list_initial_delivery_attempts(
- state: AppState,
+ state: SessionState,
merchant_id_or_profile_id: String,
constraints: api::webhook_events::EventListConstraints,
) -> RouterResponse<Vec<api::webhook_events::EventListItemResponse>> {
@@ -108,7 +108,7 @@ pub async fn list_initial_delivery_attempts(
#[instrument(skip(state))]
pub async fn list_delivery_attempts(
- state: AppState,
+ state: SessionState,
merchant_id_or_profile_id: String,
initial_attempt_id: String,
) -> RouterResponse<Vec<api::webhook_events::EventRetrieveResponse>> {
@@ -157,7 +157,7 @@ pub async fn list_delivery_attempts(
#[instrument(skip(state))]
pub async fn retry_delivery_attempt(
- state: AppState,
+ state: SessionState,
merchant_id_or_profile_id: String,
event_id: String,
) -> RouterResponse<api::webhook_events::EventRetrieveResponse> {
@@ -254,7 +254,7 @@ pub async fn retry_delivery_attempt(
}
async fn determine_identifier_and_get_key_store(
- state: AppState,
+ state: SessionState,
merchant_id_or_profile_id: String,
) -> errors::RouterResult<(MerchantAccountOrBusinessProfile, domain::MerchantKeyStore)> {
let store = state.store.as_ref();
diff --git a/crates/router/src/db/api_keys.rs b/crates/router/src/db/api_keys.rs
index 5d2f1c57a2..ea63a88170 100644
--- a/crates/router/src/db/api_keys.rs
+++ b/crates/router/src/db/api_keys.rs
@@ -373,7 +373,7 @@ impl ApiKeyInterface for MockDb {
#[cfg(test)]
mod tests {
use storage_impl::redis::{
- cache::{self, CacheKind, ACCOUNTS_CACHE},
+ cache::{self, CacheKey, CacheKind, ACCOUNTS_CACHE},
kv_store::RedisConnInterface,
pub_sub::PubSubInterface,
};
@@ -525,15 +525,12 @@ mod tests {
.await
.unwrap();
- assert!(
- ACCOUNTS_CACHE
- .get_val::<storage::ApiKey>(&format!(
- "{}_{}",
- merchant_id,
- hashed_api_key.into_inner()
- ),)
- .await
- .is_none()
- )
+ assert!(ACCOUNTS_CACHE
+ .get_val::<storage::ApiKey>(CacheKey {
+ key: format!("{}_{}", merchant_id, hashed_api_key.into_inner()),
+ prefix: String::default(),
+ },)
+ .await
+ .is_none())
}
}
diff --git a/crates/router/src/db/kafka_store.rs b/crates/router/src/db/kafka_store.rs
index 0e3b365ae0..910ad085f6 100644
--- a/crates/router/src/db/kafka_store.rs
+++ b/crates/router/src/db/kafka_store.rs
@@ -1098,8 +1098,9 @@ impl QueueInterface for KafkaStore {
entry_id: &RedisEntryId,
fields: Vec<(&str, String)>,
) -> CustomResult<(), RedisError> {
+ let stream_name = format!("{}_{}", &self.tenant_id.0, stream);
self.diesel_store
- .stream_append_entry(stream, entry_id, fields)
+ .stream_append_entry(&stream_name, entry_id, fields)
.await
}
diff --git a/crates/router/src/db/merchant_connector_account.rs b/crates/router/src/db/merchant_connector_account.rs
index b0f57367db..aea37b517b 100644
--- a/crates/router/src/db/merchant_connector_account.rs
+++ b/crates/router/src/db/merchant_connector_account.rs
@@ -769,7 +769,7 @@ mod merchant_connector_account_cache_tests {
use error_stack::ResultExt;
use masking::PeekInterface;
use storage_impl::redis::{
- cache::{self, CacheKind, ACCOUNTS_CACHE},
+ cache::{self, CacheKey, CacheKind, ACCOUNTS_CACHE},
kv_store::RedisConnInterface,
pub_sub::PubSubInterface,
};
@@ -902,10 +902,10 @@ mod merchant_connector_account_cache_tests {
.unwrap();
assert!(ACCOUNTS_CACHE
- .get_val::<domain::MerchantConnectorAccount>(&format!(
- "{}_{}",
- merchant_id, connector_label
- ),)
+ .get_val::<domain::MerchantConnectorAccount>(CacheKey {
+ key: format!("{}_{}", merchant_id, connector_label),
+ prefix: String::default(),
+ },)
.await
.is_none())
}
diff --git a/crates/router/src/lib.rs b/crates/router/src/lib.rs
index 2e9ecc13dc..7344b85d15 100644
--- a/crates/router/src/lib.rs
+++ b/crates/router/src/lib.rs
@@ -32,7 +32,7 @@ use actix_web::{
use http::StatusCode;
use hyperswitch_interfaces::secrets_interface::secret_state::SecuredSecret;
use router_env::tracing::Instrument;
-use routes::AppState;
+use routes::{AppState, SessionState};
use storage_impl::errors::ApplicationResult;
use tokio::sync::{mpsc, oneshot};
diff --git a/crates/router/src/routes.rs b/crates/router/src/routes.rs
index cd216cb0e8..9f13635ca9 100644
--- a/crates/router/src/routes.rs
+++ b/crates/router/src/routes.rs
@@ -60,7 +60,8 @@ pub use self::app::Recon;
pub use self::app::{
ApiKeys, AppState, BusinessProfile, Cache, Cards, Configs, ConnectorOnboarding, Customers,
Disputes, EphemeralKey, Files, Gsm, Health, Mandates, MerchantAccount,
- MerchantConnectorAccount, PaymentLink, PaymentMethods, Payments, Poll, Refunds, User, Webhooks,
+ MerchantConnectorAccount, PaymentLink, PaymentMethods, Payments, Poll, Refunds, SessionState,
+ User, Webhooks,
};
#[cfg(feature = "olap")]
pub use self::app::{Blocklist, Routing, Verify, WebhookEvents};
diff --git a/crates/router/src/routes/app.rs b/crates/router/src/routes/app.rs
index a7d17e602d..5af3a2bef2 100644
--- a/crates/router/src/routes/app.rs
+++ b/crates/router/src/routes/app.rs
@@ -1,4 +1,4 @@
-use std::sync::Arc;
+use std::{collections::HashMap, sync::Arc};
use actix_web::{web, Scope};
#[cfg(all(feature = "business_profile_routing", feature = "olap"))]
@@ -14,7 +14,7 @@ use hyperswitch_interfaces::{
};
use router_env::tracing_actix_web::RequestId;
use scheduler::SchedulerInterface;
-use storage_impl::MockDb;
+use storage_impl::{config::TenantConfig, redis::RedisStore, MockDb};
use tokio::sync::oneshot;
#[cfg(feature = "olap")]
@@ -43,7 +43,8 @@ use super::{ephemeral_key::*, webhooks::*};
use super::{pm_auth, poll::retrieve_poll_status};
#[cfg(feature = "olap")]
pub use crate::analytics::opensearch::OpenSearchClient;
-use crate::configs::secrets_transformers;
+#[cfg(feature = "olap")]
+use crate::analytics::AnalyticsProvider;
#[cfg(all(feature = "frm", feature = "oltp"))]
use crate::routes::fraud_check as frm_routes;
#[cfg(all(feature = "recon", feature = "olap"))]
@@ -56,7 +57,11 @@ pub use crate::{
db::{StorageImpl, StorageInterface},
events::EventsHandler,
routes::cards_info::card_iin_info,
- services::get_store,
+ services::{get_cache_store, get_store},
+};
+use crate::{
+ configs::{secrets_transformers, Settings},
+ db::kafka_store::{KafkaStore, TenantID},
};
#[derive(Clone)]
@@ -64,33 +69,87 @@ pub struct ReqState {
pub event_context: events::EventContext<crate::events::EventType, EventsHandler>,
}
+#[derive(Clone)]
+pub struct SessionState {
+ pub store: Box<dyn StorageInterface>,
+ pub conf: Arc<settings::Settings<RawSecret>>,
+ pub api_client: Box<dyn crate::services::ApiClient>,
+ pub event_handler: EventsHandler,
+ #[cfg(feature = "email")]
+ pub email_client: Arc<dyn EmailService>,
+ #[cfg(feature = "olap")]
+ pub pool: AnalyticsProvider,
+ pub file_storage_client: Box<dyn FileStorageInterface>,
+ pub request_id: Option<RequestId>,
+ pub base_url: String,
+ pub tenant: String,
+ #[cfg(feature = "olap")]
+ pub opensearch_client: Arc<OpenSearchClient>,
+}
+impl scheduler::SchedulerSessionState for SessionState {
+ fn get_db(&self) -> Box<dyn SchedulerInterface> {
+ self.store.get_scheduler_db()
+ }
+}
+impl SessionState {
+ pub fn get_req_state(&self) -> ReqState {
+ ReqState {
+ event_context: events::EventContext::new(self.event_handler.clone()),
+ }
+ }
+}
+
+pub trait SessionStateInfo {
+ fn conf(&self) -> settings::Settings<RawSecret>;
+ fn store(&self) -> Box<dyn StorageInterface>;
+ fn event_handler(&self) -> EventsHandler;
+ fn get_request_id(&self) -> Option<String>;
+ fn add_request_id(&mut self, request_id: RequestId);
+}
+
+impl SessionStateInfo for SessionState {
+ fn store(&self) -> Box<dyn StorageInterface> {
+ self.store.to_owned()
+ }
+ fn conf(&self) -> settings::Settings<RawSecret> {
+ self.conf.as_ref().to_owned()
+ }
+ fn event_handler(&self) -> EventsHandler {
+ self.event_handler.clone()
+ }
+ fn get_request_id(&self) -> Option<String> {
+ self.api_client.get_request_id()
+ }
+ fn add_request_id(&mut self, request_id: RequestId) {
+ self.api_client.add_request_id(request_id);
+ self.store.add_request_id(request_id.to_string());
+ self.request_id.replace(request_id);
+ }
+}
#[derive(Clone)]
pub struct AppState {
pub flow_name: String,
- pub store: Box<dyn StorageInterface>,
+ pub stores: HashMap<String, Box<dyn StorageInterface>>,
pub conf: Arc<settings::Settings<RawSecret>>,
pub event_handler: EventsHandler,
#[cfg(feature = "email")]
pub email_client: Arc<dyn EmailService>,
pub api_client: Box<dyn crate::services::ApiClient>,
#[cfg(feature = "olap")]
- pub pool: crate::analytics::AnalyticsProvider,
+ pub pools: HashMap<String, AnalyticsProvider>,
#[cfg(feature = "olap")]
- pub opensearch_client: OpenSearchClient,
+ pub opensearch_client: Arc<OpenSearchClient>,
pub request_id: Option<RequestId>,
pub file_storage_client: Box<dyn FileStorageInterface>,
pub encryption_client: Box<dyn EncryptionManagementInterface>,
}
-
impl scheduler::SchedulerAppState for AppState {
- fn get_db(&self) -> Box<dyn SchedulerInterface> {
- self.store.get_scheduler_db()
+ fn get_tenants(&self) -> Vec<String> {
+ self.conf.multitenancy.get_tenant_names()
}
}
-
pub trait AppStateInfo {
fn conf(&self) -> settings::Settings<RawSecret>;
- fn store(&self) -> Box<dyn StorageInterface>;
fn event_handler(&self) -> EventsHandler;
#[cfg(feature = "email")]
fn email_client(&self) -> Arc<dyn EmailService>;
@@ -104,9 +163,6 @@ impl AppStateInfo for AppState {
fn conf(&self) -> settings::Settings<RawSecret> {
self.conf.as_ref().to_owned()
}
- fn store(&self) -> Box<dyn StorageInterface> {
- self.store.to_owned()
- }
#[cfg(feature = "email")]
fn email_client(&self) -> Arc<dyn EmailService> {
self.email_client.to_owned()
@@ -116,7 +172,6 @@ impl AppStateInfo for AppState {
}
fn add_request_id(&mut self, request_id: RequestId) {
self.api_client.add_request_id(request_id);
- self.store.add_request_id(request_id.to_string());
self.request_id.replace(request_id);
}
@@ -183,43 +238,38 @@ impl AppState {
#[allow(clippy::expect_used)]
#[cfg(feature = "olap")]
- let opensearch_client = conf
- .opensearch
- .get_opensearch_client()
- .await
- .expect("Failed to create opensearch client");
-
- let store: Box<dyn StorageInterface> = match storage_impl {
- StorageImpl::Postgresql | StorageImpl::PostgresqlTest => match &event_handler {
- EventsHandler::Kafka(kafka_client) => Box::new(
- crate::db::KafkaStore::new(
- #[allow(clippy::expect_used)]
- get_store(&conf.clone(), shut_down_signal, testable)
- .await
- .expect("Failed to create store"),
- kafka_client.clone(),
- crate::db::kafka_store::TenantID("default".to_string()),
- )
- .await,
- ),
- EventsHandler::Logs(_) => Box::new(
- #[allow(clippy::expect_used)]
- get_store(&conf, shut_down_signal, testable)
- .await
- .expect("Failed to create store"),
- ),
- },
- #[allow(clippy::expect_used)]
- StorageImpl::Mock => Box::new(
- MockDb::new(&conf.redis)
- .await
- .expect("Failed to create mock store"),
- ),
- };
+ let opensearch_client = Arc::new(
+ conf.opensearch
+ .get_opensearch_client()
+ .await
+ .expect("Failed to create opensearch client"),
+ );
#[cfg(feature = "olap")]
- let pool =
- crate::analytics::AnalyticsProvider::from_conf(conf.analytics.get_inner()).await;
+ let mut pools: HashMap<String, AnalyticsProvider> = HashMap::new();
+ let mut stores = HashMap::new();
+ #[allow(clippy::expect_used)]
+ let cache_store = get_cache_store(&conf.clone(), shut_down_signal, testable)
+ .await
+ .expect("Failed to create store");
+ for (tenant_name, tenant) in conf.clone().multitenancy.get_tenants() {
+ let store: Box<dyn StorageInterface> = Self::get_store_interface(
+ &storage_impl,
+ &event_handler,
+ &conf,
+ tenant,
+ Arc::clone(&cache_store),
+ testable,
+ )
+ .await;
+ stores.insert(tenant_name.clone(), store);
+ #[cfg(feature = "olap")]
+ let pool =
+ AnalyticsProvider::from_conf(conf.analytics.get_inner(), tenant_name.as_str())
+ .await;
+ #[cfg(feature = "olap")]
+ pools.insert(tenant_name.clone(), pool);
+ }
#[cfg(feature = "email")]
let email_client = Arc::new(create_email_client(&conf).await);
@@ -228,14 +278,14 @@ impl AppState {
Self {
flow_name: String::from("default"),
- store,
+ stores,
conf: Arc::new(conf),
#[cfg(feature = "email")]
email_client,
api_client,
event_handler,
#[cfg(feature = "olap")]
- pool,
+ pools,
#[cfg(feature = "olap")]
opensearch_client,
request_id: None,
@@ -246,6 +296,43 @@ impl AppState {
.await
}
+ async fn get_store_interface(
+ storage_impl: &StorageImpl,
+ event_handler: &EventsHandler,
+ conf: &Settings,
+ tenant: &settings::Tenant,
+ cache_store: Arc<RedisStore>,
+ testable: bool,
+ ) -> Box<dyn StorageInterface> {
+ match storage_impl {
+ StorageImpl::Postgresql | StorageImpl::PostgresqlTest => match event_handler {
+ EventsHandler::Kafka(kafka_client) => Box::new(
+ KafkaStore::new(
+ #[allow(clippy::expect_used)]
+ get_store(&conf.clone(), tenant, Arc::clone(&cache_store), testable)
+ .await
+ .expect("Failed to create store"),
+ kafka_client.clone(),
+ TenantID(tenant.get_schema().to_string()),
+ )
+ .await,
+ ),
+ EventsHandler::Logs(_) => Box::new(
+ #[allow(clippy::expect_used)]
+ get_store(conf, tenant, Arc::clone(&cache_store), testable)
+ .await
+ .expect("Failed to create store"),
+ ),
+ },
+ #[allow(clippy::expect_used)]
+ StorageImpl::Mock => Box::new(
+ MockDb::new(&conf.redis)
+ .await
+ .expect("Failed to create mock store"),
+ ),
+ }
+ }
+
pub async fn new(
conf: settings::Settings<SecuredSecret>,
shut_down_signal: oneshot::Sender<()>,
@@ -265,6 +352,34 @@ impl AppState {
event_context: events::EventContext::new(self.event_handler.clone()),
}
}
+ pub fn get_session_state<E, F>(self: Arc<Self>, tenant: &str, err: F) -> Result<SessionState, E>
+ where
+ F: FnOnce() -> E + Copy,
+ {
+ Ok(SessionState {
+ store: self.stores.get(tenant).ok_or_else(err)?.clone(),
+ conf: Arc::clone(&self.conf),
+ api_client: self.api_client.clone(),
+ event_handler: self.event_handler.clone(),
+ #[cfg(feature = "olap")]
+ pool: self.pools.get(tenant).ok_or_else(err)?.clone(),
+ file_storage_client: self.file_storage_client.clone(),
+ request_id: self.request_id,
+ base_url: self
+ .conf
+ .multitenancy
+ .get_tenant(tenant)
+ .ok_or_else(err)?
+ .clone()
+ .base_url
+ .clone(),
+ tenant: tenant.to_string().clone(),
+ #[cfg(feature = "email")]
+ email_client: Arc::clone(&self.email_client),
+ #[cfg(feature = "olap")]
+ opensearch_client: Arc::clone(&self.opensearch_client),
+ })
+ }
}
pub struct Health;
diff --git a/crates/router/src/routes/customers.rs b/crates/router/src/routes/customers.rs
index 4d86ae829e..87366cf5c6 100644
--- a/crates/router/src/routes/customers.rs
+++ b/crates/router/src/routes/customers.rs
@@ -47,7 +47,7 @@ pub async fn customers_retrieve(
let auth = if auth::is_jwt_auth(req.headers()) {
Box::new(auth::JWTAuth(Permission::CustomerRead))
} else {
- match auth::is_ephemeral_auth(req.headers(), &*state.store, &payload.customer_id).await {
+ match auth::is_ephemeral_auth(req.headers(), &payload.customer_id) {
Ok(auth) => auth,
Err(err) => return api::log_and_return_error_response(err),
}
diff --git a/crates/router/src/routes/dummy_connector/core.rs b/crates/router/src/routes/dummy_connector/core.rs
index e8f84b3047..513a586d19 100644
--- a/crates/router/src/routes/dummy_connector/core.rs
+++ b/crates/router/src/routes/dummy_connector/core.rs
@@ -1,4 +1,4 @@
-use app::AppState;
+use app::SessionState;
use common_utils::generate_id_with_default_len;
use error_stack::ResultExt;
@@ -10,7 +10,7 @@ use crate::{
};
pub async fn payment(
- state: AppState,
+ state: SessionState,
req: types::DummyConnectorPaymentRequest,
) -> types::DummyConnectorResponse<types::DummyConnectorPaymentResponse> {
utils::tokio_mock_sleep(
@@ -41,7 +41,7 @@ pub async fn payment(
}
pub async fn payment_data(
- state: AppState,
+ state: SessionState,
req: types::DummyConnectorPaymentRetrieveRequest,
) -> types::DummyConnectorResponse<types::DummyConnectorPaymentResponse> {
utils::tokio_mock_sleep(
@@ -55,7 +55,7 @@ pub async fn payment_data(
}
pub async fn payment_authorize(
- state: AppState,
+ state: SessionState,
req: types::DummyConnectorPaymentConfirmRequest,
) -> types::DummyConnectorResponse<String> {
let payment_data = utils::get_payment_data_by_attempt_id(&state, req.attempt_id.clone()).await;
@@ -64,7 +64,7 @@ pub async fn payment_authorize(
if let Ok(payment_data_inner) = payment_data {
let return_url = format!(
"{}/dummy-connector/complete/{}",
- state.conf.server.base_url, req.attempt_id
+ state.base_url, req.attempt_id
);
Ok(api::ApplicationResponse::FileData((
utils::get_authorize_page(payment_data_inner, return_url, dummy_connector_conf)
@@ -83,7 +83,7 @@ pub async fn payment_authorize(
}
pub async fn payment_complete(
- state: AppState,
+ state: SessionState,
req: types::DummyConnectorPaymentCompleteRequest,
) -> types::DummyConnectorResponse<()> {
utils::tokio_mock_sleep(
@@ -145,7 +145,7 @@ pub async fn payment_complete(
}
pub async fn refund_payment(
- state: AppState,
+ state: SessionState,
req: types::DummyConnectorRefundRequest,
) -> types::DummyConnectorResponse<types::DummyConnectorRefundResponse> {
utils::tokio_mock_sleep(
@@ -197,7 +197,7 @@ pub async fn refund_payment(
}
pub async fn refund_data(
- state: AppState,
+ state: SessionState,
req: types::DummyConnectorRefundRetrieveRequest,
) -> types::DummyConnectorResponse<types::DummyConnectorRefundResponse> {
let refund_id = req.refund_id;
diff --git a/crates/router/src/routes/dummy_connector/utils.rs b/crates/router/src/routes/dummy_connector/utils.rs
index 8bba182ad0..6211c3abf8 100644
--- a/crates/router/src/routes/dummy_connector/utils.rs
+++ b/crates/router/src/routes/dummy_connector/utils.rs
@@ -11,7 +11,7 @@ use super::{
consts, errors,
types::{self, GetPaymentMethodDetails},
};
-use crate::{configs::settings, routes::AppState};
+use crate::{configs::settings, routes::SessionState};
pub async fn tokio_mock_sleep(delay: u64, tolerance: u64) {
let mut rng = rand::thread_rng();
@@ -26,7 +26,7 @@ pub async fn tokio_mock_sleep(delay: u64, tolerance: u64) {
}
pub async fn store_data_in_redis(
- state: &AppState,
+ state: &SessionState,
key: String,
data: impl serde::Serialize + Debug,
ttl: i64,
@@ -46,7 +46,7 @@ pub async fn store_data_in_redis(
}
pub async fn get_payment_data_from_payment_id(
- state: &AppState,
+ state: &SessionState,
payment_id: String,
) -> types::DummyConnectorResult<types::DummyConnectorPaymentData> {
let redis_conn = state
@@ -65,7 +65,7 @@ pub async fn get_payment_data_from_payment_id(
}
pub async fn get_payment_data_by_attempt_id(
- state: &AppState,
+ state: &SessionState,
attempt_id: String,
) -> types::DummyConnectorResult<types::DummyConnectorPaymentData> {
let redis_conn = state
@@ -336,12 +336,12 @@ impl ProcessPaymentAttempt for types::DummyConnectorPaymentMethodData {
impl types::DummyConnectorPaymentData {
pub fn process_payment_attempt(
- state: &AppState,
+ state: &SessionState,
payment_attempt: types::DummyConnectorPaymentAttempt,
) -> types::DummyConnectorResult<Self> {
let redirect_url = format!(
"{}/dummy-connector/authorize/{}",
- state.conf.server.base_url, payment_attempt.attempt_id
+ state.base_url, payment_attempt.attempt_id
);
payment_attempt
.clone()
diff --git a/crates/router/src/routes/health.rs b/crates/router/src/routes/health.rs
index 7d35a91a31..721dbd6a78 100644
--- a/crates/router/src/routes/health.rs
+++ b/crates/router/src/routes/health.rs
@@ -40,7 +40,9 @@ pub async fn deep_health_check(
.await
}
-async fn deep_health_check_func(state: app::AppState) -> RouterResponse<RouterHealthCheckResponse> {
+async fn deep_health_check_func(
+ state: app::SessionState,
+) -> RouterResponse<RouterHealthCheckResponse> {
logger::info!("Deep health check was called");
logger::debug!("Database health check begin");
diff --git a/crates/router/src/routes/payment_methods.rs b/crates/router/src/routes/payment_methods.rs
index 96daf95d11..e36a8fc3ea 100644
--- a/crates/router/src/routes/payment_methods.rs
+++ b/crates/router/src/routes/payment_methods.rs
@@ -5,7 +5,7 @@ use error_stack::ResultExt;
use router_env::{instrument, logger, tracing, Flow};
use time::PrimitiveDateTime;
-use super::app::AppState;
+use super::app::{AppState, SessionState};
use crate::{
core::{api_locking, errors, payment_methods::cards},
services::{api, authentication as auth, authorization::permissions::Permission},
@@ -139,11 +139,10 @@ pub async fn list_customer_payment_method_api(
let payload = query_payload.into_inner();
let customer_id = customer_id.into_inner().0;
- let ephemeral_auth =
- match auth::is_ephemeral_auth(req.headers(), &*state.store, &customer_id).await {
- Ok(auth) => auth,
- Err(err) => return api::log_and_return_error_response(err),
- };
+ let ephemeral_auth = match auth::is_ephemeral_auth(req.headers(), &customer_id) {
+ Ok(auth) => auth,
+ Err(err) => return api::log_and_return_error_response(err),
+ };
Box::pin(api::server_wrap(
flow,
state,
@@ -343,28 +342,28 @@ pub async fn default_payment_method_set_api(
) -> HttpResponse {
let flow = Flow::DefaultPaymentMethodsSet;
let payload = path.into_inner();
- let customer_id = payload.clone().customer_id;
+ let pc = payload.clone();
+ let customer_id = &pc.customer_id;
- let ephemeral_auth =
- match auth::is_ephemeral_auth(req.headers(), &*state.store, &customer_id).await {
- Ok(auth) => auth,
- Err(err) => return api::log_and_return_error_response(err),
- };
- let db = &*state.store.clone();
+ let ephemeral_auth = match auth::is_ephemeral_auth(req.headers(), customer_id) {
+ Ok(auth) => auth,
+ Err(err) => return api::log_and_return_error_response(err),
+ };
Box::pin(api::server_wrap(
flow,
state,
&req,
payload,
- |_state, auth: auth::AuthenticationData, default_payment_method, _| {
+ |state, auth: auth::AuthenticationData, default_payment_method, _| async move {
cards::set_default_payment_method(
- db,
+ &*state.clone().store,
auth.merchant_account.merchant_id,
auth.key_store,
- &customer_id,
+ customer_id,
default_payment_method.payment_method_id,
auth.merchant_account.storage_scheme,
)
+ .await
},
&*ephemeral_auth,
api_locking::LockAction::NotApplicable,
@@ -416,7 +415,7 @@ impl ParentPaymentMethodToken {
&self,
intent_created_at: Option<PrimitiveDateTime>,
token: PaymentTokenData,
- state: &AppState,
+ state: &SessionState,
) -> CustomResult<(), errors::ApiErrorResponse> {
let token_json_str = token
.encode_to_string_of_json()
@@ -452,7 +451,7 @@ impl ParentPaymentMethodToken {
.contains(&status)
}
- pub async fn delete(&self, state: &AppState) -> CustomResult<(), errors::ApiErrorResponse> {
+ pub async fn delete(&self, state: &SessionState) -> CustomResult<(), errors::ApiErrorResponse> {
let redis_conn = state
.store
.get_redis_conn()
diff --git a/crates/router/src/routes/payments.rs b/crates/router/src/routes/payments.rs
index ab6b0f450d..a89410a2b0 100644
--- a/crates/router/src/routes/payments.rs
+++ b/crates/router/src/routes/payments.rs
@@ -681,6 +681,7 @@ pub async fn payments_redirect_response(
auth.merchant_account,
auth.key_store,
req,
+
)
},
&auth::MerchantIdAuth(merchant_id),
@@ -742,6 +743,7 @@ pub async fn payments_redirect_response_with_creds_identifier(
auth.merchant_account,
auth.key_store,
req,
+
)
},
&auth::MerchantIdAuth(merchant_id),
@@ -786,6 +788,7 @@ pub async fn payments_complete_authorize_redirect(
auth.merchant_account,
auth.key_store,
req,
+
)
},
&auth::MerchantIdAuth(merchant_id),
@@ -1142,7 +1145,7 @@ pub async fn payments_reject(
#[allow(clippy::too_many_arguments)]
async fn authorize_verify_select<Op>(
operation: Op,
- state: app::AppState,
+ state: app::SessionState,
req_state: ReqState,
merchant_account: domain::MerchantAccount,
key_store: domain::MerchantKeyStore,
diff --git a/crates/router/src/routes/recon.rs b/crates/router/src/routes/recon.rs
index fc0794ff9e..053037b57a 100644
--- a/crates/router/src/routes/recon.rs
+++ b/crates/router/src/routes/recon.rs
@@ -4,7 +4,7 @@ use error_stack::ResultExt;
use masking::{ExposeInterface, PeekInterface, Secret};
use router_env::Flow;
-use super::AppState;
+use super::{AppState, SessionState};
use crate::{
core::{
api_locking,
@@ -70,7 +70,7 @@ pub async fn get_recon_token(state: web::Data<AppState>, req: HttpRequest) -> Ht
}
pub async fn send_recon_request(
- state: AppState,
+ state: SessionState,
user: UserFromToken,
) -> RouterResponse<recon_api::ReconStatusResponse> {
let db = &*state.store;
@@ -150,7 +150,7 @@ pub async fn send_recon_request(
}
pub async fn recon_merchant_account_update(
- state: AppState,
+ state: SessionState,
req: recon_api::ReconUpdateMerchantRequest,
) -> RouterResponse<api_types::MerchantAccountResponse> {
let merchant_id = &req.merchant_id.clone();
@@ -217,7 +217,7 @@ pub async fn recon_merchant_account_update(
}
pub async fn generate_recon_token(
- state: AppState,
+ state: SessionState,
req: ReconUser,
) -> RouterResponse<recon_api::ReconTokenResponse> {
let db = &*state.store;
@@ -243,7 +243,7 @@ pub async fn generate_recon_token(
pub async fn get_recon_auth_token(
user: UserFromStorage,
- state: AppState,
+ state: SessionState,
) -> RouterResult<Secret<String>> {
ReconToken::new_token(user.0.user_id.clone(), &state.conf).await
}
diff --git a/crates/router/src/services.rs b/crates/router/src/services.rs
index bb50e27b8c..5c860aa8a6 100644
--- a/crates/router/src/services.rs
+++ b/crates/router/src/services.rs
@@ -13,12 +13,14 @@ pub mod recon;
#[cfg(feature = "email")]
pub mod email;
+use std::sync::Arc;
+
use error_stack::ResultExt;
use hyperswitch_domain_models::errors::StorageResult;
use masking::{ExposeInterface, StrongSecret};
#[cfg(feature = "kv_store")]
use storage_impl::KVRouterStore;
-use storage_impl::RouterStore;
+use storage_impl::{redis::RedisStore, RouterStore};
use tokio::sync::oneshot;
pub use self::{api::*, encryption::*};
@@ -40,7 +42,8 @@ pub type Store = KVRouterStore<StoreType>;
#[allow(clippy::expect_used)]
pub async fn get_store(
config: &Settings,
- shut_down_signal: oneshot::Sender<()>,
+ tenant: &crate::configs::settings::Tenant,
+ cache_store: Arc<RedisStore>,
test_transaction: bool,
) -> StorageResult<Store> {
let master_config = config.master_database.clone().into_inner();
@@ -61,13 +64,13 @@ pub async fn get_store(
let conf = (master_config.into(), replica_config.into());
let store: RouterStore<StoreType> = if test_transaction {
- RouterStore::test_store(conf, &config.redis, master_enc_key).await?
+ RouterStore::test_store(conf, tenant, &config.redis, master_enc_key).await?
} else {
RouterStore::from_config(
conf,
- &config.redis,
+ tenant,
master_enc_key,
- shut_down_signal,
+ cache_store,
storage_impl::redis::cache::PUB_SUB_CHANNEL,
)
.await?
@@ -85,6 +88,15 @@ pub async fn get_store(
Ok(store)
}
+#[allow(clippy::expect_used)]
+pub async fn get_cache_store(
+ config: &Settings,
+ shut_down_signal: oneshot::Sender<()>,
+ _test_transaction: bool,
+) -> StorageResult<Arc<RedisStore>> {
+ RouterStore::<StoreType>::cache_store(&config.redis, shut_down_signal).await
+}
+
#[inline]
pub fn generate_aes256_key() -> errors::CustomResult<[u8; 32], common_utils::errors::CryptoError> {
use ring::rand::SecureRandom;
diff --git a/crates/router/src/services/api.rs b/crates/router/src/services/api.rs
index 5f69a9d403..098060e144 100644
--- a/crates/router/src/services/api.rs
+++ b/crates/router/src/services/api.rs
@@ -1,14 +1,16 @@
pub mod client;
pub mod request;
use std::{
- collections::HashMap,
+ collections::{HashMap, HashSet},
error::Error,
fmt::Debug,
future::Future,
str,
+ sync::Arc,
time::{Duration, Instant},
};
+use actix_http::header::HeaderMap;
use actix_web::{
body, http::header::HeaderValue, web, FromRequest, HttpRequest, HttpResponse, Responder,
ResponseError,
@@ -45,9 +47,9 @@ use crate::{
},
logger,
routes::{
- app::{AppStateInfo, ReqState},
+ app::{AppStateInfo, ReqState, SessionStateInfo},
metrics::{self, request as metrics_request},
- AppState,
+ AppState, SessionState,
},
types::{
self,
@@ -174,7 +176,7 @@ pub trait ConnectorIntegration<T, Req, Resp>: ConnectorIntegrationAny<T, Req, Re
async fn execute_pretasks(
&self,
_router_data: &mut types::RouterData<T, Req, Resp>,
- _app_state: &AppState,
+ _app_state: &SessionState,
) -> CustomResult<(), errors::ConnectorError> {
Ok(())
}
@@ -184,7 +186,7 @@ pub trait ConnectorIntegration<T, Req, Resp>: ConnectorIntegrationAny<T, Req, Re
async fn execute_posttasks(
&self,
_router_data: &mut types::RouterData<T, Req, Resp>,
- _app_state: &AppState,
+ _app_state: &SessionState,
) -> CustomResult<(), errors::ConnectorError> {
Ok(())
}
@@ -297,7 +299,7 @@ pub async fn execute_connector_processing_step<
Req: Debug + Clone + 'static,
Resp: Debug + Clone + 'static,
>(
- state: &'b AppState,
+ state: &'b SessionState,
connector_integration: BoxedConnectorIntegration<'a, T, Req, Resp>,
req: &'b types::RouterData<T, Req, Resp>,
call_connector_action: payments::CallConnectorAction,
@@ -555,7 +557,7 @@ where
#[instrument(skip_all)]
pub async fn call_connector_api(
- state: &AppState,
+ state: &SessionState,
request: Request,
flow_name: &str,
) -> CustomResult<Result<types::Response, types::Response>, errors::ApiClientError> {
@@ -591,7 +593,7 @@ pub async fn call_connector_api(
#[instrument(skip_all)]
pub async fn send_request(
- state: &AppState,
+ state: &SessionState,
request: Request,
option_timeout_secs: Option<u64>,
) -> CustomResult<reqwest::Response, errors::ApiClientError> {
@@ -915,15 +917,16 @@ pub enum AuthFlow {
pub async fn server_wrap_util<'a, 'b, U, T, Q, F, Fut, E, OErr>(
flow: &'a impl router_env::types::FlowMetric,
state: web::Data<AppState>,
+ incoming_request_header: &HeaderMap,
mut request_state: ReqState,
request: &'a HttpRequest,
payload: T,
func: F,
- api_auth: &dyn AuthenticateAndFetch<U, AppState>,
+ api_auth: &dyn AuthenticateAndFetch<U, SessionState>,
lock_action: api_locking::LockAction,
) -> CustomResult<ApplicationResponse<Q>, OErr>
where
- F: Fn(AppState, U, T, ReqState) -> Fut,
+ F: Fn(SessionState, U, T, ReqState) -> Fut,
'b: 'a,
Fut: Future<Output = CustomResult<ApplicationResponse<Q>, E>>,
Q: Serialize + Debug + 'a + ApiEventMetric,
@@ -945,17 +948,49 @@ where
let mut app_state = state.get_ref().clone();
- app_state.add_request_id(request_id);
let start_instant = Instant::now();
let serialized_request = masking::masked_serialize(&payload)
.attach_printable("Failed to serialize json request")
.change_context(errors::ApiErrorResponse::InternalServerError.switch())?;
let mut event_type = payload.get_api_event_type();
+ let tenants: HashSet<_> = state
+ .conf
+ .multitenancy
+ .get_tenant_names()
+ .into_iter()
+ .collect();
+ let tenant_id = if !state.conf.multitenancy.enabled {
+ common_utils::consts::DEFAULT_TENANT.to_string()
+ } else {
+ incoming_request_header
+ .get("x-tenant-id")
+ .and_then(|value| value.to_str().ok())
+ .ok_or_else(|| errors::ApiErrorResponse::MissingTenantId.switch())
+ .map(|req_tenant_id| {
+ if !tenants.contains(req_tenant_id) {
+ Err(errors::ApiErrorResponse::InvalidTenant {
+ tenant_id: req_tenant_id.to_string(),
+ }
+ .switch())
+ } else {
+ Ok(req_tenant_id.to_string())
+ }
+ })??
+ };
+ // let tenant_id = "public".to_string();
+ let mut session_state =
+ Arc::new(app_state.clone()).get_session_state(tenant_id.as_str(), || {
+ errors::ApiErrorResponse::InvalidTenant {
+ tenant_id: tenant_id.clone(),
+ }
+ .switch()
+ })?;
+ session_state.add_request_id(request_id);
// Currently auth failures are not recorded as API events
let (auth_out, auth_type) = api_auth
- .authenticate_and_fetch(request.headers(), &app_state)
+ .authenticate_and_fetch(request.headers(), &session_state)
.await
.switch()?;
@@ -975,14 +1010,14 @@ where
let output = {
lock_action
.clone()
- .perform_locking_action(&app_state, merchant_id.to_owned())
+ .perform_locking_action(&session_state, merchant_id.to_owned())
.await
.switch()?;
- let res = func(app_state.clone(), auth_out, payload, request_state)
+ let res = func(session_state.clone(), auth_out, payload, request_state)
.await
.switch();
lock_action
- .free_lock_action(&app_state, merchant_id.to_owned())
+ .free_lock_action(&session_state, merchant_id.to_owned())
.await
.switch()?;
res
@@ -1064,11 +1099,11 @@ pub async fn server_wrap<'a, T, U, Q, F, Fut, E>(
request: &'a HttpRequest,
payload: T,
func: F,
- api_auth: &dyn AuthenticateAndFetch<U, AppState>,
+ api_auth: &dyn AuthenticateAndFetch<U, SessionState>,
lock_action: api_locking::LockAction,
) -> HttpResponse
where
- F: Fn(AppState, U, T, ReqState) -> Fut,
+ F: Fn(SessionState, U, T, ReqState) -> Fut,
Fut: Future<Output = CustomResult<ApplicationResponse<Q>, E>>,
Q: Serialize + Debug + ApiEventMetric + 'a,
T: Debug + Serialize + ApiEventMetric,
@@ -1109,6 +1144,7 @@ where
server_wrap_util(
&flow,
state.clone(),
+ incoming_request_header,
req_state,
request,
payload,
diff --git a/crates/router/src/services/api/client.rs b/crates/router/src/services/api/client.rs
index d6c55baf60..add93e9911 100644
--- a/crates/router/src/services/api/client.rs
+++ b/crates/router/src/services/api/client.rs
@@ -15,7 +15,7 @@ use crate::{
errors::{ApiClientError, CustomResult},
payments,
},
- routes::AppState,
+ routes::SessionState,
};
static NON_PROXIED_CLIENT: OnceCell<reqwest::Client> = OnceCell::new();
@@ -165,7 +165,7 @@ where
async fn send_request(
&self,
- state: &AppState,
+ state: &SessionState,
request: Request,
option_timeout_secs: Option<u64>,
forward_to_kafka: bool,
@@ -340,7 +340,7 @@ impl ApiClient for ProxyClient {
}
async fn send_request(
&self,
- state: &AppState,
+ state: &SessionState,
request: Request,
option_timeout_secs: Option<u64>,
_forward_to_kafka: bool,
@@ -392,7 +392,7 @@ impl ApiClient for MockApiClient {
async fn send_request(
&self,
- _state: &AppState,
+ _state: &SessionState,
_request: Request,
_option_timeout_secs: Option<u64>,
_forward_to_kafka: bool,
diff --git a/crates/router/src/services/authentication.rs b/crates/router/src/services/authentication.rs
index 64a7c8069f..28f9ccd1a7 100644
--- a/crates/router/src/services/authentication.rs
+++ b/crates/router/src/services/authentication.rs
@@ -25,14 +25,13 @@ use crate::consts;
#[cfg(feature = "olap")]
use crate::core::errors::UserResult;
#[cfg(feature = "recon")]
-use crate::routes::AppState;
+use crate::routes::SessionState;
use crate::{
core::{
api_keys,
errors::{self, utils::StorageErrorExt, RouterResult},
},
- db::StorageInterface,
- routes::app::AppStateInfo,
+ routes::app::SessionStateInfo,
services::api,
types::domain,
utils::OptionExt,
@@ -226,7 +225,7 @@ impl GetUserIdFromAuth for UserFromSinglePurposeToken {
#[async_trait]
pub trait AuthenticateAndFetch<T, A>
where
- A: AppStateInfo,
+ A: SessionStateInfo,
{
async fn authenticate_and_fetch(
&self,
@@ -243,7 +242,7 @@ pub struct NoAuth;
#[async_trait]
impl<A> AuthenticateAndFetch<(), A> for NoAuth
where
- A: AppStateInfo + Sync,
+ A: SessionStateInfo + Sync,
{
async fn authenticate_and_fetch(
&self,
@@ -257,7 +256,7 @@ where
#[async_trait]
impl<A> AuthenticateAndFetch<AuthenticationData, A> for ApiKeyAuth
where
- A: AppStateInfo + Sync,
+ A: SessionStateInfo + Sync,
{
async fn authenticate_and_fetch(
&self,
@@ -335,7 +334,7 @@ pub(crate) struct SinglePurposeJWTAuth(pub TokenPurpose);
#[async_trait]
impl<A> AuthenticateAndFetch<UserFromSinglePurposeToken, A> for SinglePurposeJWTAuth
where
- A: AppStateInfo + Sync,
+ A: SessionStateInfo + Sync,
{
async fn authenticate_and_fetch(
&self,
@@ -368,7 +367,7 @@ where
#[async_trait]
impl<A> AuthenticateAndFetch<Box<dyn GetUserIdFromAuth>, A> for SinglePurposeJWTAuth
where
- A: AppStateInfo + Sync,
+ A: SessionStateInfo + Sync,
{
async fn authenticate_and_fetch(
&self,
@@ -403,7 +402,7 @@ pub struct AdminApiAuth;
#[async_trait]
impl<A> AuthenticateAndFetch<(), A> for AdminApiAuth
where
- A: AppStateInfo + Sync,
+ A: SessionStateInfo + Sync,
{
async fn authenticate_and_fetch(
&self,
@@ -425,13 +424,42 @@ where
}
}
+#[derive(Debug)]
+pub struct EphemeralKeyAuth(pub id_type::CustomerId);
+
+#[async_trait]
+impl<A> AuthenticateAndFetch<AuthenticationData, A> for EphemeralKeyAuth
+where
+ A: SessionStateInfo + Sync,
+{
+ async fn authenticate_and_fetch(
+ &self,
+ request_headers: &HeaderMap,
+ state: &A,
+ ) -> RouterResult<(AuthenticationData, AuthenticationType)> {
+ let api_key =
+ get_api_key(request_headers).change_context(errors::ApiErrorResponse::Unauthorized)?;
+ let ephemeral_key = state
+ .store()
+ .get_ephemeral_key(api_key)
+ .await
+ .change_context(errors::ApiErrorResponse::Unauthorized)?;
+
+ if ephemeral_key.customer_id.ne(&self.0) {
+ return Err(report!(errors::ApiErrorResponse::InvalidEphemeralKey));
+ }
+ MerchantIdAuth(ephemeral_key.merchant_id)
+ .authenticate_and_fetch(request_headers, state)
+ .await
+ }
+}
#[derive(Debug)]
pub struct MerchantIdAuth(pub String);
#[async_trait]
impl<A> AuthenticateAndFetch<AuthenticationData, A> for MerchantIdAuth
where
- A: AppStateInfo + Sync,
+ A: SessionStateInfo + Sync,
{
async fn authenticate_and_fetch(
&self,
@@ -485,7 +513,7 @@ pub struct PublishableKeyAuth;
#[async_trait]
impl<A> AuthenticateAndFetch<AuthenticationData, A> for PublishableKeyAuth
where
- A: AppStateInfo + Sync,
+ A: SessionStateInfo + Sync,
{
async fn authenticate_and_fetch(
&self,
@@ -529,7 +557,7 @@ struct JwtAuthPayloadFetchUnit {
#[async_trait]
impl<A> AuthenticateAndFetch<(), A> for JWTAuth
where
- A: AppStateInfo + Sync,
+ A: SessionStateInfo + Sync,
{
async fn authenticate_and_fetch(
&self,
@@ -558,7 +586,7 @@ where
#[async_trait]
impl<A> AuthenticateAndFetch<UserFromToken, A> for JWTAuth
where
- A: AppStateInfo + Sync,
+ A: SessionStateInfo + Sync,
{
async fn authenticate_and_fetch(
&self,
@@ -596,7 +624,7 @@ pub struct JWTAuthMerchantFromRoute {
#[async_trait]
impl<A> AuthenticateAndFetch<(), A> for JWTAuthMerchantFromRoute
where
- A: AppStateInfo + Sync,
+ A: SessionStateInfo + Sync,
{
async fn authenticate_and_fetch(
&self,
@@ -633,7 +661,7 @@ pub struct JWTAuthMerchantOrProfileFromRoute {
#[async_trait]
impl<A> AuthenticateAndFetch<(), A> for JWTAuthMerchantOrProfileFromRoute
where
- A: AppStateInfo + Sync,
+ A: SessionStateInfo + Sync,
{
async fn authenticate_and_fetch(
&self,
@@ -690,7 +718,7 @@ where
pub async fn parse_jwt_payload<A, T>(headers: &HeaderMap, state: &A) -> RouterResult<T>
where
T: serde::de::DeserializeOwned,
- A: AppStateInfo + Sync,
+ A: SessionStateInfo + Sync,
{
let token = match get_cookie_from_header(headers).and_then(cookies::parse_cookie) {
Ok(cookies) => cookies,
@@ -708,7 +736,7 @@ where
#[async_trait]
impl<A> AuthenticateAndFetch<AuthenticationData, A> for JWTAuth
where
- A: AppStateInfo + Sync,
+ A: SessionStateInfo + Sync,
{
async fn authenticate_and_fetch(
&self,
@@ -758,7 +786,7 @@ pub type AuthenticationDataWithUserId = (AuthenticationData, String);
#[async_trait]
impl<A> AuthenticateAndFetch<AuthenticationDataWithUserId, A> for JWTAuth
where
- A: AppStateInfo + Sync,
+ A: SessionStateInfo + Sync,
{
async fn authenticate_and_fetch(
&self,
@@ -809,7 +837,7 @@ pub struct DashboardNoPermissionAuth;
#[async_trait]
impl<A> AuthenticateAndFetch<UserFromToken, A> for DashboardNoPermissionAuth
where
- A: AppStateInfo + Sync,
+ A: SessionStateInfo + Sync,
{
async fn authenticate_and_fetch(
&self,
@@ -840,7 +868,7 @@ where
#[async_trait]
impl<A> AuthenticateAndFetch<Box<dyn GetUserIdFromAuth>, A> for DashboardNoPermissionAuth
where
- A: AppStateInfo + Sync,
+ A: SessionStateInfo + Sync,
{
async fn authenticate_and_fetch(
&self,
@@ -871,7 +899,7 @@ where
#[async_trait]
impl<A> AuthenticateAndFetch<(), A> for DashboardNoPermissionAuth
where
- A: AppStateInfo + Sync,
+ A: SessionStateInfo + Sync,
{
async fn authenticate_and_fetch(
&self,
@@ -890,7 +918,7 @@ where
#[async_trait]
impl<A> AuthenticateAndFetch<AuthenticationData, A> for DashboardNoPermissionAuth
where
- A: AppStateInfo + Sync,
+ A: SessionStateInfo + Sync,
{
async fn authenticate_and_fetch(
&self,
@@ -987,7 +1015,7 @@ impl ClientSecretFetch for api_models::payment_methods::PaymentMethodUpdate {
}
}
-pub fn get_auth_type_and_flow<A: AppStateInfo + Sync>(
+pub fn get_auth_type_and_flow<A: SessionStateInfo + Sync>(
headers: &HeaderMap,
) -> RouterResult<(
Box<dyn AuthenticateAndFetch<AuthenticationData, A>>,
@@ -1009,7 +1037,7 @@ pub fn check_client_secret_and_get_auth<T>(
api::AuthFlow,
)>
where
- T: AppStateInfo,
+ T: SessionStateInfo,
ApiKeyAuth: AuthenticateAndFetch<AuthenticationData, T>,
PublishableKeyAuth: AuthenticateAndFetch<AuthenticationData, T>,
{
@@ -1034,27 +1062,17 @@ where
Ok((Box::new(ApiKeyAuth), api::AuthFlow::Merchant))
}
-pub async fn is_ephemeral_auth<A: AppStateInfo + Sync>(
+pub fn is_ephemeral_auth<A: SessionStateInfo + Sync>(
headers: &HeaderMap,
- db: &dyn StorageInterface,
customer_id: &id_type::CustomerId,
) -> RouterResult<Box<dyn AuthenticateAndFetch<AuthenticationData, A>>> {
let api_key = get_api_key(headers)?;
if !api_key.starts_with("epk") {
- return Ok(Box::new(ApiKeyAuth));
+ Ok(Box::new(ApiKeyAuth))
+ } else {
+ Ok(Box::new(EphemeralKeyAuth(customer_id.to_owned())))
}
-
- let ephemeral_key = db
- .get_ephemeral_key(api_key)
- .await
- .change_context(errors::ApiErrorResponse::Unauthorized)?;
-
- if ephemeral_key.customer_id.ne(customer_id) {
- return Err(report!(errors::ApiErrorResponse::InvalidEphemeralKey));
- }
-
- Ok(Box::new(MerchantIdAuth(ephemeral_key.merchant_id)))
}
pub fn is_jwt_auth(headers: &HeaderMap) -> bool {
@@ -1064,7 +1082,7 @@ pub fn is_jwt_auth(headers: &HeaderMap) -> bool {
.is_ok()
}
-pub async fn decode_jwt<T>(token: &str, state: &impl AppStateInfo) -> RouterResult<T>
+pub async fn decode_jwt<T>(token: &str, state: &impl SessionStateInfo) -> RouterResult<T>
where
T: serde::de::DeserializeOwned,
{
@@ -1140,7 +1158,7 @@ pub struct ReconAdmin;
#[cfg(feature = "recon")]
impl<A> AuthenticateAndFetch<(), A> for ReconAdmin
where
- A: AppStateInfo + Sync,
+ A: SessionStateInfo + Sync,
{
async fn authenticate_and_fetch(
&self,
@@ -1176,13 +1194,13 @@ impl AuthInfo for ReconUser {
}
#[cfg(all(feature = "olap", feature = "recon"))]
#[async_trait]
-impl AuthenticateAndFetch<ReconUser, AppState> for ReconJWT {
+impl AuthenticateAndFetch<ReconUser, SessionState> for ReconJWT {
async fn authenticate_and_fetch(
&self,
request_headers: &HeaderMap,
- state: &AppState,
+ state: &SessionState,
) -> RouterResult<(ReconUser, AuthenticationType)> {
- let payload = parse_jwt_payload::<AppState, ReconToken>(request_headers, state).await?;
+ let payload = parse_jwt_payload::<SessionState, ReconToken>(request_headers, state).await?;
Ok((
ReconUser {
diff --git a/crates/router/src/services/authentication/blacklist.rs b/crates/router/src/services/authentication/blacklist.rs
index c1abb06475..8a3aefd8fc 100644
--- a/crates/router/src/services/authentication/blacklist.rs
+++ b/crates/router/src/services/authentication/blacklist.rs
@@ -13,17 +13,17 @@ use crate::consts::{EMAIL_TOKEN_BLACKLIST_PREFIX, EMAIL_TOKEN_TIME_IN_SECS};
use crate::{
consts::{JWT_TOKEN_TIME_IN_SECS, ROLE_BLACKLIST_PREFIX, USER_BLACKLIST_PREFIX},
core::errors::{ApiErrorResponse, RouterResult},
- routes::app::AppStateInfo,
+ routes::app::SessionStateInfo,
};
#[cfg(feature = "olap")]
use crate::{
core::errors::{UserErrors, UserResult},
- routes::AppState,
+ routes::SessionState,
services::authorization as authz,
};
#[cfg(feature = "olap")]
-pub async fn insert_user_in_blacklist(state: &AppState, user_id: &str) -> UserResult<()> {
+pub async fn insert_user_in_blacklist(state: &SessionState, user_id: &str) -> UserResult<()> {
let user_blacklist_key = format!("{}{}", USER_BLACKLIST_PREFIX, user_id);
let expiry =
expiry_to_i64(JWT_TOKEN_TIME_IN_SECS).change_context(UserErrors::InternalServerError)?;
@@ -39,7 +39,7 @@ pub async fn insert_user_in_blacklist(state: &AppState, user_id: &str) -> UserRe
}
#[cfg(feature = "olap")]
-pub async fn insert_role_in_blacklist(state: &AppState, role_id: &str) -> UserResult<()> {
+pub async fn insert_role_in_blacklist(state: &SessionState, role_id: &str) -> UserResult<()> {
let role_blacklist_key = format!("{}{}", ROLE_BLACKLIST_PREFIX, role_id);
let expiry =
expiry_to_i64(JWT_TOKEN_TIME_IN_SECS).change_context(UserErrors::InternalServerError)?;
@@ -58,7 +58,7 @@ pub async fn insert_role_in_blacklist(state: &AppState, role_id: &str) -> UserRe
}
#[cfg(feature = "olap")]
-async fn invalidate_role_cache(state: &AppState, role_id: &str) -> RouterResult<()> {
+async fn invalidate_role_cache(state: &SessionState, role_id: &str) -> RouterResult<()> {
let redis_conn = get_redis_connection(state)?;
redis_conn
.delete_key(authz::get_cache_key_from_role_id(role_id).as_str())
@@ -67,7 +67,7 @@ async fn invalidate_role_cache(state: &AppState, role_id: &str) -> RouterResult<
.change_context(ApiErrorResponse::InternalServerError)
}
-pub async fn check_user_in_blacklist<A: AppStateInfo>(
+pub async fn check_user_in_blacklist<A: SessionStateInfo>(
state: &A,
user_id: &str,
token_expiry: u64,
@@ -82,7 +82,7 @@ pub async fn check_user_in_blacklist<A: AppStateInfo>(
.map(|timestamp| timestamp.map_or(false, |timestamp| timestamp > token_issued_at))
}
-pub async fn check_role_in_blacklist<A: AppStateInfo>(
+pub async fn check_role_in_blacklist<A: SessionStateInfo>(
state: &A,
role_id: &str,
token_expiry: u64,
@@ -98,7 +98,7 @@ pub async fn check_role_in_blacklist<A: AppStateInfo>(
}
#[cfg(feature = "email")]
-pub async fn insert_email_token_in_blacklist(state: &AppState, token: &str) -> UserResult<()> {
+pub async fn insert_email_token_in_blacklist(state: &SessionState, token: &str) -> UserResult<()> {
let redis_conn = get_redis_connection(state).change_context(UserErrors::InternalServerError)?;
let blacklist_key = format!("{}{token}", EMAIL_TOKEN_BLACKLIST_PREFIX);
let expiry =
@@ -110,7 +110,7 @@ pub async fn insert_email_token_in_blacklist(state: &AppState, token: &str) -> U
}
#[cfg(feature = "email")]
-pub async fn check_email_token_in_blacklist(state: &AppState, token: &str) -> UserResult<()> {
+pub async fn check_email_token_in_blacklist(state: &SessionState, token: &str) -> UserResult<()> {
let redis_conn = get_redis_connection(state).change_context(UserErrors::InternalServerError)?;
let blacklist_key = format!("{}{token}", EMAIL_TOKEN_BLACKLIST_PREFIX);
let key_exists = redis_conn
@@ -124,7 +124,7 @@ pub async fn check_email_token_in_blacklist(state: &AppState, token: &str) -> Us
Ok(())
}
-fn get_redis_connection<A: AppStateInfo>(state: &A) -> RouterResult<Arc<RedisConnectionPool>> {
+fn get_redis_connection<A: SessionStateInfo>(state: &A) -> RouterResult<Arc<RedisConnectionPool>> {
state
.store()
.get_redis_conn()
@@ -140,14 +140,14 @@ fn expiry_to_i64(expiry: u64) -> RouterResult<i64> {
pub trait BlackList {
async fn check_in_blacklist<A>(&self, state: &A) -> RouterResult<bool>
where
- A: AppStateInfo + Sync;
+ A: SessionStateInfo + Sync;
}
#[async_trait::async_trait]
impl BlackList for AuthToken {
async fn check_in_blacklist<A>(&self, state: &A) -> RouterResult<bool>
where
- A: AppStateInfo + Sync,
+ A: SessionStateInfo + Sync,
{
Ok(
check_user_in_blacklist(state, &self.user_id, self.exp).await?
@@ -161,7 +161,7 @@ impl BlackList for AuthToken {
impl BlackList for SinglePurposeToken {
async fn check_in_blacklist<A>(&self, state: &A) -> RouterResult<bool>
where
- A: AppStateInfo + Sync,
+ A: SessionStateInfo + Sync,
{
check_user_in_blacklist(state, &self.user_id, self.exp).await
}
diff --git a/crates/router/src/services/authorization.rs b/crates/router/src/services/authorization.rs
index 33edb17325..768c57a36d 100644
--- a/crates/router/src/services/authorization.rs
+++ b/crates/router/src/services/authorization.rs
@@ -9,7 +9,7 @@ use super::authentication::AuthToken;
use crate::{
consts,
core::errors::{ApiErrorResponse, RouterResult, StorageErrorExt},
- routes::app::AppStateInfo,
+ routes::app::SessionStateInfo,
};
#[cfg(feature = "olap")]
@@ -23,7 +23,7 @@ pub async fn get_permissions<A>(
token: &AuthToken,
) -> RouterResult<Vec<permissions::Permission>>
where
- A: AppStateInfo + Sync,
+ A: SessionStateInfo + Sync,
{
if let Some(permissions) = get_permissions_from_predefined_roles(&token.role_id) {
return Ok(permissions);
@@ -55,7 +55,7 @@ async fn get_permissions_from_cache<A>(
role_id: &str,
) -> RouterResult<Vec<permissions::Permission>>
where
- A: AppStateInfo + Sync,
+ A: SessionStateInfo + Sync,
{
let redis_conn = get_redis_connection(state)?;
@@ -82,7 +82,7 @@ async fn get_permissions_from_db<A>(
org_id: &str,
) -> RouterResult<Vec<permissions::Permission>>
where
- A: AppStateInfo + Sync,
+ A: SessionStateInfo + Sync,
{
state
.store()
@@ -99,7 +99,7 @@ pub async fn set_permissions_in_cache<A>(
expiry: i64,
) -> RouterResult<()>
where
- A: AppStateInfo + Sync,
+ A: SessionStateInfo + Sync,
{
let redis_conn = get_redis_connection(state)?;
@@ -139,7 +139,7 @@ pub fn check_authorization(
)
}
-fn get_redis_connection<A: AppStateInfo>(state: &A) -> RouterResult<Arc<RedisConnectionPool>> {
+fn get_redis_connection<A: SessionStateInfo>(state: &A) -> RouterResult<Arc<RedisConnectionPool>> {
state
.store()
.get_redis_conn()
diff --git a/crates/router/src/services/authorization/roles.rs b/crates/router/src/services/authorization/roles.rs
index f99892c565..8e5cb6fbea 100644
--- a/crates/router/src/services/authorization/roles.rs
+++ b/crates/router/src/services/authorization/roles.rs
@@ -4,7 +4,7 @@ use common_enums::{PermissionGroup, RoleScope};
use common_utils::errors::CustomResult;
use super::{permission_groups::get_permissions_vec, permissions::Permission};
-use crate::{core::errors, routes::AppState};
+use crate::{core::errors, routes::SessionState};
pub mod predefined_roles;
@@ -67,7 +67,7 @@ impl RoleInfo {
}
pub async fn from_role_id(
- state: &AppState,
+ state: &SessionState,
role_id: &str,
merchant_id: &str,
org_id: &str,
diff --git a/crates/router/src/services/email/types.rs b/crates/router/src/services/email/types.rs
index ee51d976b4..d05e6ab225 100644
--- a/crates/router/src/services/email/types.rs
+++ b/crates/router/src/services/email/types.rs
@@ -7,7 +7,7 @@ use error_stack::ResultExt;
use external_services::email::{EmailContents, EmailData, EmailError};
use masking::{ExposeInterface, PeekInterface, Secret};
-use crate::{configs, consts, routes::AppState};
+use crate::{configs, consts, routes::SessionState};
#[cfg(feature = "olap")]
use crate::{
core::errors::{UserErrors, UserResult},
@@ -407,7 +407,7 @@ pub struct BizEmailProd {
}
impl BizEmailProd {
- pub fn new(state: &AppState, data: ProdIntent) -> UserResult<Self> {
+ pub fn new(state: &SessionState, data: ProdIntent) -> UserResult<Self> {
Ok(Self {
recipient_email: (domain::UserEmail::new(
consts::user::BUSINESS_EMAIL.to_string().into(),
diff --git a/crates/router/src/services/pm_auth.rs b/crates/router/src/services/pm_auth.rs
index a54ba88199..d63dadc8b1 100644
--- a/crates/router/src/services/pm_auth.rs
+++ b/crates/router/src/services/pm_auth.rs
@@ -7,12 +7,12 @@ use pm_auth::{
use crate::{
core::errors::{self},
logger,
- routes::AppState,
+ routes::SessionState,
services::{self},
};
pub async fn execute_connector_processing_step<'b, 'a, T, Req, Resp>(
- state: &'b AppState,
+ state: &'b SessionState,
connector_integration: BoxedConnectorIntegration<'a, T, Req, Resp>,
req: &'b PaymentAuthRouterData<T, Req, Resp>,
connector: &pm_auth_types::PaymentMethodAuthConnectors,
diff --git a/crates/router/src/types/api/mandates.rs b/crates/router/src/types/api/mandates.rs
index 0e80fd224d..71b90ab41c 100644
--- a/crates/router/src/types/api/mandates.rs
+++ b/crates/router/src/types/api/mandates.rs
@@ -11,7 +11,7 @@ use crate::{
payment_methods,
},
newtype,
- routes::AppState,
+ routes::SessionState,
types::{
api, domain,
storage::{self, enums as storage_enums},
@@ -26,7 +26,7 @@ newtype!(
#[async_trait::async_trait]
pub(crate) trait MandateResponseExt: Sized {
async fn from_db_mandate(
- state: &AppState,
+ state: &SessionState,
key_store: domain::MerchantKeyStore,
mandate: storage::Mandate,
storage_scheme: storage_enums::MerchantStorageScheme,
@@ -36,7 +36,7 @@ pub(crate) trait MandateResponseExt: Sized {
#[async_trait::async_trait]
impl MandateResponseExt for MandateResponse {
async fn from_db_mandate(
- state: &AppState,
+ state: &SessionState,
key_store: domain::MerchantKeyStore,
mandate: storage::Mandate,
storage_scheme: storage_enums::MerchantStorageScheme,
diff --git a/crates/router/src/types/api/verify_connector.rs b/crates/router/src/types/api/verify_connector.rs
index 60749f6478..0b932f9aeb 100644
--- a/crates/router/src/types/api/verify_connector.rs
+++ b/crates/router/src/types/api/verify_connector.rs
@@ -8,7 +8,7 @@ use crate::{
services,
services::ConnectorIntegration,
types::{self, api, domain, storage::enums as storage_enums},
- AppState,
+ SessionState,
};
#[derive(Clone)]
@@ -113,7 +113,7 @@ impl VerifyConnectorData {
#[async_trait::async_trait]
pub trait VerifyConnector {
async fn verify(
- state: &AppState,
+ state: &SessionState,
connector_data: VerifyConnectorData,
) -> errors::RouterResponse<()> {
let authorize_data = connector_data.get_payment_authorize_data();
@@ -147,7 +147,7 @@ pub trait VerifyConnector {
}
async fn get_access_token(
- _state: &AppState,
+ _state: &SessionState,
_connector_data: VerifyConnectorData,
) -> errors::CustomResult<Option<types::AccessToken>, errors::ApiErrorResponse> {
// AccessToken is None for the connectors without the AccessToken Flow.
diff --git a/crates/router/src/types/api/verify_connector/paypal.rs b/crates/router/src/types/api/verify_connector/paypal.rs
index 2cb2a8061d..99b7feb661 100644
--- a/crates/router/src/types/api/verify_connector/paypal.rs
+++ b/crates/router/src/types/api/verify_connector/paypal.rs
@@ -4,7 +4,7 @@ use super::{VerifyConnector, VerifyConnectorData};
use crate::{
connector,
core::errors,
- routes::AppState,
+ routes::SessionState,
services,
types::{self, api},
};
@@ -12,7 +12,7 @@ use crate::{
#[async_trait::async_trait]
impl VerifyConnector for connector::Paypal {
async fn get_access_token(
- state: &AppState,
+ state: &SessionState,
connector_data: VerifyConnectorData,
) -> errors::CustomResult<Option<types::AccessToken>, errors::ApiErrorResponse> {
let token_data: types::AccessTokenRequestData =
diff --git a/crates/router/src/types/api/webhooks.rs b/crates/router/src/types/api/webhooks.rs
index 964885cae5..726a5a1542 100644
--- a/crates/router/src/types/api/webhooks.rs
+++ b/crates/router/src/types/api/webhooks.rs
@@ -146,7 +146,7 @@ pub trait IncomingWebhook: ConnectorCommon + Sync {
async fn verify_webhook_source_verification_call(
&self,
- state: &crate::routes::AppState,
+ state: &crate::routes::SessionState,
merchant_account: &domain::MerchantAccount,
merchant_connector_account: domain::MerchantConnectorAccount,
connector_name: &str,
diff --git a/crates/router/src/types/domain/user.rs b/crates/router/src/types/domain/user.rs
index 91323b0c16..60d75ce81d 100644
--- a/crates/router/src/types/domain/user.rs
+++ b/crates/router/src/types/domain/user.rs
@@ -30,7 +30,7 @@ use crate::{
errors::{self, UserErrors, UserResult},
},
db::StorageInterface,
- routes::AppState,
+ routes::SessionState,
services::{self, authentication as auth, authentication::UserFromToken, authorization::info},
types::transformers::ForeignFrom,
utils::{self, user::password},
@@ -237,7 +237,7 @@ impl UserCompanyName {
pub struct NewUserOrganization(diesel_org::OrganizationNew);
impl NewUserOrganization {
- pub async fn insert_org_in_db(self, state: AppState) -> UserResult<Organization> {
+ pub async fn insert_org_in_db(self, state: SessionState) -> UserResult<Organization> {
state
.store
.insert_organization(self.0)
@@ -351,7 +351,7 @@ impl NewUserMerchant {
self.new_organization.clone()
}
- pub async fn check_if_already_exists_in_db(&self, state: AppState) -> UserResult<()> {
+ pub async fn check_if_already_exists_in_db(&self, state: SessionState) -> UserResult<()> {
if state
.store
.get_merchant_key_store_by_merchant_id(
@@ -370,7 +370,10 @@ impl NewUserMerchant {
Ok(())
}
- pub async fn create_new_merchant_and_insert_in_db(&self, state: AppState) -> UserResult<()> {
+ pub async fn create_new_merchant_and_insert_in_db(
+ &self,
+ state: SessionState,
+ ) -> UserResult<()> {
self.check_if_already_exists_in_db(state.clone()).await?;
Box::pin(admin::create_merchant_account(
state.clone(),
@@ -554,7 +557,7 @@ impl NewUser {
.attach_printable("Error while inserting user")
}
- pub async fn check_if_already_exists_in_db(&self, state: AppState) -> UserResult<()> {
+ pub async fn check_if_already_exists_in_db(&self, state: SessionState) -> UserResult<()> {
if state
.store
.find_user_by_email(&self.get_email().into_inner())
@@ -568,7 +571,7 @@ impl NewUser {
pub async fn insert_user_and_merchant_in_db(
&self,
- state: AppState,
+ state: SessionState,
) -> UserResult<UserFromStorage> {
self.check_if_already_exists_in_db(state.clone()).await?;
let db = state.store.as_ref();
@@ -585,7 +588,7 @@ impl NewUser {
pub async fn insert_user_role_in_db(
self,
- state: AppState,
+ state: SessionState,
role_id: String,
user_status: UserStatus,
) -> UserResult<UserRole> {
@@ -790,7 +793,7 @@ impl UserFromStorage {
self.0.email.clone()
}
- pub async fn get_role_from_db(&self, state: AppState) -> UserResult<UserRole> {
+ pub async fn get_role_from_db(&self, state: SessionState) -> UserResult<UserRole> {
state
.store
.find_user_role_by_user_id(&self.0.user_id)
@@ -798,7 +801,7 @@ impl UserFromStorage {
.change_context(UserErrors::InternalServerError)
}
- pub async fn get_roles_from_db(&self, state: &AppState) -> UserResult<Vec<UserRole>> {
+ pub async fn get_roles_from_db(&self, state: &SessionState) -> UserResult<Vec<UserRole>> {
state
.store
.list_user_roles_by_user_id(&self.0.user_id)
@@ -807,7 +810,7 @@ impl UserFromStorage {
}
#[cfg(feature = "email")]
- pub fn get_verification_days_left(&self, state: &AppState) -> UserResult<Option<i64>> {
+ pub fn get_verification_days_left(&self, state: &SessionState) -> UserResult<Option<i64>> {
if self.0.is_verified {
return Ok(None);
}
@@ -829,7 +832,7 @@ impl UserFromStorage {
Ok(Some(days_left_for_verification.whole_days()))
}
- pub fn is_password_rotate_required(&self, state: &AppState) -> UserResult<bool> {
+ pub fn is_password_rotate_required(&self, state: &SessionState) -> UserResult<bool> {
let last_password_modified_at =
if let Some(last_password_modified_at) = self.0.last_password_modified_at {
last_password_modified_at.date()
@@ -855,7 +858,7 @@ impl UserFromStorage {
pub async fn get_role_from_db_by_merchant_id(
&self,
- state: &AppState,
+ state: &SessionState,
merchant_id: &str,
) -> CustomResult<UserRole, errors::StorageError> {
state
@@ -866,7 +869,7 @@ impl UserFromStorage {
pub async fn get_preferred_or_active_user_role_from_db(
&self,
- state: &AppState,
+ state: &SessionState,
) -> CustomResult<UserRole, errors::StorageError> {
if let Some(preferred_merchant_id) = self.get_preferred_merchant_id() {
self.get_role_from_db_by_merchant_id(state, &preferred_merchant_id)
@@ -887,7 +890,7 @@ impl UserFromStorage {
}
}
- pub async fn get_or_create_key_store(&self, state: &AppState) -> UserResult<UserKeyStore> {
+ pub async fn get_or_create_key_store(&self, state: &SessionState) -> UserResult<UserKeyStore> {
let master_key = state.store.get_master_key();
let key_store_result = state
.store
@@ -936,7 +939,7 @@ impl UserFromStorage {
pub async fn decrypt_and_get_totp_secret(
&self,
- state: &AppState,
+ state: &SessionState,
) -> UserResult<Option<Secret<String>>> {
if self.0.totp_secret.is_none() {
return Ok(None);
@@ -1023,7 +1026,7 @@ impl SignInWithRoleStrategyType {
pub async fn get_signin_response(
self,
- state: &AppState,
+ state: &SessionState,
) -> UserResult<user_api::SignInResponse> {
match self {
Self::SingleRole(strategy) => strategy.get_signin_response(state).await,
@@ -1038,7 +1041,10 @@ pub struct SignInWithSingleRoleStrategy {
}
impl SignInWithSingleRoleStrategy {
- async fn get_signin_response(self, state: &AppState) -> UserResult<user_api::SignInResponse> {
+ async fn get_signin_response(
+ self,
+ state: &SessionState,
+ ) -> UserResult<user_api::SignInResponse> {
let token =
utils::user::generate_jwt_auth_token(state, &self.user, &self.user_role).await?;
utils::user_role::set_role_permissions_in_cache_by_user_role(state, &self.user_role).await;
@@ -1058,7 +1064,10 @@ pub struct SignInWithMultipleRolesStrategy {
}
impl SignInWithMultipleRolesStrategy {
- async fn get_signin_response(self, state: &AppState) -> UserResult<user_api::SignInResponse> {
+ async fn get_signin_response(
+ self,
+ state: &SessionState,
+ ) -> UserResult<user_api::SignInResponse> {
let merchant_accounts = state
.store
.list_multiple_merchant_accounts(
diff --git a/crates/router/src/types/domain/user/decision_manager.rs b/crates/router/src/types/domain/user/decision_manager.rs
index 5a0388c7f3..41ae12350f 100644
--- a/crates/router/src/types/domain/user/decision_manager.rs
+++ b/crates/router/src/types/domain/user/decision_manager.rs
@@ -5,7 +5,7 @@ use masking::Secret;
use super::UserFromStorage;
use crate::{
core::errors::{StorageErrorExt, UserErrors, UserResult},
- routes::AppState,
+ routes::SessionState,
services::authentication as auth,
utils,
};
@@ -17,7 +17,7 @@ pub enum UserFlow {
}
impl UserFlow {
- async fn is_required(&self, user: &UserFromStorage, state: &AppState) -> UserResult<bool> {
+ async fn is_required(&self, user: &UserFromStorage, state: &SessionState) -> UserResult<bool> {
match self {
Self::SPTFlow(flow) => flow.is_required(user, state).await,
Self::JWTFlow(flow) => flow.is_required(user, state).await,
@@ -36,7 +36,7 @@ pub enum SPTFlow {
}
impl SPTFlow {
- async fn is_required(&self, user: &UserFromStorage, state: &AppState) -> UserResult<bool> {
+ async fn is_required(&self, user: &UserFromStorage, state: &SessionState) -> UserResult<bool> {
match self {
// TOTP
Self::TOTP => Ok(true),
@@ -54,7 +54,7 @@ impl SPTFlow {
pub async fn generate_spt(
self,
- state: &AppState,
+ state: &SessionState,
next_flow: &NextFlow,
) -> UserResult<Secret<String>> {
auth::SinglePurposeToken::new_token(
@@ -74,13 +74,17 @@ pub enum JWTFlow {
}
impl JWTFlow {
- async fn is_required(&self, _user: &UserFromStorage, _state: &AppState) -> UserResult<bool> {
+ async fn is_required(
+ &self,
+ _user: &UserFromStorage,
+ _state: &SessionState,
+ ) -> UserResult<bool> {
Ok(true)
}
pub async fn generate_jwt(
self,
- state: &AppState,
+ state: &SessionState,
next_flow: &NextFlow,
user_role: &UserRole,
) -> UserResult<Secret<String>> {
@@ -183,7 +187,7 @@ impl CurrentFlow {
})
}
- pub async fn next(&self, user: UserFromStorage, state: &AppState) -> UserResult<NextFlow> {
+ pub async fn next(&self, user: UserFromStorage, state: &SessionState) -> UserResult<NextFlow> {
let flows = self.origin.get_flows();
let remaining_flows = flows.iter().skip(self.current_flow_index + 1);
for flow in remaining_flows {
@@ -209,7 +213,7 @@ impl NextFlow {
pub async fn from_origin(
origin: Origin,
user: UserFromStorage,
- state: &AppState,
+ state: &SessionState,
) -> UserResult<Self> {
let flows = origin.get_flows();
for flow in flows {
@@ -228,7 +232,7 @@ impl NextFlow {
self.next_flow
}
- pub async fn get_token(&self, state: &AppState) -> UserResult<Secret<String>> {
+ pub async fn get_token(&self, state: &SessionState) -> UserResult<Secret<String>> {
match self.next_flow {
UserFlow::SPTFlow(spt_flow) => spt_flow.generate_spt(state, self).await,
UserFlow::JWTFlow(jwt_flow) => {
@@ -251,7 +255,7 @@ impl NextFlow {
pub async fn get_token_with_user_role(
&self,
- state: &AppState,
+ state: &SessionState,
user_role: &UserRole,
) -> UserResult<Secret<String>> {
match self.next_flow {
diff --git a/crates/router/src/types/storage/payment_attempt.rs b/crates/router/src/types/storage/payment_attempt.rs
index 4ad45f554c..1cba84ad9f 100644
--- a/crates/router/src/types/storage/payment_attempt.rs
+++ b/crates/router/src/types/storage/payment_attempt.rs
@@ -124,8 +124,11 @@ mod tests {
..PaymentAttemptNew::default()
};
- let response = state
- .store
+ let store = state
+ .stores
+ .get(state.conf.multitenancy.get_tenant_names().first().unwrap())
+ .unwrap();
+ let response = store
.insert_payment_attempt(payment_attempt, enums::MerchantStorageScheme::PostgresOnly)
.await
.unwrap();
@@ -165,14 +168,16 @@ mod tests {
attempt_id: attempt_id.clone(),
..PaymentAttemptNew::default()
};
- state
- .store
+ let store = state
+ .stores
+ .get(state.conf.multitenancy.get_tenant_names().first().unwrap())
+ .unwrap();
+ store
.insert_payment_attempt(payment_attempt, enums::MerchantStorageScheme::PostgresOnly)
.await
.unwrap();
- let response = state
- .store
+ let response = store
.find_payment_attempt_by_payment_id_merchant_id_attempt_id(
&payment_id,
&merchant_id,
@@ -218,14 +223,16 @@ mod tests {
attempt_id: uuid.clone(),
..PaymentAttemptNew::default()
};
- state
- .store
+ let store = state
+ .stores
+ .get(state.conf.multitenancy.get_tenant_names().first().unwrap())
+ .unwrap();
+ store
.insert_payment_attempt(payment_attempt, enums::MerchantStorageScheme::PostgresOnly)
.await
.unwrap();
- let response = state
- .store
+ let response = store
.find_payment_attempt_by_payment_id_merchant_id_attempt_id(
&uuid,
"1",
diff --git a/crates/router/src/utils.rs b/crates/router/src/utils.rs
index da6cac195c..b83d3138b7 100644
--- a/crates/router/src/utils.rs
+++ b/crates/router/src/utils.rs
@@ -826,7 +826,7 @@ pub async fn trigger_payments_webhook<F, Op>(
key_store: &domain::MerchantKeyStore,
payment_data: crate::core::payments::PaymentData<F>,
customer: Option<domain::Customer>,
- state: &crate::routes::AppState,
+ state: &crate::routes::SessionState,
operation: Op,
) -> RouterResult<()>
where
@@ -858,7 +858,7 @@ where
captures,
customer,
services::AuthFlow::Merchant,
- &state.conf.server,
+ &state.base_url,
&operation,
&state.conf.connector_request_reference_id_config,
None,
diff --git a/crates/router/src/utils/connector_onboarding.rs b/crates/router/src/utils/connector_onboarding.rs
index aeea146df2..15ad2eb895 100644
--- a/crates/router/src/utils/connector_onboarding.rs
+++ b/crates/router/src/utils/connector_onboarding.rs
@@ -5,7 +5,7 @@ use super::errors::StorageErrorExt;
use crate::{
consts,
core::errors::{ApiErrorResponse, NotImplementedMessage, RouterResult},
- routes::{app::settings, AppState},
+ routes::{app::settings, SessionState},
types::{self, api::enums},
};
@@ -41,7 +41,7 @@ pub fn is_enabled(
}
pub async fn check_if_connector_exists(
- state: &AppState,
+ state: &SessionState,
connector_id: &str,
merchant_id: &str,
) -> RouterResult<()> {
@@ -70,7 +70,7 @@ pub async fn check_if_connector_exists(
}
pub async fn set_tracking_id_in_configs(
- state: &AppState,
+ state: &SessionState,
connector_id: &str,
connector: enums::Connector,
) -> RouterResult<()> {
@@ -115,7 +115,7 @@ pub async fn set_tracking_id_in_configs(
}
pub async fn get_tracking_id_from_configs(
- state: &AppState,
+ state: &SessionState,
connector_id: &str,
connector: enums::Connector,
) -> RouterResult<String> {
diff --git a/crates/router/src/utils/connector_onboarding/paypal.rs b/crates/router/src/utils/connector_onboarding/paypal.rs
index 708763a444..9827a4b093 100644
--- a/crates/router/src/utils/connector_onboarding/paypal.rs
+++ b/crates/router/src/utils/connector_onboarding/paypal.rs
@@ -5,7 +5,7 @@ use http::header;
use crate::{
connector,
core::errors::{ApiErrorResponse, RouterResult},
- routes::AppState,
+ routes::SessionState,
types,
types::api::{
enums,
@@ -14,7 +14,7 @@ use crate::{
utils::verify_connector as verify_connector_utils,
};
-pub async fn generate_access_token(state: AppState) -> RouterResult<types::AccessToken> {
+pub async fn generate_access_token(state: SessionState) -> RouterResult<types::AccessToken> {
let connector = enums::Connector::Paypal;
let boxed_connector = types::api::ConnectorData::convert_connector(
&state.conf.connectors,
diff --git a/crates/router/src/utils/currency.rs b/crates/router/src/utils/currency.rs
index 5cf68635c4..c16b46e518 100644
--- a/crates/router/src/utils/currency.rs
+++ b/crates/router/src/utils/currency.rs
@@ -14,7 +14,7 @@ use tokio::{sync::RwLock, time::sleep};
use crate::{
logger,
routes::app::settings::{Conversion, DefaultExchangeRates},
- services, AppState,
+ services, SessionState,
};
const REDIX_FOREX_CACHE_KEY: &str = "{forex_cache}_lock";
const REDIX_FOREX_CACHE_DATA: &str = "{forex_cache}_data";
@@ -121,7 +121,7 @@ async fn save_forex_to_local(
// Alternative handler for handling the case, When no data in local as well as redis
#[allow(dead_code)]
async fn waited_fetch_and_update_caches(
- state: &AppState,
+ state: &SessionState,
local_fetch_retry_delay: u64,
local_fetch_retry_count: u64,
) -> CustomResult<FxExchangeRatesCacheEntry, ForexCacheError> {
@@ -171,7 +171,7 @@ impl From<Conversion> for CurrencyFactors {
}
}
pub async fn get_forex_rates(
- state: &AppState,
+ state: &SessionState,
call_delay: i64,
local_fetch_retry_delay: u64,
local_fetch_retry_count: u64,
@@ -197,7 +197,7 @@ pub async fn get_forex_rates(
}
async fn handler_local_no_data(
- state: &AppState,
+ state: &SessionState,
call_delay: i64,
_local_fetch_retry_delay: u64,
_local_fetch_retry_count: u64,
@@ -216,7 +216,7 @@ async fn handler_local_no_data(
}
async fn successive_fetch_and_save_forex(
- state: &AppState,
+ state: &SessionState,
stale_redis_data: Option<FxExchangeRatesCacheEntry>,
) -> CustomResult<FxExchangeRatesCacheEntry, ForexCacheError> {
match acquire_redis_lock(state).await {
@@ -249,7 +249,7 @@ async fn successive_fetch_and_save_forex(
}
async fn successive_save_data_to_redis_local(
- state: &AppState,
+ state: &SessionState,
forex: FxExchangeRatesCacheEntry,
) -> CustomResult<FxExchangeRatesCacheEntry, ForexCacheError> {
Ok(save_forex_to_redis(state, &forex)
@@ -268,7 +268,7 @@ async fn successive_save_data_to_redis_local(
}
async fn fallback_forex_redis_check(
- state: &AppState,
+ state: &SessionState,
redis_data: FxExchangeRatesCacheEntry,
call_delay: i64,
) -> CustomResult<FxExchangeRatesCacheEntry, ForexCacheError> {
@@ -287,7 +287,7 @@ async fn fallback_forex_redis_check(
}
async fn handler_local_expired(
- state: &AppState,
+ state: &SessionState,
call_delay: i64,
local_rates: FxExchangeRatesCacheEntry,
) -> CustomResult<FxExchangeRatesCacheEntry, ForexCacheError> {
@@ -316,7 +316,7 @@ async fn handler_local_expired(
}
async fn fetch_forex_rates(
- state: &AppState,
+ state: &SessionState,
) -> Result<FxExchangeRatesCacheEntry, error_stack::Report<ForexCacheError>> {
let forex_api_key = state.conf.forex_api.get_inner().api_key.peek();
@@ -371,7 +371,7 @@ async fn fetch_forex_rates(
}
pub async fn fallback_fetch_forex_rates(
- state: &AppState,
+ state: &SessionState,
) -> CustomResult<FxExchangeRatesCacheEntry, ForexCacheError> {
let fallback_forex_api_key = state.conf.forex_api.get_inner().fallback_api_key.peek();
@@ -438,7 +438,7 @@ pub async fn fallback_fetch_forex_rates(
}
async fn release_redis_lock(
- state: &AppState,
+ state: &SessionState,
) -> Result<DelReply, error_stack::Report<ForexCacheError>> {
state
.store
@@ -449,9 +449,9 @@ async fn release_redis_lock(
.change_context(ForexCacheError::RedisLockReleaseFailed)
}
-async fn acquire_redis_lock(app_state: &AppState) -> CustomResult<bool, ForexCacheError> {
- let forex_api = app_state.conf.forex_api.get_inner();
- app_state
+async fn acquire_redis_lock(state: &SessionState) -> CustomResult<bool, ForexCacheError> {
+ let forex_api = state.conf.forex_api.get_inner();
+ state
.store
.get_redis_conn()
.change_context(ForexCacheError::RedisConnectionError)?
@@ -472,7 +472,7 @@ async fn acquire_redis_lock(app_state: &AppState) -> CustomResult<bool, ForexCac
}
async fn save_forex_to_redis(
- app_state: &AppState,
+ app_state: &SessionState,
forex_exchange_cache_entry: &FxExchangeRatesCacheEntry,
) -> CustomResult<(), ForexCacheError> {
app_state
@@ -485,7 +485,7 @@ async fn save_forex_to_redis(
}
async fn retrieve_forex_from_redis(
- app_state: &AppState,
+ app_state: &SessionState,
) -> CustomResult<Option<FxExchangeRatesCacheEntry>, ForexCacheError> {
app_state
.store
@@ -510,7 +510,7 @@ async fn is_redis_expired(
}
pub async fn convert_currency(
- state: AppState,
+ state: SessionState,
amount: i64,
to_currency: String,
from_currency: String,
diff --git a/crates/router/src/utils/user.rs b/crates/router/src/utils/user.rs
index db1d0ea250..eaa386d7f6 100644
--- a/crates/router/src/utils/user.rs
+++ b/crates/router/src/utils/user.rs
@@ -8,7 +8,7 @@ use redis_interface::RedisConnectionPool;
use crate::{
core::errors::{StorageError, UserErrors, UserResult},
- routes::AppState,
+ routes::SessionState,
services::{
authentication::{AuthToken, UserFromToken},
authorization::roles::RoleInfo,
@@ -25,7 +25,7 @@ pub mod two_factor_auth;
impl UserFromToken {
pub async fn get_merchant_account_from_db(
&self,
- state: AppState,
+ state: SessionState,
) -> UserResult<MerchantAccount> {
let key_store = state
.store
@@ -55,7 +55,7 @@ impl UserFromToken {
Ok(merchant_account)
}
- pub async fn get_user_from_db(&self, state: &AppState) -> UserResult<UserFromStorage> {
+ pub async fn get_user_from_db(&self, state: &SessionState) -> UserResult<UserFromStorage> {
let user = state
.store
.find_user_by_id(&self.user_id)
@@ -64,7 +64,7 @@ impl UserFromToken {
Ok(user.into())
}
- pub async fn get_role_info_from_db(&self, state: &AppState) -> UserResult<RoleInfo> {
+ pub async fn get_role_info_from_db(&self, state: &SessionState) -> UserResult<RoleInfo> {
RoleInfo::from_role_id(state, &self.role_id, &self.merchant_id, &self.org_id)
.await
.change_context(UserErrors::InternalServerError)
@@ -72,7 +72,7 @@ impl UserFromToken {
}
pub async fn generate_jwt_auth_token(
- state: &AppState,
+ state: &SessionState,
user: &UserFromStorage,
user_role: &UserRole,
) -> UserResult<masking::Secret<String>> {
@@ -88,7 +88,7 @@ pub async fn generate_jwt_auth_token(
}
pub async fn generate_jwt_auth_token_with_custom_role_attributes(
- state: &AppState,
+ state: &SessionState,
user: &UserFromStorage,
merchant_id: String,
org_id: String,
@@ -106,7 +106,7 @@ pub async fn generate_jwt_auth_token_with_custom_role_attributes(
}
pub fn get_dashboard_entry_response(
- state: &AppState,
+ state: &SessionState,
user: UserFromStorage,
user_role: UserRole,
token: masking::Secret<String>,
@@ -126,7 +126,7 @@ pub fn get_dashboard_entry_response(
#[allow(unused_variables)]
pub fn get_verification_days_left(
- state: &AppState,
+ state: &SessionState,
user: &UserFromStorage,
) -> UserResult<Option<i64>> {
#[cfg(feature = "email")]
@@ -176,7 +176,7 @@ pub fn get_multiple_merchant_details_with_status(
}
pub async fn get_user_from_db_by_email(
- state: &AppState,
+ state: &SessionState,
email: domain::UserEmail,
) -> CustomResult<UserFromStorage, StorageError> {
state
@@ -193,7 +193,7 @@ pub fn get_token_from_signin_response(resp: &user_api::SignInResponse) -> maskin
}
}
-pub fn get_redis_connection(state: &AppState) -> UserResult<Arc<RedisConnectionPool>> {
+pub fn get_redis_connection(state: &SessionState) -> UserResult<Arc<RedisConnectionPool>> {
state
.store
.get_redis_conn()
diff --git a/crates/router/src/utils/user/dashboard_metadata.rs b/crates/router/src/utils/user/dashboard_metadata.rs
index 3979a86494..5622a43f4d 100644
--- a/crates/router/src/utils/user/dashboard_metadata.rs
+++ b/crates/router/src/utils/user/dashboard_metadata.rs
@@ -13,11 +13,11 @@ use masking::Secret;
use crate::{
core::errors::{UserErrors, UserResult},
- headers, AppState,
+ headers, SessionState,
};
pub async fn insert_merchant_scoped_metadata_to_db(
- state: &AppState,
+ state: &SessionState,
user_id: String,
merchant_id: String,
org_id: String,
@@ -50,7 +50,7 @@ pub async fn insert_merchant_scoped_metadata_to_db(
})
}
pub async fn insert_user_scoped_metadata_to_db(
- state: &AppState,
+ state: &SessionState,
user_id: String,
merchant_id: String,
org_id: String,
@@ -84,7 +84,7 @@ pub async fn insert_user_scoped_metadata_to_db(
}
pub async fn get_merchant_scoped_metadata_from_db(
- state: &AppState,
+ state: &SessionState,
merchant_id: String,
org_id: String,
metadata_keys: Vec<DBEnum>,
@@ -97,7 +97,7 @@ pub async fn get_merchant_scoped_metadata_from_db(
.attach_printable("DB Error Fetching DashboardMetaData")
}
pub async fn get_user_scoped_metadata_from_db(
- state: &AppState,
+ state: &SessionState,
user_id: String,
merchant_id: String,
org_id: String,
@@ -121,7 +121,7 @@ pub async fn get_user_scoped_metadata_from_db(
}
pub async fn update_merchant_scoped_metadata(
- state: &AppState,
+ state: &SessionState,
user_id: String,
merchant_id: String,
org_id: String,
@@ -149,7 +149,7 @@ pub async fn update_merchant_scoped_metadata(
.change_context(UserErrors::InternalServerError)
}
pub async fn update_user_scoped_metadata(
- state: &AppState,
+ state: &SessionState,
user_id: String,
merchant_id: String,
org_id: String,
diff --git a/crates/router/src/utils/user/sample_data.rs b/crates/router/src/utils/user/sample_data.rs
index ea690af35a..9be2ddb57a 100644
--- a/crates/router/src/utils/user/sample_data.rs
+++ b/crates/router/src/utils/user/sample_data.rs
@@ -12,12 +12,12 @@ use time::OffsetDateTime;
use crate::{
consts,
core::errors::sample_data::{SampleDataError, SampleDataResult},
- AppState,
+ SessionState,
};
#[allow(clippy::type_complexity)]
pub async fn generate_sample_data(
- state: &AppState,
+ state: &SessionState,
req: SampleDataRequest,
merchant_id: &str,
) -> SampleDataResult<Vec<(PaymentIntentNew, PaymentAttemptBatchNew, Option<RefundNew>)>> {
diff --git a/crates/router/src/utils/user/two_factor_auth.rs b/crates/router/src/utils/user/two_factor_auth.rs
index 6bd693c07f..a0915f3ed8 100644
--- a/crates/router/src/utils/user/two_factor_auth.rs
+++ b/crates/router/src/utils/user/two_factor_auth.rs
@@ -6,7 +6,7 @@ use totp_rs::{Algorithm, TOTP};
use crate::{
consts,
core::errors::{UserErrors, UserResult},
- routes::AppState,
+ routes::SessionState,
};
pub fn generate_default_totp(
@@ -31,7 +31,7 @@ pub fn generate_default_totp(
.change_context(UserErrors::InternalServerError)
}
-pub async fn check_totp_in_redis(state: &AppState, user_id: &str) -> UserResult<bool> {
+pub async fn check_totp_in_redis(state: &SessionState, user_id: &str) -> UserResult<bool> {
let redis_conn = super::get_redis_connection(state)?;
let key = format!("{}{}", consts::user::REDIS_TOTP_PREFIX, user_id);
redis_conn
@@ -40,7 +40,7 @@ pub async fn check_totp_in_redis(state: &AppState, user_id: &str) -> UserResult<
.change_context(UserErrors::InternalServerError)
}
-pub async fn check_recovery_code_in_redis(state: &AppState, user_id: &str) -> UserResult<bool> {
+pub async fn check_recovery_code_in_redis(state: &SessionState, user_id: &str) -> UserResult<bool> {
let redis_conn = super::get_redis_connection(state)?;
let key = format!("{}{}", consts::user::REDIS_RECOVERY_CODE_PREFIX, user_id);
redis_conn
@@ -49,7 +49,7 @@ pub async fn check_recovery_code_in_redis(state: &AppState, user_id: &str) -> Us
.change_context(UserErrors::InternalServerError)
}
-pub async fn insert_totp_in_redis(state: &AppState, user_id: &str) -> UserResult<()> {
+pub async fn insert_totp_in_redis(state: &SessionState, user_id: &str) -> UserResult<()> {
let redis_conn = super::get_redis_connection(state)?;
let key = format!("{}{}", consts::user::REDIS_TOTP_PREFIX, user_id);
redis_conn
@@ -63,7 +63,7 @@ pub async fn insert_totp_in_redis(state: &AppState, user_id: &str) -> UserResult
}
pub async fn insert_totp_secret_in_redis(
- state: &AppState,
+ state: &SessionState,
user_id: &str,
secret: &masking::Secret<String>,
) -> UserResult<()> {
@@ -79,7 +79,7 @@ pub async fn insert_totp_secret_in_redis(
}
pub async fn get_totp_secret_from_redis(
- state: &AppState,
+ state: &SessionState,
user_id: &str,
) -> UserResult<Option<masking::Secret<String>>> {
let redis_conn = super::get_redis_connection(state)?;
@@ -90,7 +90,7 @@ pub async fn get_totp_secret_from_redis(
.map(|secret| secret.map(Into::into))
}
-pub async fn delete_totp_secret_from_redis(state: &AppState, user_id: &str) -> UserResult<()> {
+pub async fn delete_totp_secret_from_redis(state: &SessionState, user_id: &str) -> UserResult<()> {
let redis_conn = super::get_redis_connection(state)?;
redis_conn
.delete_key(&get_totp_secret_key(user_id))
@@ -103,7 +103,7 @@ fn get_totp_secret_key(user_id: &str) -> String {
format!("{}{}", consts::user::REDIS_TOTP_SECRET_PREFIX, user_id)
}
-pub async fn insert_recovery_code_in_redis(state: &AppState, user_id: &str) -> UserResult<()> {
+pub async fn insert_recovery_code_in_redis(state: &SessionState, user_id: &str) -> UserResult<()> {
let redis_conn = super::get_redis_connection(state)?;
let key = format!("{}{}", consts::user::REDIS_RECOVERY_CODE_PREFIX, user_id);
redis_conn
diff --git a/crates/router/src/utils/user_role.rs b/crates/router/src/utils/user_role.rs
index ba4c287866..d0ad08848c 100644
--- a/crates/router/src/utils/user_role.rs
+++ b/crates/router/src/utils/user_role.rs
@@ -9,7 +9,7 @@ use router_env::logger;
use crate::{
consts,
core::errors::{StorageErrorExt, UserErrors, UserResult},
- routes::AppState,
+ routes::SessionState,
services::authorization::{self as authz, permissions::Permission, roles},
types::domain,
};
@@ -73,7 +73,7 @@ pub fn validate_role_groups(groups: &[PermissionGroup]) -> UserResult<()> {
}
pub async fn validate_role_name(
- state: &AppState,
+ state: &SessionState,
role_name: &domain::RoleName,
merchant_id: &str,
org_id: &str,
@@ -101,7 +101,7 @@ pub async fn validate_role_name(
}
pub async fn set_role_permissions_in_cache_by_user_role(
- state: &AppState,
+ state: &SessionState,
user_role: &UserRole,
) -> bool {
set_role_permissions_in_cache_if_required(
@@ -116,7 +116,7 @@ pub async fn set_role_permissions_in_cache_by_user_role(
}
pub async fn set_role_permissions_in_cache_if_required(
- state: &AppState,
+ state: &SessionState,
role_id: &str,
merchant_id: &str,
org_id: &str,
@@ -143,7 +143,7 @@ pub async fn set_role_permissions_in_cache_if_required(
}
pub async fn get_multiple_role_info_for_user_roles(
- state: &AppState,
+ state: &SessionState,
user_roles: &[UserRole],
) -> UserResult<Vec<roles::RoleInfo>> {
futures::future::try_join_all(user_roles.iter().map(|user_role| async {
diff --git a/crates/router/src/workflows/api_key_expiry.rs b/crates/router/src/workflows/api_key_expiry.rs
index c591481010..dff7905a26 100644
--- a/crates/router/src/workflows/api_key_expiry.rs
+++ b/crates/router/src/workflows/api_key_expiry.rs
@@ -1,12 +1,12 @@
use common_utils::{errors::ValidationError, ext_traits::ValueExt};
use diesel_models::{enums as storage_enums, ApiKeyExpiryTrackingData};
use router_env::logger;
-use scheduler::{workflows::ProcessTrackerWorkflow, SchedulerAppState};
+use scheduler::{workflows::ProcessTrackerWorkflow, SchedulerSessionState};
use crate::{
errors,
logger::error,
- routes::{metrics, AppState},
+ routes::{metrics, SessionState},
services::email::types::ApiKeyExpiryReminder,
types::{api, domain::UserEmail, storage},
utils::OptionExt,
@@ -15,10 +15,10 @@ use crate::{
pub struct ApiKeyExpiryWorkflow;
#[async_trait::async_trait]
-impl ProcessTrackerWorkflow<AppState> for ApiKeyExpiryWorkflow {
+impl ProcessTrackerWorkflow<SessionState> for ApiKeyExpiryWorkflow {
async fn execute_workflow<'a>(
&'a self,
- state: &'a AppState,
+ state: &'a SessionState,
process: storage::ProcessTracker,
) -> Result<(), errors::ProcessTrackerError> {
let db = &*state.store;
@@ -137,7 +137,7 @@ impl ProcessTrackerWorkflow<AppState> for ApiKeyExpiryWorkflow {
async fn error_handler<'a>(
&'a self,
- _state: &'a AppState,
+ _state: &'a SessionState,
process: storage::ProcessTracker,
_error: errors::ProcessTrackerError,
) -> errors::CustomResult<(), errors::ProcessTrackerError> {
diff --git a/crates/router/src/workflows/attach_payout_account_workflow.rs b/crates/router/src/workflows/attach_payout_account_workflow.rs
index 98d3f7844b..eb60510ad7 100644
--- a/crates/router/src/workflows/attach_payout_account_workflow.rs
+++ b/crates/router/src/workflows/attach_payout_account_workflow.rs
@@ -7,17 +7,17 @@ use scheduler::{
use crate::{
core::payouts,
errors as core_errors,
- routes::AppState,
+ routes::SessionState,
types::{api, storage},
};
pub struct AttachPayoutAccountWorkflow;
#[async_trait::async_trait]
-impl ProcessTrackerWorkflow<AppState> for AttachPayoutAccountWorkflow {
+impl ProcessTrackerWorkflow<SessionState> for AttachPayoutAccountWorkflow {
async fn execute_workflow<'a>(
&'a self,
- state: &'a AppState,
+ state: &'a SessionState,
process: storage::ProcessTracker,
) -> Result<(), errors::ProcessTrackerError> {
// Gather context
@@ -63,7 +63,7 @@ impl ProcessTrackerWorkflow<AppState> for AttachPayoutAccountWorkflow {
async fn error_handler<'a>(
&'a self,
- state: &'a AppState,
+ state: &'a SessionState,
process: storage::ProcessTracker,
error: errors::ProcessTrackerError,
) -> core_errors::CustomResult<(), errors::ProcessTrackerError> {
diff --git a/crates/router/src/workflows/outgoing_webhook_retry.rs b/crates/router/src/workflows/outgoing_webhook_retry.rs
index 63bdb7ec98..53b275dfeb 100644
--- a/crates/router/src/workflows/outgoing_webhook_retry.rs
+++ b/crates/router/src/workflows/outgoing_webhook_retry.rs
@@ -17,18 +17,18 @@ use crate::{
core::webhooks::{self as webhooks_core, types::OutgoingWebhookTrackingData},
db::StorageInterface,
errors, logger,
- routes::{app::ReqState, AppState},
+ routes::{app::ReqState, SessionState},
types::{domain, storage},
};
pub struct OutgoingWebhookRetryWorkflow;
#[async_trait::async_trait]
-impl ProcessTrackerWorkflow<AppState> for OutgoingWebhookRetryWorkflow {
+impl ProcessTrackerWorkflow<SessionState> for OutgoingWebhookRetryWorkflow {
#[instrument(skip_all)]
async fn execute_workflow<'a>(
&'a self,
- state: &'a AppState,
+ state: &'a SessionState,
process: storage::ProcessTracker,
) -> Result<(), errors::ProcessTrackerError> {
let delivery_attempt = storage::enums::WebhookDeliveryAttempt::AutomaticRetry;
@@ -207,7 +207,7 @@ impl ProcessTrackerWorkflow<AppState> for OutgoingWebhookRetryWorkflow {
#[instrument(skip_all)]
async fn error_handler<'a>(
&'a self,
- state: &'a AppState,
+ state: &'a SessionState,
process: storage::ProcessTracker,
error: errors::ProcessTrackerError,
) -> errors::CustomResult<(), errors::ProcessTrackerError> {
@@ -313,7 +313,7 @@ pub(crate) async fn retry_webhook_delivery_task(
#[instrument(skip_all)]
async fn get_outgoing_webhook_content_and_event_type(
- state: AppState,
+ state: SessionState,
req_state: ReqState,
merchant_account: domain::MerchantAccount,
key_store: domain::MerchantKeyStore,
diff --git a/crates/router/src/workflows/payment_sync.rs b/crates/router/src/workflows/payment_sync.rs
index 14f372789e..c34b8ebe73 100644
--- a/crates/router/src/workflows/payment_sync.rs
+++ b/crates/router/src/workflows/payment_sync.rs
@@ -3,7 +3,7 @@ use error_stack::ResultExt;
use router_env::logger;
use scheduler::{
consumer::{self, types::process_data, workflows::ProcessTrackerWorkflow},
- errors as sch_errors, utils as scheduler_utils, SchedulerAppState,
+ errors as sch_errors, utils as scheduler_utils,
};
use crate::{
@@ -14,7 +14,7 @@ use crate::{
},
db::StorageInterface,
errors,
- routes::AppState,
+ routes::SessionState,
services,
types::{
api,
@@ -26,10 +26,10 @@ use crate::{
pub struct PaymentsSyncWorkflow;
#[async_trait::async_trait]
-impl ProcessTrackerWorkflow<AppState> for PaymentsSyncWorkflow {
+impl ProcessTrackerWorkflow<SessionState> for PaymentsSyncWorkflow {
async fn execute_workflow<'a>(
&'a self,
- state: &'a AppState,
+ state: &'a SessionState,
process: storage::ProcessTracker,
) -> Result<(), sch_errors::ProcessTrackerError> {
let db: &dyn StorageInterface = &*state.store;
@@ -87,7 +87,7 @@ impl ProcessTrackerWorkflow<AppState> for PaymentsSyncWorkflow {
match &payment_data.payment_attempt.status {
status if terminal_status.contains(status) => {
state
- .get_db()
+ .store
.as_scheduler()
.finish_process_with_business_status(process, "COMPLETED_BY_PT".to_string())
.await?
@@ -192,7 +192,7 @@ impl ProcessTrackerWorkflow<AppState> for PaymentsSyncWorkflow {
async fn error_handler<'a>(
&'a self,
- state: &'a AppState,
+ state: &'a SessionState,
process: storage::ProcessTracker,
error: sch_errors::ProcessTrackerError,
) -> errors::CustomResult<(), sch_errors::ProcessTrackerError> {
diff --git a/crates/router/src/workflows/refund_router.rs b/crates/router/src/workflows/refund_router.rs
index 934c208f91..515e34c068 100644
--- a/crates/router/src/workflows/refund_router.rs
+++ b/crates/router/src/workflows/refund_router.rs
@@ -1,16 +1,16 @@
use scheduler::consumer::workflows::ProcessTrackerWorkflow;
use crate::{
- core::refunds as refund_flow, errors, logger::error, routes::AppState, types::storage,
+ core::refunds as refund_flow, errors, logger::error, routes::SessionState, types::storage,
};
pub struct RefundWorkflowRouter;
#[async_trait::async_trait]
-impl ProcessTrackerWorkflow<AppState> for RefundWorkflowRouter {
+impl ProcessTrackerWorkflow<SessionState> for RefundWorkflowRouter {
async fn execute_workflow<'a>(
&'a self,
- state: &'a AppState,
+ state: &'a SessionState,
process: storage::ProcessTracker,
) -> Result<(), errors::ProcessTrackerError> {
Ok(Box::pin(refund_flow::start_refund_workflow(state, &process)).await?)
@@ -18,7 +18,7 @@ impl ProcessTrackerWorkflow<AppState> for RefundWorkflowRouter {
async fn error_handler<'a>(
&'a self,
- _state: &'a AppState,
+ _state: &'a SessionState,
process: storage::ProcessTracker,
_error: errors::ProcessTrackerError,
) -> errors::CustomResult<(), errors::ProcessTrackerError> {
diff --git a/crates/router/src/workflows/tokenized_data.rs b/crates/router/src/workflows/tokenized_data.rs
index 0674982f92..bc1842205a 100644
--- a/crates/router/src/workflows/tokenized_data.rs
+++ b/crates/router/src/workflows/tokenized_data.rs
@@ -1,16 +1,16 @@
use scheduler::consumer::workflows::ProcessTrackerWorkflow;
use crate::{
- core::payment_methods::vault, errors, logger::error, routes::AppState, types::storage,
+ core::payment_methods::vault, errors, logger::error, routes::SessionState, types::storage,
};
pub struct DeleteTokenizeDataWorkflow;
#[async_trait::async_trait]
-impl ProcessTrackerWorkflow<AppState> for DeleteTokenizeDataWorkflow {
+impl ProcessTrackerWorkflow<SessionState> for DeleteTokenizeDataWorkflow {
async fn execute_workflow<'a>(
&'a self,
- state: &'a AppState,
+ state: &'a SessionState,
process: storage::ProcessTracker,
) -> Result<(), errors::ProcessTrackerError> {
Ok(vault::start_tokenize_data_workflow(state, &process).await?)
@@ -18,7 +18,7 @@ impl ProcessTrackerWorkflow<AppState> for DeleteTokenizeDataWorkflow {
async fn error_handler<'a>(
&'a self,
- _state: &'a AppState,
+ _state: &'a SessionState,
process: storage::ProcessTracker,
_error: errors::ProcessTrackerError,
) -> errors::CustomResult<(), errors::ProcessTrackerError> {
diff --git a/crates/router/tests/cache.rs b/crates/router/tests/cache.rs
index c6eef06db7..f0c79e4dcb 100644
--- a/crates/router/tests/cache.rs
+++ b/crates/router/tests/cache.rs
@@ -1,6 +1,8 @@
#![allow(clippy::unwrap_used)]
+use std::sync::Arc;
+
use router::{configs::settings::Settings, routes, services};
-use storage_impl::redis::cache;
+use storage_impl::redis::cache::{self, CacheKey};
mod utils;
@@ -9,13 +11,15 @@ async fn invalidate_existing_cache_success() {
// Arrange
Box::pin(utils::setup()).await;
let (tx, _) = tokio::sync::oneshot::channel();
- let state = Box::pin(routes::AppState::new(
+ let app_state = Box::pin(routes::AppState::new(
Settings::default(),
tx,
Box::new(services::MockApiClient),
))
.await;
-
+ let state = Arc::new(app_state)
+ .get_session_state("public", || {})
+ .unwrap();
let cache_key = "cacheKey".to_string();
let cache_key_value = "val".to_string();
let _ = state
@@ -29,11 +33,23 @@ async fn invalidate_existing_cache_success() {
let client = awc::Client::default();
cache::CONFIG_CACHE
- .push(cache_key.clone(), cache_key_value.clone())
+ .push(
+ CacheKey {
+ key: cache_key.clone(),
+ prefix: String::default(),
+ },
+ cache_key_value.clone(),
+ )
.await;
cache::ACCOUNTS_CACHE
- .push(cache_key.clone(), cache_key_value.clone())
+ .push(
+ CacheKey {
+ key: cache_key.clone(),
+ prefix: String::default(),
+ },
+ cache_key_value.clone(),
+ )
.await;
// Act
@@ -51,11 +67,17 @@ async fn invalidate_existing_cache_success() {
println!("invalidate Cache: {response:?} : {response_body:?}");
assert_eq!(response.status(), awc::http::StatusCode::OK);
assert!(cache::CONFIG_CACHE
- .get_val::<String>(&cache_key)
+ .get_val::<String>(CacheKey {
+ key: cache_key.clone(),
+ prefix: String::default()
+ })
.await
.is_none());
assert!(cache::ACCOUNTS_CACHE
- .get_val::<String>(&cache_key)
+ .get_val::<String>(CacheKey {
+ key: cache_key,
+ prefix: String::default()
+ })
.await
.is_none());
}
diff --git a/crates/router/tests/connectors/aci.rs b/crates/router/tests/connectors/aci.rs
index 414ab8cd1d..10e8b36653 100644
--- a/crates/router/tests/connectors/aci.rs
+++ b/crates/router/tests/connectors/aci.rs
@@ -1,4 +1,4 @@
-use std::{marker::PhantomData, str::FromStr};
+use std::{marker::PhantomData, str::FromStr, sync::Arc};
use api_models::payments::{Address, AddressDetails, PhoneDetails};
use common_utils::id_type;
@@ -191,13 +191,16 @@ async fn payments_create_success() {
let conf = Settings::new().unwrap();
let tx: oneshot::Sender<()> = oneshot::channel().0;
- let state = Box::pin(routes::AppState::with_storage(
+ let app_state = Box::pin(routes::AppState::with_storage(
conf,
StorageImpl::PostgresqlTest,
tx,
Box::new(services::MockApiClient),
))
.await;
+ let state = Arc::new(app_state)
+ .get_session_state("public", || {})
+ .unwrap();
static CV: aci::Aci = aci::Aci;
let connector = types::api::ConnectorData {
@@ -236,13 +239,16 @@ async fn payments_create_failure() {
static CV: aci::Aci = aci::Aci;
let tx: oneshot::Sender<()> = oneshot::channel().0;
- let state = Box::pin(routes::AppState::with_storage(
+ let app_state = Box::pin(routes::AppState::with_storage(
conf,
StorageImpl::PostgresqlTest,
tx,
Box::new(services::MockApiClient),
))
.await;
+ let state = Arc::new(app_state)
+ .get_session_state("public", || {})
+ .unwrap();
let connector = types::api::ConnectorData {
connector: Box::new(&CV),
connector_name: types::Connector::Aci,
@@ -297,13 +303,16 @@ async fn refund_for_successful_payments() {
};
let tx: oneshot::Sender<()> = oneshot::channel().0;
- let state = Box::pin(routes::AppState::with_storage(
+ let app_state = Box::pin(routes::AppState::with_storage(
conf,
StorageImpl::PostgresqlTest,
tx,
Box::new(services::MockApiClient),
))
.await;
+ let state = Arc::new(app_state)
+ .get_session_state("public", || {})
+ .unwrap();
let connector_integration: services::BoxedConnectorIntegration<
'_,
types::api::Authorize,
@@ -366,13 +375,16 @@ async fn refunds_create_failure() {
};
let tx: oneshot::Sender<()> = oneshot::channel().0;
- let state = Box::pin(routes::AppState::with_storage(
+ let app_state = Box::pin(routes::AppState::with_storage(
conf,
StorageImpl::PostgresqlTest,
tx,
Box::new(services::MockApiClient),
))
.await;
+ let state = Arc::new(app_state)
+ .get_session_state("public", || {})
+ .unwrap();
let connector_integration: services::BoxedConnectorIntegration<
'_,
types::api::Execute,
diff --git a/crates/router/tests/connectors/utils.rs b/crates/router/tests/connectors/utils.rs
index b7be24f2a1..0de19f17b5 100644
--- a/crates/router/tests/connectors/utils.rs
+++ b/crates/router/tests/connectors/utils.rs
@@ -1,4 +1,4 @@
-use std::{fmt::Debug, marker::PhantomData, str::FromStr, time::Duration};
+use std::{fmt::Debug, marker::PhantomData, str::FromStr, sync::Arc, time::Duration};
use async_trait::async_trait;
use common_utils::pii::Email;
@@ -95,13 +95,16 @@ pub trait ConnectorActions: Connector {
payment_info,
);
let tx: oneshot::Sender<()> = oneshot::channel().0;
- let state = Box::pin(routes::AppState::with_storage(
+ let app_state = Box::pin(routes::AppState::with_storage(
Settings::new().unwrap(),
StorageImpl::PostgresqlTest,
tx,
Box::new(services::MockApiClient),
))
.await;
+ let state = Arc::new(app_state)
+ .get_session_state("public", || {})
+ .unwrap();
integration.execute_pretasks(&mut request, &state).await?;
Box::pin(call_connector(request, integration)).await
}
@@ -120,13 +123,16 @@ pub trait ConnectorActions: Connector {
);
let tx: oneshot::Sender<()> = oneshot::channel().0;
- let state = Box::pin(routes::AppState::with_storage(
+ let app_state = Box::pin(routes::AppState::with_storage(
Settings::new().unwrap(),
StorageImpl::PostgresqlTest,
tx,
Box::new(services::MockApiClient),
))
.await;
+ let state = Arc::new(app_state)
+ .get_session_state("public", || {})
+ .unwrap();
integration.execute_pretasks(&mut request, &state).await?;
Box::pin(call_connector(request, integration)).await
}
@@ -145,13 +151,16 @@ pub trait ConnectorActions: Connector {
);
let tx: oneshot::Sender<()> = oneshot::channel().0;
- let state = Box::pin(routes::AppState::with_storage(
+ let app_state = Box::pin(routes::AppState::with_storage(
Settings::new().unwrap(),
StorageImpl::PostgresqlTest,
tx,
Box::new(services::MockApiClient),
))
.await;
+ let state = Arc::new(app_state)
+ .get_session_state("public", || {})
+ .unwrap();
integration.execute_pretasks(&mut request, &state).await?;
Box::pin(call_connector(request, integration)).await
}
@@ -174,13 +183,16 @@ pub trait ConnectorActions: Connector {
);
let tx: oneshot::Sender<()> = oneshot::channel().0;
- let state = Box::pin(routes::AppState::with_storage(
+ let app_state = Box::pin(routes::AppState::with_storage(
Settings::new().unwrap(),
StorageImpl::PostgresqlTest,
tx,
Box::new(services::MockApiClient),
))
.await;
+ let state = Arc::new(app_state)
+ .get_session_state("public", || {})
+ .unwrap();
integration.execute_pretasks(&mut request, &state).await?;
Box::pin(call_connector(request, integration)).await
}
@@ -598,13 +610,16 @@ pub trait ConnectorActions: Connector {
let mut request = self.get_payout_request(None, payout_type, payment_info);
let tx: oneshot::Sender<()> = oneshot::channel().0;
- let state = Box::pin(routes::AppState::with_storage(
+ let app_state = Box::pin(routes::AppState::with_storage(
Settings::new().unwrap(),
StorageImpl::PostgresqlTest,
tx,
Box::new(services::MockApiClient),
))
.await;
+ let state = Arc::new(app_state)
+ .get_session_state("public", || {})
+ .unwrap();
connector_integration
.execute_pretasks(&mut request, &state)
.await?;
@@ -639,13 +654,16 @@ pub trait ConnectorActions: Connector {
let mut request = self.get_payout_request(connector_payout_id, payout_type, payment_info);
let tx: oneshot::Sender<()> = oneshot::channel().0;
- let state = Box::pin(routes::AppState::with_storage(
+ let app_state = Box::pin(routes::AppState::with_storage(
Settings::new().unwrap(),
StorageImpl::PostgresqlTest,
tx,
Box::new(services::MockApiClient),
))
.await;
+ let state = Arc::new(app_state)
+ .get_session_state("public", || {})
+ .unwrap();
connector_integration
.execute_pretasks(&mut request, &state)
.await?;
@@ -681,13 +699,16 @@ pub trait ConnectorActions: Connector {
request.connector_customer = connector_customer;
let tx: oneshot::Sender<()> = oneshot::channel().0;
- let state = Box::pin(routes::AppState::with_storage(
+ let app_state = Box::pin(routes::AppState::with_storage(
Settings::new().unwrap(),
StorageImpl::PostgresqlTest,
tx,
Box::new(services::MockApiClient),
))
.await;
+ let state = Arc::new(app_state)
+ .get_session_state("public", || {})
+ .unwrap();
connector_integration
.execute_pretasks(&mut request, &state)
.await?;
@@ -723,13 +744,16 @@ pub trait ConnectorActions: Connector {
self.get_payout_request(Some(connector_payout_id), payout_type, payment_info);
let tx: oneshot::Sender<()> = oneshot::channel().0;
- let state = Box::pin(routes::AppState::with_storage(
+ let app_state = Box::pin(routes::AppState::with_storage(
Settings::new().unwrap(),
StorageImpl::PostgresqlTest,
tx,
Box::new(services::MockApiClient),
))
.await;
+ let state = Arc::new(app_state)
+ .get_session_state("public", || {})
+ .unwrap();
connector_integration
.execute_pretasks(&mut request, &state)
.await?;
@@ -811,13 +835,16 @@ pub trait ConnectorActions: Connector {
let mut request = self.get_payout_request(None, payout_type, payment_info);
let tx = oneshot::channel().0;
- let state = Box::pin(routes::AppState::with_storage(
+ let app_state = Box::pin(routes::AppState::with_storage(
Settings::new().unwrap(),
StorageImpl::PostgresqlTest,
tx,
Box::new(services::MockApiClient),
))
.await;
+ let state = Arc::new(app_state)
+ .get_session_state("public", || {})
+ .unwrap();
connector_integration
.execute_pretasks(&mut request, &state)
.await?;
@@ -844,13 +871,16 @@ async fn call_connector<
let conf = Settings::new().unwrap();
let tx: oneshot::Sender<()> = oneshot::channel().0;
- let state = Box::pin(routes::AppState::with_storage(
+ let app_state = Box::pin(routes::AppState::with_storage(
conf,
StorageImpl::PostgresqlTest,
tx,
Box::new(services::MockApiClient),
))
.await;
+ let state = Arc::new(app_state)
+ .get_session_state("public", || {})
+ .unwrap();
services::api::execute_connector_processing_step(
&state,
integration,
diff --git a/crates/router/tests/payments.rs b/crates/router/tests/payments.rs
index e76eee4c17..ed11f3b8b1 100644
--- a/crates/router/tests/payments.rs
+++ b/crates/router/tests/payments.rs
@@ -2,6 +2,8 @@
mod utils;
+use std::sync::Arc;
+
use common_utils::{id_type, types::MinorUnit};
use router::{
configs,
@@ -276,13 +278,16 @@ async fn payments_create_core() {
use configs::settings::Settings;
let conf = Settings::new().expect("invalid settings");
let tx: oneshot::Sender<()> = oneshot::channel().0;
- let state = Box::pin(routes::AppState::with_storage(
+ let app_state = Box::pin(routes::AppState::with_storage(
conf,
StorageImpl::PostgresqlTest,
tx,
Box::new(services::MockApiClient),
))
.await;
+ let state = Arc::new(app_state)
+ .get_session_state("public", || {})
+ .unwrap();
let key_store = state
.store
@@ -457,13 +462,16 @@ async fn payments_create_core_adyen_no_redirect() {
use crate::configs::settings::Settings;
let conf = Settings::new().expect("invalid settings");
let tx: oneshot::Sender<()> = oneshot::channel().0;
- let state = Box::pin(routes::AppState::with_storage(
+ let app_state = Box::pin(routes::AppState::with_storage(
conf,
StorageImpl::PostgresqlTest,
tx,
Box::new(services::MockApiClient),
))
.await;
+ let state = Arc::new(app_state)
+ .get_session_state("public", || {})
+ .unwrap();
let customer_id = format!("cust_{}", Uuid::new_v4());
let merchant_id = "arunraj".to_string();
diff --git a/crates/router/tests/payments2.rs b/crates/router/tests/payments2.rs
index 42cfe3b74c..4c178e4122 100644
--- a/crates/router/tests/payments2.rs
+++ b/crates/router/tests/payments2.rs
@@ -2,6 +2,8 @@
mod utils;
+use std::sync::Arc;
+
use common_utils::{id_type, types::MinorUnit};
use router::{
core::payments,
@@ -36,13 +38,16 @@ async fn payments_create_core() {
use router::configs::settings::Settings;
let conf = Settings::new().expect("invalid settings");
let tx: oneshot::Sender<()> = oneshot::channel().0;
- let state = Box::pin(routes::AppState::with_storage(
+ let app_state = Box::pin(routes::AppState::with_storage(
conf,
StorageImpl::PostgresqlTest,
tx,
Box::new(services::MockApiClient),
))
.await;
+ let state = Arc::new(app_state)
+ .get_session_state("public", || {})
+ .unwrap();
let key_store = state
.store
@@ -224,13 +229,16 @@ async fn payments_create_core_adyen_no_redirect() {
let conf = Settings::new().expect("invalid settings");
let tx: oneshot::Sender<()> = oneshot::channel().0;
- let state = Box::pin(routes::AppState::with_storage(
+ let app_state = Box::pin(routes::AppState::with_storage(
conf,
StorageImpl::PostgresqlTest,
tx,
Box::new(services::MockApiClient),
))
.await;
+ let state = Arc::new(app_state)
+ .get_session_state("public", || {})
+ .unwrap();
let customer_id = format!("cust_{}", Uuid::new_v4());
let merchant_id = "arunraj".to_string();
diff --git a/crates/router/tests/services.rs b/crates/router/tests/services.rs
index eff7fe7f87..d907000ccc 100644
--- a/crates/router/tests/services.rs
+++ b/crates/router/tests/services.rs
@@ -1,4 +1,4 @@
-use std::sync::atomic;
+use std::sync::{atomic, Arc};
use router::{configs::settings::Settings, routes, services};
@@ -6,16 +6,20 @@ mod utils;
#[tokio::test]
#[should_panic]
+#[allow(clippy::unwrap_used)]
async fn get_redis_conn_failure() {
// Arrange
utils::setup().await;
let (tx, _) = tokio::sync::oneshot::channel();
- let state = Box::pin(routes::AppState::new(
+ let app_state = Box::pin(routes::AppState::new(
Settings::default(),
tx,
Box::new(services::MockApiClient),
))
.await;
+ let state = Arc::new(app_state)
+ .get_session_state("public", || {})
+ .unwrap();
let _ = state.store.get_redis_conn().map(|conn| {
conn.is_redis_available
@@ -30,16 +34,20 @@ async fn get_redis_conn_failure() {
}
#[tokio::test]
+#[allow(clippy::unwrap_used)]
async fn get_redis_conn_success() {
// Arrange
Box::pin(utils::setup()).await;
let (tx, _) = tokio::sync::oneshot::channel();
- let state = Box::pin(routes::AppState::new(
+ let app_state = Box::pin(routes::AppState::new(
Settings::default(),
tx,
Box::new(services::MockApiClient),
))
.await;
+ let state = Arc::new(app_state)
+ .get_session_state("public", || {})
+ .unwrap();
// Act
let result = state.store.get_redis_conn();
diff --git a/crates/scheduler/src/consumer.rs b/crates/scheduler/src/consumer.rs
index a95ac49324..3e15a7cde0 100644
--- a/crates/scheduler/src/consumer.rs
+++ b/crates/scheduler/src/consumer.rs
@@ -1,6 +1,9 @@
// TODO: Figure out what to log
-use std::sync::{self, atomic};
+use std::{
+ sync::{self, atomic},
+ time as std_time,
+};
pub mod types;
pub mod workflows;
@@ -22,7 +25,7 @@ use super::env::logger;
pub use super::workflows::ProcessTrackerWorkflow;
use crate::{
configs::settings::SchedulerSettings, db::process_tracker::ProcessTrackerInterface, errors,
- metrics, utils as pt_utils, SchedulerAppState, SchedulerInterface,
+ metrics, utils as pt_utils, SchedulerAppState, SchedulerInterface, SchedulerSessionState,
};
// Valid consumer business statuses
@@ -31,12 +34,16 @@ pub fn valid_business_statuses() -> Vec<&'static str> {
}
#[instrument(skip_all)]
-pub async fn start_consumer<T: SchedulerAppState + 'static>(
+pub async fn start_consumer<T: SchedulerAppState + 'static, U: SchedulerSessionState + 'static, F>(
state: &T,
settings: sync::Arc<SchedulerSettings>,
- workflow_selector: impl workflows::ProcessTrackerWorkflows<T> + 'static + Copy + std::fmt::Debug,
+ workflow_selector: impl workflows::ProcessTrackerWorkflows<U> + 'static + Copy + std::fmt::Debug,
(tx, mut rx): (mpsc::Sender<()>, mpsc::Receiver<()>),
-) -> CustomResult<(), errors::ProcessTrackerError> {
+ app_state_to_session_state: F,
+) -> CustomResult<(), errors::ProcessTrackerError>
+where
+ F: Fn(&T, &str) -> CustomResult<U, errors::ProcessTrackerError>,
+{
use std::time::Duration;
use rand::distributions::{Distribution, Uniform};
@@ -77,17 +84,29 @@ pub async fn start_consumer<T: SchedulerAppState + 'static>(
if settings.consumer.disabled {
continue;
}
+ consumer_operation_counter.fetch_add(1, atomic::Ordering::SeqCst);
+ let start_time = std_time::Instant::now();
+ let tenants = state.get_tenants();
+ for tenant in tenants {
+ let session_state = app_state_to_session_state(state, tenant.as_str())?;
+ pt_utils::consumer_operation_handler(
+ session_state.clone(),
+ settings.clone(),
+ |error| {
+ logger::error!(?error, "Failed to perform consumer operation");
+ },
+ workflow_selector,
+ )
+ .await;
+ }
+
+ let end_time = std_time::Instant::now();
+ let duration = end_time.saturating_duration_since(start_time).as_secs_f64();
+ logger::debug!("Time taken to execute consumer_operation: {}s", duration);
- pt_utils::consumer_operation_handler(
- state.clone(),
- settings.clone(),
- |error| {
- logger::error!(?error, "Failed to perform consumer operation");
- },
- sync::Arc::clone(&consumer_operation_counter),
- workflow_selector,
- )
- .await;
+ let current_count =
+ consumer_operation_counter.fetch_sub(1, atomic::Ordering::SeqCst);
+ logger::info!("Current tasks being executed: {}", current_count);
}
Ok(()) | Err(mpsc::error::TryRecvError::Disconnected) => {
logger::debug!("Awaiting shutdown!");
@@ -116,7 +135,7 @@ pub async fn start_consumer<T: SchedulerAppState + 'static>(
}
#[instrument(skip_all)]
-pub async fn consumer_operations<T: SchedulerAppState + 'static>(
+pub async fn consumer_operations<T: SchedulerSessionState + 'static>(
state: &T,
settings: &SchedulerSettings,
workflow_selector: impl workflows::ProcessTrackerWorkflows<T> + 'static + Copy + std::fmt::Debug,
@@ -125,13 +144,10 @@ pub async fn consumer_operations<T: SchedulerAppState + 'static>(
let group_name = settings.consumer.consumer_group.clone();
let consumer_name = format!("consumer_{}", Uuid::new_v4());
- let group_created = &mut state
+ let _group_created = &mut state
.get_db()
.consumer_group_create(&stream_name, &group_name, &RedisEntryId::AfterLastID)
.await;
- if group_created.is_err() {
- logger::info!("Consumer group {group_name} already exists");
- }
let mut tasks = state
.get_db()
@@ -139,7 +155,9 @@ pub async fn consumer_operations<T: SchedulerAppState + 'static>(
.fetch_consumer_tasks(&stream_name, &group_name, &consumer_name)
.await?;
- logger::info!("{} picked {} tasks", consumer_name, tasks.len());
+ if !tasks.is_empty() {
+ logger::info!("{} picked {} tasks", consumer_name, tasks.len());
+ }
let mut handler = vec![];
for task in tasks.iter_mut() {
@@ -216,11 +234,10 @@ pub async fn start_workflow<T>(
workflow_selector: impl workflows::ProcessTrackerWorkflows<T> + 'static + std::fmt::Debug,
) -> CustomResult<(), errors::ProcessTrackerError>
where
- T: SchedulerAppState,
+ T: SchedulerSessionState,
{
tracing::Span::current().record("workflow_id", Uuid::new_v4().to_string());
logger::info!(pt.name=?process.name, pt.id=%process.id);
-
let res = workflow_selector
.trigger_workflow(&state.clone(), process.clone())
.await
diff --git a/crates/scheduler/src/consumer/workflows.rs b/crates/scheduler/src/consumer/workflows.rs
index 3e8a4c8e50..bbece87f30 100644
--- a/crates/scheduler/src/consumer/workflows.rs
+++ b/crates/scheduler/src/consumer/workflows.rs
@@ -3,7 +3,7 @@ use common_utils::errors::CustomResult;
pub use diesel_models::process_tracker as storage;
use router_env::logger;
-use crate::{errors, SchedulerAppState};
+use crate::{errors, SchedulerSessionState};
pub type WorkflowSelectorFn =
fn(&storage::ProcessTracker) -> Result<(), errors::ProcessTrackerError>;
@@ -26,7 +26,7 @@ pub trait ProcessTrackerWorkflows<T>: Send + Sync {
process: storage::ProcessTracker,
) -> CustomResult<(), errors::ProcessTrackerError>
where
- T: SchedulerAppState,
+ T: SchedulerSessionState,
{
let app_state = &state.clone();
let output = operation.execute_workflow(app_state, process.clone()).await;
diff --git a/crates/scheduler/src/errors.rs b/crates/scheduler/src/errors.rs
index e630287c31..52ea03e0c4 100644
--- a/crates/scheduler/src/errors.rs
+++ b/crates/scheduler/src/errors.rs
@@ -59,6 +59,8 @@ pub enum ProcessTrackerError {
EEmailError(error_stack::Report<EmailError>),
#[error("Type Conversion error")]
TypeConversionError,
+ #[error("Tenant not found")]
+ TenantNotFound,
}
#[macro_export]
diff --git a/crates/scheduler/src/producer.rs b/crates/scheduler/src/producer.rs
index 397aab84e9..6390bc6689 100644
--- a/crates/scheduler/src/producer.rs
+++ b/crates/scheduler/src/producer.rs
@@ -16,17 +16,20 @@ use super::{
};
use crate::{
configs::settings::SchedulerSettings, errors, flow::SchedulerFlow,
- scheduler::SchedulerInterface, utils::*, SchedulerAppState,
+ scheduler::SchedulerInterface, utils::*, SchedulerAppState, SchedulerSessionState,
};
#[instrument(skip_all)]
-pub async fn start_producer<T>(
+pub async fn start_producer<T, U, F>(
state: &T,
scheduler_settings: Arc<SchedulerSettings>,
(tx, mut rx): (mpsc::Sender<()>, mpsc::Receiver<()>),
+ app_state_to_session_state: F,
) -> CustomResult<(), errors::ProcessTrackerError>
where
+ F: Fn(&T, &str) -> CustomResult<U, errors::ProcessTrackerError>,
T: SchedulerAppState,
+ U: SchedulerSessionState,
{
use std::time::Duration;
@@ -64,13 +67,17 @@ where
match rx.try_recv() {
Err(mpsc::error::TryRecvError::Empty) => {
interval.tick().await;
- match run_producer_flow(state, &scheduler_settings).await {
- Ok(_) => (),
- Err(error) => {
- // Intentionally not propagating error to caller.
- // Any errors that occur in the producer flow must be handled here only, as
- // this is the topmost level function which is concerned with the producer flow.
- error!(%error);
+ let tenants = state.get_tenants();
+ for tenant in tenants {
+ let session_state = app_state_to_session_state(state, tenant.as_str())?;
+ match run_producer_flow(&session_state, &scheduler_settings).await {
+ Ok(_) => (),
+ Err(error) => {
+ // Intentionally not propagating error to caller.
+ // Any errors that occur in the producer flow must be handled here only, as
+ // this is the topmost level function which is concerned with the producer flow.
+ error!(%error);
+ }
}
}
}
@@ -78,7 +85,7 @@ where
logger::debug!("Awaiting shutdown!");
rx.close();
shutdown_interval.tick().await;
- logger::info!("Terminating consumer");
+ logger::info!("Terminating producer");
break;
}
}
@@ -97,7 +104,7 @@ pub async fn run_producer_flow<T>(
settings: &SchedulerSettings,
) -> CustomResult<(), errors::ProcessTrackerError>
where
- T: SchedulerAppState,
+ T: SchedulerSessionState,
{
lock_acquire_release::<_, _, _>(state.get_db().as_scheduler(), settings, move || async {
let tasks = fetch_producer_tasks(state.get_db().as_scheduler(), settings).await?;
diff --git a/crates/scheduler/src/scheduler.rs b/crates/scheduler/src/scheduler.rs
index 273f10819f..39a45d02ba 100644
--- a/crates/scheduler/src/scheduler.rs
+++ b/crates/scheduler/src/scheduler.rs
@@ -52,22 +52,46 @@ impl SchedulerInterface for MockDb {}
#[async_trait::async_trait]
pub trait SchedulerAppState: Send + Sync + Clone {
+ fn get_tenants(&self) -> Vec<String>;
+}
+#[async_trait::async_trait]
+pub trait SchedulerSessionState: Send + Sync + Clone {
fn get_db(&self) -> Box<dyn SchedulerInterface>;
}
-
-pub async fn start_process_tracker<T: SchedulerAppState + 'static>(
+pub async fn start_process_tracker<
+ T: SchedulerAppState + 'static,
+ U: SchedulerSessionState + 'static,
+ F,
+>(
state: &T,
scheduler_flow: SchedulerFlow,
scheduler_settings: Arc<SchedulerSettings>,
channel: (mpsc::Sender<()>, mpsc::Receiver<()>),
- runner_from_task: impl workflows::ProcessTrackerWorkflows<T> + 'static + Copy + std::fmt::Debug,
-) -> CustomResult<(), errors::ProcessTrackerError> {
+ runner_from_task: impl workflows::ProcessTrackerWorkflows<U> + 'static + Copy + std::fmt::Debug,
+ app_state_to_session_state: F,
+) -> CustomResult<(), errors::ProcessTrackerError>
+where
+ F: Fn(&T, &str) -> CustomResult<U, errors::ProcessTrackerError>,
+{
match scheduler_flow {
SchedulerFlow::Producer => {
- producer::start_producer(state, scheduler_settings, channel).await?
+ producer::start_producer(
+ state,
+ scheduler_settings,
+ channel,
+ app_state_to_session_state,
+ )
+ .await?
}
SchedulerFlow::Consumer => {
- consumer::start_consumer(state, scheduler_settings, runner_from_task, channel).await?
+ consumer::start_consumer(
+ state,
+ scheduler_settings,
+ runner_from_task,
+ channel,
+ app_state_to_session_state,
+ )
+ .await?
}
SchedulerFlow::Cleaner => {
error!("This flow has not been implemented yet!");
diff --git a/crates/scheduler/src/utils.rs b/crates/scheduler/src/utils.rs
index 8b80b7c72c..7f073a8e10 100644
--- a/crates/scheduler/src/utils.rs
+++ b/crates/scheduler/src/utils.rs
@@ -1,7 +1,4 @@
-use std::{
- sync::{self, atomic},
- time as std_time,
-};
+use std::sync;
use common_utils::errors::CustomResult;
use diesel_models::enums::{self, ProcessTrackerStatus};
@@ -17,7 +14,7 @@ use super::{
};
use crate::{
configs::settings::SchedulerSettings, consumer::types::ProcessTrackerBatch, errors,
- flow::SchedulerFlow, metrics, SchedulerAppState, SchedulerInterface,
+ flow::SchedulerFlow, metrics, SchedulerInterface, SchedulerSessionState,
};
pub async fn divide_and_append_tasks<T>(
@@ -258,26 +255,16 @@ pub async fn consumer_operation_handler<E, T>(
state: T,
settings: sync::Arc<SchedulerSettings>,
error_handler_fun: E,
- consumer_operation_counter: sync::Arc<atomic::AtomicU64>,
workflow_selector: impl workflows::ProcessTrackerWorkflows<T> + 'static + Copy + std::fmt::Debug,
) where
// Error handler function
E: FnOnce(error_stack::Report<errors::ProcessTrackerError>),
- T: SchedulerAppState + Send + Sync + 'static,
+ T: SchedulerSessionState + Send + Sync + 'static,
{
- consumer_operation_counter.fetch_add(1, atomic::Ordering::SeqCst);
- let start_time = std_time::Instant::now();
-
match consumer::consumer_operations(&state, &settings, workflow_selector).await {
Ok(_) => (),
Err(err) => error_handler_fun(err),
}
- let end_time = std_time::Instant::now();
- let duration = end_time.saturating_duration_since(start_time).as_secs_f64();
- logger::debug!("Time taken to execute consumer_operation: {}s", duration);
-
- let current_count = consumer_operation_counter.fetch_sub(1, atomic::Ordering::SeqCst);
- logger::info!("Current tasks being executed: {}", current_count);
}
pub fn add_histogram_metrics(
diff --git a/crates/storage_impl/src/config.rs b/crates/storage_impl/src/config.rs
index fd95a6d315..e371936a04 100644
--- a/crates/storage_impl/src/config.rs
+++ b/crates/storage_impl/src/config.rs
@@ -1,3 +1,4 @@
+use common_utils::DbConnectionParams;
use masking::Secret;
#[derive(Debug, Clone, serde::Deserialize)]
@@ -14,6 +15,29 @@ pub struct Database {
pub max_lifetime: Option<u64>,
}
+impl DbConnectionParams for Database {
+ fn get_username(&self) -> &str {
+ &self.username
+ }
+ fn get_password(&self) -> Secret<String> {
+ self.password.clone()
+ }
+ fn get_host(&self) -> &str {
+ &self.host
+ }
+ fn get_port(&self) -> u16 {
+ self.port
+ }
+ fn get_dbname(&self) -> &str {
+ &self.dbname
+ }
+}
+
+pub trait TenantConfig: Send + Sync {
+ fn get_schema(&self) -> &str;
+ fn get_redis_key_prefix(&self) -> &str;
+}
+
#[derive(Debug, serde::Deserialize, Clone, Copy, Default)]
#[serde(rename_all = "PascalCase")]
pub enum QueueStrategy {
diff --git a/crates/storage_impl/src/database/store.rs b/crates/storage_impl/src/database/store.rs
index 17ae76b5bb..543cc47870 100644
--- a/crates/storage_impl/src/database/store.rs
+++ b/crates/storage_impl/src/database/store.rs
@@ -1,11 +1,11 @@
use async_bb8_diesel::{AsyncConnection, ConnectionError};
use bb8::CustomizeConnection;
+use common_utils::DbConnectionParams;
use diesel::PgConnection;
use error_stack::ResultExt;
use hyperswitch_domain_models::errors::{StorageError, StorageResult};
-use masking::PeekInterface;
-use crate::config::Database;
+use crate::config::{Database, TenantConfig};
pub type PgPool = bb8::Pool<async_bb8_diesel::ConnectionManager<PgConnection>>;
pub type PgPooledConn = async_bb8_diesel::Connection<PgConnection>;
@@ -13,7 +13,11 @@ pub type PgPooledConn = async_bb8_diesel::Connection<PgConnection>;
#[async_trait::async_trait]
pub trait DatabaseStore: Clone + Send + Sync {
type Config: Send;
- async fn new(config: Self::Config, test_transaction: bool) -> StorageResult<Self>;
+ async fn new(
+ config: Self::Config,
+ tenant_config: &dyn TenantConfig,
+ test_transaction: bool,
+ ) -> StorageResult<Self>;
fn get_master_pool(&self) -> &PgPool;
fn get_replica_pool(&self) -> &PgPool;
}
@@ -26,9 +30,14 @@ pub struct Store {
#[async_trait::async_trait]
impl DatabaseStore for Store {
type Config = Database;
- async fn new(config: Database, test_transaction: bool) -> StorageResult<Self> {
+ async fn new(
+ config: Database,
+ tenant_config: &dyn TenantConfig,
+ test_transaction: bool,
+ ) -> StorageResult<Self> {
Ok(Self {
- master_pool: diesel_make_pg_pool(&config, test_transaction).await?,
+ master_pool: diesel_make_pg_pool(&config, tenant_config.get_schema(), test_transaction)
+ .await?,
})
}
@@ -50,14 +59,23 @@ pub struct ReplicaStore {
#[async_trait::async_trait]
impl DatabaseStore for ReplicaStore {
type Config = (Database, Database);
- async fn new(config: (Database, Database), test_transaction: bool) -> StorageResult<Self> {
+ async fn new(
+ config: (Database, Database),
+ tenant_config: &dyn TenantConfig,
+ test_transaction: bool,
+ ) -> StorageResult<Self> {
let (master_config, replica_config) = config;
- let master_pool = diesel_make_pg_pool(&master_config, test_transaction)
- .await
- .attach_printable("failed to create master pool")?;
- let replica_pool = diesel_make_pg_pool(&replica_config, test_transaction)
- .await
- .attach_printable("failed to create replica pool")?;
+ let master_pool =
+ diesel_make_pg_pool(&master_config, tenant_config.get_schema(), test_transaction)
+ .await
+ .attach_printable("failed to create master pool")?;
+ let replica_pool = diesel_make_pg_pool(
+ &replica_config,
+ tenant_config.get_schema(),
+ test_transaction,
+ )
+ .await
+ .attach_printable("failed to create replica pool")?;
Ok(Self {
master_pool,
replica_pool,
@@ -75,16 +93,10 @@ impl DatabaseStore for ReplicaStore {
pub async fn diesel_make_pg_pool(
database: &Database,
+ schema: &str,
test_transaction: bool,
) -> StorageResult<PgPool> {
- let database_url = format!(
- "postgres://{}:{}@{}:{}/{}",
- database.username,
- database.password.peek(),
- database.host,
- database.port,
- database.dbname
- );
+ let database_url = database.get_database_url(schema);
let manager = async_bb8_diesel::ConnectionManager::<PgConnection>::new(database_url);
let mut pool = bb8::Pool::builder()
.max_size(database.pool_size)
diff --git a/crates/storage_impl/src/lib.rs b/crates/storage_impl/src/lib.rs
index b1582bb6e9..d55f812c5a 100644
--- a/crates/storage_impl/src/lib.rs
+++ b/crates/storage_impl/src/lib.rs
@@ -29,7 +29,7 @@ use database::store::PgPool;
#[cfg(not(feature = "payouts"))]
use hyperswitch_domain_models::{PayoutAttemptInterface, PayoutsInterface};
pub use mock_db::MockDb;
-use redis_interface::{errors::RedisError, SaddReply};
+use redis_interface::{errors::RedisError, RedisConnectionPool, SaddReply};
pub use crate::database::store::DatabaseStore;
#[cfg(not(feature = "payouts"))]
@@ -38,7 +38,7 @@ pub use crate::database::store::Store;
#[derive(Debug, Clone)]
pub struct RouterStore<T: DatabaseStore> {
db_store: T,
- cache_store: RedisStore,
+ cache_store: Arc<RedisStore>,
master_encryption_key: StrongSecret<Vec<u8>>,
pub request_id: Option<String>,
}
@@ -55,19 +55,23 @@ where
tokio::sync::oneshot::Sender<()>,
&'static str,
);
- async fn new(config: Self::Config, test_transaction: bool) -> StorageResult<Self> {
+ async fn new(
+ config: Self::Config,
+ tenant_config: &dyn config::TenantConfig,
+ test_transaction: bool,
+ ) -> StorageResult<Self> {
let (db_conf, cache_conf, encryption_key, cache_error_signal, inmemory_cache_stream) =
config;
if test_transaction {
- Self::test_store(db_conf, &cache_conf, encryption_key)
+ Self::test_store(db_conf, tenant_config, &cache_conf, encryption_key)
.await
.attach_printable("failed to create test router store")
} else {
Self::from_config(
db_conf,
- &cache_conf,
+ tenant_config,
encryption_key,
- cache_error_signal,
+ Self::cache_store(&cache_conf, cache_error_signal).await?,
inmemory_cache_stream,
)
.await
@@ -83,9 +87,7 @@ where
}
impl<T: DatabaseStore> RedisConnInterface for RouterStore<T> {
- fn get_redis_conn(
- &self,
- ) -> error_stack::Result<Arc<redis_interface::RedisConnectionPool>, RedisError> {
+ fn get_redis_conn(&self) -> error_stack::Result<Arc<RedisConnectionPool>, RedisError> {
self.cache_store.get_redis_conn()
}
}
@@ -93,23 +95,26 @@ impl<T: DatabaseStore> RedisConnInterface for RouterStore<T> {
impl<T: DatabaseStore> RouterStore<T> {
pub async fn from_config(
db_conf: T::Config,
- cache_conf: &redis_interface::RedisSettings,
+ tenant_config: &dyn config::TenantConfig,
encryption_key: StrongSecret<Vec<u8>>,
- cache_error_signal: tokio::sync::oneshot::Sender<()>,
+ cache_store: Arc<RedisStore>,
inmemory_cache_stream: &str,
) -> StorageResult<Self> {
- let db_store = T::new(db_conf, false).await?;
- let cache_store = RedisStore::new(cache_conf)
- .await
- .change_context(StorageError::InitializationError)
- .attach_printable("Failed to create cache store")?;
- cache_store.set_error_callback(cache_error_signal);
+ let db_store = T::new(db_conf, tenant_config, false).await?;
+ let redis_conn = cache_store.redis_conn.clone();
+ let cache_store = Arc::new(RedisStore {
+ redis_conn: Arc::new(RedisConnectionPool::clone(
+ &redis_conn,
+ tenant_config.get_redis_key_prefix(),
+ )),
+ });
cache_store
.redis_conn
.subscribe(inmemory_cache_stream)
.await
.change_context(StorageError::InitializationError)
.attach_printable("Failed to subscribe to inmemory cache stream")?;
+
Ok(Self {
db_store,
cache_store,
@@ -118,6 +123,18 @@ impl<T: DatabaseStore> RouterStore<T> {
})
}
+ pub async fn cache_store(
+ cache_conf: &redis_interface::RedisSettings,
+ cache_error_signal: tokio::sync::oneshot::Sender<()>,
+ ) -> StorageResult<Arc<RedisStore>> {
+ let cache_store = RedisStore::new(cache_conf)
+ .await
+ .change_context(StorageError::InitializationError)
+ .attach_printable("Failed to create cache store")?;
+ cache_store.set_error_callback(cache_error_signal);
+ Ok(Arc::new(cache_store))
+ }
+
pub fn master_key(&self) -> &StrongSecret<Vec<u8>> {
&self.master_encryption_key
}
@@ -127,18 +144,19 @@ impl<T: DatabaseStore> RouterStore<T> {
/// Will panic if `CONNECTOR_AUTH_FILE_PATH` is not set
pub async fn test_store(
db_conf: T::Config,
+ tenant_config: &dyn config::TenantConfig,
cache_conf: &redis_interface::RedisSettings,
encryption_key: StrongSecret<Vec<u8>>,
) -> StorageResult<Self> {
// TODO: create an error enum and return proper error here
- let db_store = T::new(db_conf, true).await?;
+ let db_store = T::new(db_conf, tenant_config, true).await?;
let cache_store = RedisStore::new(cache_conf)
.await
.change_context(StorageError::InitializationError)
.attach_printable("failed to create redis cache")?;
Ok(Self {
db_store,
- cache_store,
+ cache_store: Arc::new(cache_store),
master_encryption_key: encryption_key,
request_id: None,
})
@@ -162,9 +180,13 @@ where
T: DatabaseStore,
{
type Config = (RouterStore<T>, String, u8, u32, Option<bool>);
- async fn new(config: Self::Config, _test_transaction: bool) -> StorageResult<Self> {
- let (router_store, drainer_stream_name, drainer_num_partitions, ttl_for_kv, soft_kill_mode) =
- config;
+ async fn new(
+ config: Self::Config,
+ tenant_config: &dyn config::TenantConfig,
+ _test_transaction: bool,
+ ) -> StorageResult<Self> {
+ let (router_store, _, drainer_num_partitions, ttl_for_kv, soft_kill_mode) = config;
+ let drainer_stream_name = format!("{}_{}", tenant_config.get_schema(), config.1);
Ok(Self::from_store(
router_store,
drainer_stream_name,
@@ -182,9 +204,7 @@ where
}
impl<T: DatabaseStore> RedisConnInterface for KVRouterStore<T> {
- fn get_redis_conn(
- &self,
- ) -> error_stack::Result<Arc<redis_interface::RedisConnectionPool>, RedisError> {
+ fn get_redis_conn(&self) -> error_stack::Result<Arc<RedisConnectionPool>, RedisError> {
self.router_store.get_redis_conn()
}
}
@@ -282,7 +302,7 @@ pub trait UniqueConstraints {
fn table_name(&self) -> &str;
async fn check_for_constraints(
&self,
- redis_conn: &Arc<redis_interface::RedisConnectionPool>,
+ redis_conn: &Arc<RedisConnectionPool>,
) -> CustomResult<(), RedisError> {
let constraints = self.unique_constraints();
let sadd_result = redis_conn
diff --git a/crates/storage_impl/src/redis/cache.rs b/crates/storage_impl/src/redis/cache.rs
index 4a72b86fef..c0375773b5 100644
--- a/crates/storage_impl/src/redis/cache.rs
+++ b/crates/storage_impl/src/redis/cache.rs
@@ -1,4 +1,4 @@
-use std::{any::Any, borrow::Cow, sync::Arc};
+use std::{any::Any, borrow::Cow, fmt::Debug, sync::Arc};
use common_utils::{
errors::{self, CustomResult},
@@ -8,7 +8,7 @@ use dyn_clone::DynClone;
use error_stack::{Report, ResultExt};
use moka::future::Cache as MokaCache;
use once_cell::sync::Lazy;
-use redis_interface::{errors::RedisError, RedisValue};
+use redis_interface::{errors::RedisError, RedisConnectionPool, RedisValue};
use router_env::tracing::{self, instrument};
use crate::{
@@ -118,6 +118,23 @@ pub struct Cache {
inner: MokaCache<String, Arc<dyn Cacheable>>,
}
+#[derive(Debug, Clone)]
+pub struct CacheKey {
+ pub key: String,
+ // #TODO: make it usage specific enum Eg: CacheKind { Tenant(String), NoTenant, Partition(String) }
+ pub prefix: String,
+}
+
+impl From<CacheKey> for String {
+ fn from(val: CacheKey) -> Self {
+ if val.prefix.is_empty() {
+ val.key
+ } else {
+ format!("{}:{}", val.prefix, val.key)
+ }
+ }
+}
+
impl Cache {
/// With given `time_to_live` and `time_to_idle` creates a moka cache.
///
@@ -138,44 +155,38 @@ impl Cache {
}
}
- pub async fn push<T: Cacheable>(&self, key: String, val: T) {
- self.inner.insert(key, Arc::new(val)).await;
+ pub async fn push<T: Cacheable>(&self, key: CacheKey, val: T) {
+ self.inner.insert(key.into(), Arc::new(val)).await;
}
- pub async fn get_val<T: Clone + Cacheable>(&self, key: &str) -> Option<T> {
- let val = self.inner.get(key).await?;
+ pub async fn get_val<T: Clone + Cacheable>(&self, key: CacheKey) -> Option<T> {
+ let val = self.inner.get::<String>(&key.into()).await?;
(*val).as_any().downcast_ref::<T>().cloned()
}
/// Check if a key exists in cache
- pub async fn exists(&self, key: &str) -> bool {
- self.inner.contains_key(key)
+ pub async fn exists(&self, key: CacheKey) -> bool {
+ self.inner.contains_key::<String>(&key.into())
}
- pub async fn remove(&self, key: &str) {
- self.inner.invalidate(key).await;
+ pub async fn remove(&self, key: CacheKey) {
+ self.inner.invalidate::<String>(&key.into()).await;
}
}
#[instrument(skip_all)]
pub async fn get_or_populate_redis<T, F, Fut>(
- store: &(dyn RedisConnInterface + Send + Sync),
+ redis: &Arc<RedisConnectionPool>,
key: impl AsRef<str>,
fun: F,
) -> CustomResult<T, StorageError>
where
- T: serde::Serialize + serde::de::DeserializeOwned + std::fmt::Debug,
+ T: serde::Serialize + serde::de::DeserializeOwned + Debug,
F: FnOnce() -> Fut + Send,
Fut: futures::Future<Output = CustomResult<T, StorageError>> + Send,
{
let type_name = std::any::type_name::<T>();
let key = key.as_ref();
- let redis = &store
- .get_redis_conn()
- .change_context(StorageError::RedisError(
- RedisError::RedisConnectionError.into(),
- ))
- .attach_printable("Failed to get redis connection")?;
let redis_val = redis.get_and_deserialize_key::<T>(key, type_name).await;
let get_data_set_redis = || async {
let data = fun().await?;
@@ -206,16 +217,35 @@ pub async fn get_or_populate_in_memory<T, F, Fut>(
cache: &Cache,
) -> CustomResult<T, StorageError>
where
- T: Cacheable + serde::Serialize + serde::de::DeserializeOwned + std::fmt::Debug + Clone,
+ T: Cacheable + serde::Serialize + serde::de::DeserializeOwned + Debug + Clone,
F: FnOnce() -> Fut + Send,
Fut: futures::Future<Output = CustomResult<T, StorageError>> + Send,
{
- let cache_val = cache.get_val::<T>(key).await;
+ let redis = &store
+ .get_redis_conn()
+ .change_context(StorageError::RedisError(
+ RedisError::RedisConnectionError.into(),
+ ))
+ .attach_printable("Failed to get redis connection")?;
+ let cache_val = cache
+ .get_val::<T>(CacheKey {
+ key: key.to_string(),
+ prefix: redis.key_prefix.clone(),
+ })
+ .await;
if let Some(val) = cache_val {
Ok(val)
} else {
- let val = get_or_populate_redis(store, key, fun).await?;
- cache.push(key.to_string(), val.clone()).await;
+ let val = get_or_populate_redis(redis, key, fun).await?;
+ cache
+ .push(
+ CacheKey {
+ key: key.to_string(),
+ prefix: redis.key_prefix.clone(),
+ },
+ val.clone(),
+ )
+ .await;
Ok(val)
}
}
@@ -223,7 +253,7 @@ where
#[instrument(skip_all)]
pub async fn redact_cache<T, F, Fut>(
store: &(dyn RedisConnInterface + Send + Sync),
- key: &str,
+ key: &'static str,
fun: F,
in_memory: Option<&Cache>,
) -> CustomResult<T, StorageError>
@@ -232,7 +262,6 @@ where
Fut: futures::Future<Output = CustomResult<T, StorageError>> + Send,
{
let data = fun().await?;
- in_memory.async_map(|cache| cache.remove(key)).await;
let redis_conn = store
.get_redis_conn()
@@ -240,6 +269,11 @@ where
RedisError::RedisConnectionError.into(),
))
.attach_printable("Failed to get redis connection")?;
+ let tenant_key = CacheKey {
+ key: key.to_string(),
+ prefix: redis_conn.key_prefix.clone(),
+ };
+ in_memory.async_map(|cache| cache.remove(tenant_key)).await;
redis_conn
.delete_key(key)
@@ -312,9 +346,22 @@ mod cache_tests {
#[tokio::test]
async fn construct_and_get_cache() {
let cache = Cache::new(1800, 1800, None);
- cache.push("key".to_string(), "val".to_string()).await;
+ cache
+ .push(
+ CacheKey {
+ key: "key".to_string(),
+ prefix: "prefix".to_string(),
+ },
+ "val".to_string(),
+ )
+ .await;
assert_eq!(
- cache.get_val::<String>("key").await,
+ cache
+ .get_val::<String>(CacheKey {
+ key: "key".to_string(),
+ prefix: "prefix".to_string()
+ })
+ .await,
Some(String::from("val"))
);
}
@@ -322,25 +369,78 @@ mod cache_tests {
#[tokio::test]
async fn eviction_on_size_test() {
let cache = Cache::new(2, 2, Some(0));
- cache.push("key".to_string(), "val".to_string()).await;
- assert_eq!(cache.get_val::<String>("key").await, None);
+ cache
+ .push(
+ CacheKey {
+ key: "key".to_string(),
+ prefix: "prefix".to_string(),
+ },
+ "val".to_string(),
+ )
+ .await;
+ assert_eq!(
+ cache
+ .get_val::<String>(CacheKey {
+ key: "key".to_string(),
+ prefix: "prefix".to_string()
+ })
+ .await,
+ None
+ );
}
#[tokio::test]
async fn invalidate_cache_for_key() {
let cache = Cache::new(1800, 1800, None);
- cache.push("key".to_string(), "val".to_string()).await;
+ cache
+ .push(
+ CacheKey {
+ key: "key".to_string(),
+ prefix: "prefix".to_string(),
+ },
+ "val".to_string(),
+ )
+ .await;
+
+ cache
+ .remove(CacheKey {
+ key: "key".to_string(),
+ prefix: "prefix".to_string(),
+ })
+ .await;
- cache.remove("key").await;
-
- assert_eq!(cache.get_val::<String>("key").await, None);
+ assert_eq!(
+ cache
+ .get_val::<String>(CacheKey {
+ key: "key".to_string(),
+ prefix: "prefix".to_string()
+ })
+ .await,
+ None
+ );
}
#[tokio::test]
async fn eviction_on_time_test() {
let cache = Cache::new(2, 2, None);
- cache.push("key".to_string(), "val".to_string()).await;
+ cache
+ .push(
+ CacheKey {
+ key: "key".to_string(),
+ prefix: "prefix".to_string(),
+ },
+ "val".to_string(),
+ )
+ .await;
tokio::time::sleep(std::time::Duration::from_secs(3)).await;
- assert_eq!(cache.get_val::<String>("key").await, None);
+ assert_eq!(
+ cache
+ .get_val::<String>(CacheKey {
+ key: "key".to_string(),
+ prefix: "prefix".to_string()
+ })
+ .await,
+ None
+ );
}
}
diff --git a/crates/storage_impl/src/redis/pub_sub.rs b/crates/storage_impl/src/redis/pub_sub.rs
index 830f6251d6..1f07978424 100644
--- a/crates/storage_impl/src/redis/pub_sub.rs
+++ b/crates/storage_impl/src/redis/pub_sub.rs
@@ -2,7 +2,9 @@ use error_stack::ResultExt;
use redis_interface::{errors as redis_errors, PubsubInterface, RedisValue};
use router_env::{logger, tracing::Instrument};
-use crate::redis::cache::{CacheKind, ACCOUNTS_CACHE, CGRAPH_CACHE, CONFIG_CACHE, ROUTING_CACHE};
+use crate::redis::cache::{
+ CacheKey, CacheKind, ACCOUNTS_CACHE, CGRAPH_CACHE, CONFIG_CACHE, ROUTING_CACHE,
+};
#[async_trait::async_trait]
pub trait PubSubInterface {
@@ -55,7 +57,7 @@ impl PubSubInterface for std::sync::Arc<redis_interface::RedisConnectionPool> {
#[inline]
async fn on_message(&self) -> error_stack::Result<(), redis_errors::RedisError> {
- logger::debug!("Started on message");
+ logger::debug!("Started on message: {:?}", self.key_prefix);
let mut rx = self.subscriber.on_message();
while let Ok(message) = rx.recv().await {
logger::debug!("Invalidating {message:?}");
@@ -71,26 +73,66 @@ impl PubSubInterface for std::sync::Arc<redis_interface::RedisConnectionPool> {
let key = match key {
CacheKind::Config(key) => {
- CONFIG_CACHE.remove(key.as_ref()).await;
+ CONFIG_CACHE
+ .remove(CacheKey {
+ key: key.to_string(),
+ prefix: self.key_prefix.clone(),
+ })
+ .await;
key
}
CacheKind::Accounts(key) => {
- ACCOUNTS_CACHE.remove(key.as_ref()).await;
+ ACCOUNTS_CACHE
+ .remove(CacheKey {
+ key: key.to_string(),
+ prefix: self.key_prefix.clone(),
+ })
+ .await;
key
}
CacheKind::CGraph(key) => {
- CGRAPH_CACHE.remove(key.as_ref()).await;
+ CGRAPH_CACHE
+ .remove(CacheKey {
+ key: key.to_string(),
+ prefix: self.key_prefix.clone(),
+ })
+ .await;
key
}
CacheKind::Routing(key) => {
- ROUTING_CACHE.remove(key.as_ref()).await;
+ ROUTING_CACHE
+ .remove(CacheKey {
+ key: key.to_string(),
+ prefix: self.key_prefix.clone(),
+ })
+ .await;
key
}
CacheKind::All(key) => {
- CONFIG_CACHE.remove(key.as_ref()).await;
- ACCOUNTS_CACHE.remove(key.as_ref()).await;
- CGRAPH_CACHE.remove(key.as_ref()).await;
- ROUTING_CACHE.remove(key.as_ref()).await;
+ CONFIG_CACHE
+ .remove(CacheKey {
+ key: key.to_string(),
+ prefix: self.key_prefix.clone(),
+ })
+ .await;
+ ACCOUNTS_CACHE
+ .remove(CacheKey {
+ key: key.to_string(),
+ prefix: self.key_prefix.clone(),
+ })
+ .await;
+ CGRAPH_CACHE
+ .remove(CacheKey {
+ key: key.to_string(),
+ prefix: self.key_prefix.clone(),
+ })
+ .await;
+ ROUTING_CACHE
+ .remove(CacheKey {
+ key: key.to_string(),
+ prefix: self.key_prefix.clone(),
+ })
+ .await;
key
}
};
diff --git a/loadtest/config/development.toml b/loadtest/config/development.toml
index ad60418339..2abe90f608 100644
--- a/loadtest/config/development.toml
+++ b/loadtest/config/development.toml
@@ -322,3 +322,9 @@ partner_id = ""
[unmasked_headers]
keys = "user-agent"
+
+[multitenancy]
+enabled = false
+
+[multitenancy.tenants]
+public = { name = "hyperswitch", base_url = "http://localhost:8080", schema = "public", redis_key_prefix = ""}
\ No newline at end of file