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

Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
Co-authored-by: Arun Raj M <jarnura47@gmail.com>
This commit is contained in:
Jagan
2024-06-03 17:57:30 +05:30
committed by GitHub
parent a1788b8da9
commit 15d6c3e846
188 changed files with 2260 additions and 1414 deletions

View File

@ -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,