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
Rust adyenbeginner-friendlyfeaturedfinancefintechhacktoberfesthigh-performanceopen-sourceorchestrationpaymentpayment-gatewaypayment-integrationpayment-processingpaymentspayments-platformrestful-apirustsdkstripeworks-with-react
feat(platform): modify queries to support analytics for connected merchant (#11635)
Apoorv Dixit22b2f6f48302
diff --git a/crates/analytics/src/opensearch.rs b/crates/analytics/src/opensearch.rsindex c00ebfc04e..747ef24a9b 100644--- a/crates/analytics/src/opensearch.rs+++ b/crates/analytics/src/opensearch.rs@@ -795,8 +795,9 @@ impl OpenSearchQueryBuilder {AuthInfo::MerchantLevel {org_id,merchant_ids,+ processor_merchant_ids,} => {- let must_clauses = vec![+ let mut must_clauses = vec![json!({"term": {"organization_id.keyword": {@@ -811,6 +812,14 @@ impl OpenSearchQueryBuilder {}),];+ if let Some(processor_mids) = processor_merchant_ids {+ must_clauses.push(json!({+ "terms": {+ "processor_merchant_id.keyword": processor_mids+ }+ }));+ }+json!({"bool": {"must": must_clauses@@ -821,8 +830,9 @@ impl OpenSearchQueryBuilder {org_id,merchant_id,profile_ids,+ processor_merchant_id,} => {- let must_clauses = vec![+ let mut must_clauses = vec![json!({"term": {"organization_id.keyword": {@@ -844,6 +854,16 @@ impl OpenSearchQueryBuilder {}),];+ if let Some(processor_mid) = processor_merchant_id {+ must_clauses.push(json!({+ "term": {+ "processor_merchant_id.keyword": {+ "value": processor_mid+ }+ }+ }));+ }+json!({"bool": {"must": must_clausesdiff --git a/crates/analytics/src/payment_intents/core.rs b/crates/analytics/src/payment_intents/core.rsindex 0a512c419e..793104b1bc 100644--- a/crates/analytics/src/payment_intents/core.rs+++ b/crates/analytics/src/payment_intents/core.rs@@ -365,62 +365,44 @@ pub async fn get_metrics(pub async fn get_filters(pool: &AnalyticsProvider,req: GetPaymentIntentFiltersRequest,- merchant_id: &common_utils::id_type::MerchantId,+ auth: &AuthInfo,) -> AnalyticsResult<PaymentIntentFiltersResponse> {let mut res = PaymentIntentFiltersResponse::default();for dim in req.group_by_names {let values = match pool {- AnalyticsProvider::Sqlx(pool) => {- get_payment_intent_filter_for_dimension(dim, merchant_id, &req.time_range, pool)- .await+ AnalyticsProvider::Sqlx(pool) => {+ get_payment_intent_filter_for_dimension(dim, auth, &req.time_range, pool).await}- AnalyticsProvider::Clickhouse(pool) => {- get_payment_intent_filter_for_dimension(dim, merchant_id, &req.time_range, pool)- .await+ AnalyticsProvider::Clickhouse(pool) => {+ get_payment_intent_filter_for_dimension(dim, auth, &req.time_range, pool).await}- AnalyticsProvider::CombinedCkh(sqlx_poll, ckh_pool) => {- let ckh_result = get_payment_intent_filter_for_dimension(- dim,- merchant_id,- &req.time_range,- ckh_pool,- )- .await;- let sqlx_result = get_payment_intent_filter_for_dimension(- dim,- merchant_id,- &req.time_range,- sqlx_poll,- )- .await;+ AnalyticsProvider::CombinedCkh(sqlx_poll, ckh_pool) => {+ let ckh_result =+ get_payment_intent_filter_for_dimension(dim, auth, &req.time_range, ckh_pool)+ .await;+ let sqlx_result =+ get_payment_intent_filter_for_dimension(dim, auth, &req.time_range, sqlx_poll)+ .await;match (&sqlx_result, &ckh_result) {(Ok(ref sqlx_res), Ok(ref ckh_res)) if sqlx_res != ckh_res => {router_env::logger::error!(clickhouse_result=?ckh_res, postgres_result=?sqlx_res, "Mismatch between clickhouse & postgres payment intents analytics filters")- },+ }_ => {}};ckh_result}- AnalyticsProvider::CombinedSqlx(sqlx_poll, ckh_pool) => {- let ckh_result = get_payment_intent_filter_for_dimension(- dim,- merchant_id,- &req.time_range,- ckh_pool,- )- .await;- let sqlx_result = get_payment_intent_filter_for_dimension(- dim,- merchant_id,- &req.time_range,- sqlx_poll,- )- .await;+ AnalyticsProvider::CombinedSqlx(sqlx_poll, ckh_pool) => {+ let ckh_result =+ get_payment_intent_filter_for_dimension(dim, auth, &req.time_range, ckh_pool)+ .await;+ let sqlx_result =+ get_payment_intent_filter_for_dimension(dim, auth, &req.time_range, sqlx_poll)+ .await;match (&sqlx_result, &ckh_result) {(Ok(ref sqlx_res), Ok(ref ckh_res)) if sqlx_res != ckh_res => {router_env::logger::error!(clickhouse_result=?ckh_res, postgres_result=?sqlx_res, "Mismatch between clickhouse & postgres payment intents analytics filters")- },+ }_ => {}};sqlx_resultdiff --git a/crates/analytics/src/payment_intents/filters.rs b/crates/analytics/src/payment_intents/filters.rsindex 1468a67570..bdd654e96f 100644--- a/crates/analytics/src/payment_intents/filters.rs+++ b/crates/analytics/src/payment_intents/filters.rs@@ -5,6 +5,7 @@ use error_stack::ResultExt;use time::PrimitiveDateTime;use crate::{+ enums::AuthInfo,query::{Aggregate, GroupByClause, QueryBuilder, QueryFilter, ToSql, Window},types::{AnalyticsCollection, AnalyticsDataSource, DBEnumWrapper, FiltersError, FiltersResult,@@ -16,7 +17,7 @@ pub trait PaymentIntentFilterAnalytics: LoadRow<PaymentIntentFilterRow> {}pub async fn get_payment_intent_filter_for_dimension<T>(dimension: PaymentIntentDimensions,- merchant_id: &common_utils::id_type::MerchantId,+ auth: &AuthInfo,time_range: &TimeRange,pool: &T,) -> FiltersResult<Vec<PaymentIntentFilterRow>>@@ -36,9 +37,7 @@ where.attach_printable("Error filtering time range").switch()?;- query_builder- .add_filter_clause("merchant_id", merchant_id)- .switch()?;+ auth.set_filter_clause(&mut query_builder).switch()?;query_builder.set_distinct();diff --git a/crates/analytics/src/query.rs b/crates/analytics/src/query.rsindex f8453eca39..bcabee8ebe 100644--- a/crates/analytics/src/query.rs+++ b/crates/analytics/src/query.rs@@ -952,6 +952,7 @@ whereSelf::MerchantLevel {org_id,merchant_ids,+ processor_merchant_ids,} => {builder.add_filter_clause("organization_id", org_id)@@ -959,11 +960,17 @@ wherebuilder.add_filter_in_range_clause("merchant_id", merchant_ids).attach_printable("Error adding merchant_id filter")?;+ if let Some(processor_mids) = processor_merchant_ids {+ builder+ .add_filter_in_range_clause("processor_merchant_id", processor_mids)+ .attach_printable("Error adding processor_merchant_id filter")?;+ }}Self::ProfileLevel {org_id,merchant_id,profile_ids,+ processor_merchant_id,} => {builder.add_filter_clause("organization_id", org_id)@@ -974,6 +981,11 @@ wherebuilder.add_filter_in_range_clause("profile_id", profile_ids).attach_printable("Error adding profile_id filter")?;+ if let Some(processor_mid) = processor_merchant_id {+ builder+ .add_filter_clause("processor_merchant_id", processor_mid)+ .attach_printable("Error adding processor_merchant_id filter")?;+ }}}Ok(())diff --git a/crates/common_utils/src/types/authentication.rs b/crates/common_utils/src/types/authentication.rsindex 331f1e2a65..0ecbd29dcf 100644--- a/crates/common_utils/src/types/authentication.rs+++ b/crates/common_utils/src/types/authentication.rs@@ -22,17 +22,27 @@ pub enum AuthInfo {MerchantLevel {/// org_id: OrganizationIdorg_id: id_type::OrganizationId,- /// merchant_ids: Vec<MerchantId>+ /// merchant_ids: The merchant IDs to filter analytics data+ /// For platform use cases with connected merchants, this contains the platform merchant's ID.+ /// For standard merchants, this contains the merchant's own ID.merchant_ids: Vec<id_type::MerchantId>,+ /// processor_merchant_ids: Optional Vec of processor merchant IDs for platform use cases+ /// For Connected merchants, this contains the connected merchant's ID+ processor_merchant_ids: Option<Vec<id_type::MerchantId>>,},/// ProfileLevel: Authentication at the profile levelProfileLevel {/// org_id: OrganizationIdorg_id: id_type::OrganizationId,- /// merchant_id: MerchantId+ /// merchant_id: The merchant ID to filter analytics data+ /// For platform use cases with connected merchants, this contains the platform merchant's ID.+ /// For standard merchants, this contains the merchant's own ID.merchant_id: id_type::MerchantId,/// profile_ids: Vec<ProfileId>profile_ids: Vec<id_type::ProfileId>,+ /// processor_merchant_id: Optional processor merchant ID for platform use cases+ /// For Connected merchants, this is the connected merchant's ID+ processor_merchant_id: Option<id_type::MerchantId>,},}diff --git a/crates/hyperswitch_domain_models/src/platform.rs b/crates/hyperswitch_domain_models/src/platform.rsindex babe4b47d3..7428deec04 100644--- a/crates/hyperswitch_domain_models/src/platform.rs+++ b/crates/hyperswitch_domain_models/src/platform.rs@@ -1,3 +1,5 @@+use common_utils::types::authentication::AuthInfo;+pub use crate::{merchant_account::MerchantAccount, merchant_key_store::MerchantKeyStore};/// Provider = The business owner or the governing entity in the hierarchy.@@ -155,4 +157,69 @@ impl Platform {pub fn get_initiator(&self) -> Option<&Initiator> {self.initiator.as_ref()}++ /// Build MerchantLevel AuthInfo with platform use case support.+ /// For connected merchants, merchant_ids contains the platform's ID and+ /// processor_merchant_ids contains the connected merchant's ID.+ pub fn to_merchant_level_auth_info(&self) -> AuthInfo {+ let processor_account = self.get_processor().get_account();+ let provider_account = self.get_provider().get_account();++ let org_id = processor_account.get_org_id().clone();++ let (merchant_ids, processor_merchant_ids) = match processor_account.merchant_account_type {+ common_enums::MerchantAccountType::Connected => (+ vec![provider_account.get_id().clone()],+ Some(vec![processor_account.get_id().clone()]),+ ),+ common_enums::MerchantAccountType::Standard+ | common_enums::MerchantAccountType::Platform => {+ (vec![provider_account.get_id().clone()], None)+ }+ };++ AuthInfo::MerchantLevel {+ org_id,+ merchant_ids,+ processor_merchant_ids,+ }+ }++ /// Build ProfileLevel AuthInfo with platform use case support.+ /// For connected merchants, merchant_id contains the platform's ID and+ /// processor_merchant_id contains the connected merchant's ID.+ pub fn to_profile_level_auth_info(+ &self,+ profile_id: common_utils::id_type::ProfileId,+ ) -> AuthInfo {+ let processor_account = self.get_processor().get_account();+ let provider_account = self.get_provider().get_account();++ let org_id = processor_account.get_org_id().clone();++ let (merchant_id, processor_merchant_id) = match processor_account.merchant_account_type {+ common_enums::MerchantAccountType::Connected => (+ provider_account.get_id().clone(),+ Some(processor_account.get_id().clone()),+ ),+ common_enums::MerchantAccountType::Standard+ | common_enums::MerchantAccountType::Platform => {+ (provider_account.get_id().clone(), None)+ }+ };++ AuthInfo::ProfileLevel {+ org_id,+ merchant_id,+ profile_ids: vec![profile_id],+ processor_merchant_id,+ }+ }++ /// Build OrgLevel AuthInfo from the platform.+ pub fn to_org_level_auth_info(&self) -> AuthInfo {+ AuthInfo::OrgLevel {+ org_id: self.get_processor().get_account().get_org_id().clone(),+ }+ }}diff --git a/crates/router/src/analytics.rs b/crates/router/src/analytics.rsindex 59e2b94258..72b8a18945 100644--- a/crates/router/src/analytics.rs+++ b/crates/router/src/analytics.rs@@ -471,7 +471,7 @@ pub mod routes {).service(web::resource("/filters/payments")- .route(web::post().to(get_payment_intents_filters)),+ .route(web::post().to(get_merchant_payment_intents_filters)),).service(web::scope("/merchant")@@ -480,8 +480,9 @@ pub mod routes {.route(web::post().to(get_merchant_payment_intent_metrics)),).service(- web::resource("/filters/payments")- .route(web::post().to(get_payment_intents_filters)),+ web::resource("/filters/payments").route(+ web::post().to(get_merchant_payment_intents_filters),+ ),),).service(@@ -544,12 +545,7 @@ pub mod routes {&req,payload,|state, auth: AuthenticationData, req, _| async move {- let org_id = auth.platform.get_processor().get_account().get_org_id();- let merchant_id = auth.platform.get_processor().get_account().get_id();- let auth: AuthInfo = AuthInfo::MerchantLevel {- org_id: org_id.clone(),- merchant_ids: vec![merchant_id.clone()],- };+ let auth_info = auth.platform.to_merchant_level_auth_info();let validator_response = request_validator(AnalyticsRequest {payment_attempt: Some(req.clone()),@@ -559,7 +555,7 @@ pub mod routes {).await?;let ex_rates = validator_response;- analytics::payments::get_metrics(&state.pool, &ex_rates, &auth, req)+ analytics::payments::get_metrics(&state.pool, &ex_rates, &auth_info, req).await.map(ApplicationResponse::Json)},@@ -596,10 +592,7 @@ pub mod routes {&req,payload,|state, auth: AuthenticationData, req, _| async move {- let org_id = auth.platform.get_processor().get_account().get_org_id();- let auth: AuthInfo = AuthInfo::OrgLevel {- org_id: org_id.clone(),- };+ let auth_info = auth.platform.to_org_level_auth_info();let validator_response = request_validator(AnalyticsRequest {@@ -610,7 +603,7 @@ pub mod routes {).await?;let ex_rates = validator_response;- analytics::payments::get_metrics(&state.pool, &ex_rates, &auth, req)+ analytics::payments::get_metrics(&state.pool, &ex_rates, &auth_info, req).await.map(ApplicationResponse::Json)},@@ -654,19 +647,13 @@ pub mod routes {&req,payload,|state, auth: AuthenticationData, req, _| async move {- let org_id = auth.platform.get_processor().get_account().get_org_id();- let merchant_id = auth.platform.get_processor().get_account().get_id();let profile_id = auth.profile.ok_or(report!(UserErrors::JwtProfileIdMissing)).change_context(AnalyticsError::AccessForbiddenError)?.get_id().clone();- let auth: AuthInfo = AuthInfo::ProfileLevel {- org_id: org_id.clone(),- merchant_id: merchant_id.clone(),- profile_ids: vec![profile_id.clone()],- };+ let auth_info: AuthInfo = auth.platform.to_profile_level_auth_info(profile_id);let validator_response = request_validator(AnalyticsRequest {@@ -677,7 +664,7 @@ pub mod routes {).await?;let ex_rates = validator_response;- analytics::payments::get_metrics(&state.pool, &ex_rates, &auth, req)+ analytics::payments::get_metrics(&state.pool, &ex_rates, &auth_info, req).await.map(ApplicationResponse::Json)},@@ -713,12 +700,7 @@ pub mod routes {&req,payload,|state, auth: AuthenticationData, req, _| async move {- let org_id = auth.platform.get_processor().get_account().get_org_id();- let merchant_id = auth.platform.get_processor().get_account().get_id();- let auth: AuthInfo = AuthInfo::MerchantLevel {- org_id: org_id.clone(),- merchant_ids: vec![merchant_id.clone()],- };+ let auth_info = auth.platform.to_merchant_level_auth_info();let validator_response = request_validator(AnalyticsRequest {@@ -729,7 +711,7 @@ pub mod routes {).await?;let ex_rates = validator_response;- analytics::payment_intents::get_metrics(&state.pool, &ex_rates, &auth, req)+ analytics::payment_intents::get_metrics(&state.pool, &ex_rates, &auth_info, req).await.map(ApplicationResponse::Json)},@@ -766,10 +748,7 @@ pub mod routes {&req,payload,|state, auth: AuthenticationData, req, _| async move {- let org_id = auth.platform.get_processor().get_account().get_org_id();- let auth: AuthInfo = AuthInfo::OrgLevel {- org_id: org_id.clone(),- };+ let auth_info = auth.platform.to_org_level_auth_info();let validator_response = request_validator(AnalyticsRequest {@@ -780,7 +759,7 @@ pub mod routes {).await?;let ex_rates = validator_response;- analytics::payment_intents::get_metrics(&state.pool, &ex_rates, &auth, req)+ analytics::payment_intents::get_metrics(&state.pool, &ex_rates, &auth_info, req).await.map(ApplicationResponse::Json)},@@ -824,19 +803,13 @@ pub mod routes {&req,payload,|state, auth: AuthenticationData, req, _| async move {- let org_id = auth.platform.get_processor().get_account().get_org_id();- let merchant_id = auth.platform.get_processor().get_account().get_id();let profile_id = auth.profile.ok_or(report!(UserErrors::JwtProfileIdMissing)).change_context(AnalyticsError::AccessForbiddenError)?.get_id().clone();- let auth: AuthInfo = AuthInfo::ProfileLevel {- org_id: org_id.clone(),- merchant_id: merchant_id.clone(),- profile_ids: vec![profile_id.clone()],- };+ let auth_info = auth.platform.to_profile_level_auth_info(profile_id);let validator_response = request_validator(AnalyticsRequest {@@ -847,7 +820,7 @@ pub mod routes {).await?;let ex_rates = validator_response;- analytics::payment_intents::get_metrics(&state.pool, &ex_rates, &auth, req)+ analytics::payment_intents::get_metrics(&state.pool, &ex_rates, &auth_info, req).await.map(ApplicationResponse::Json)},@@ -883,12 +856,7 @@ pub mod routes {&req,payload,|state, auth: AuthenticationData, req, _| async move {- let org_id = auth.platform.get_processor().get_account().get_org_id();- let merchant_id = auth.platform.get_processor().get_account().get_id();- let auth: AuthInfo = AuthInfo::MerchantLevel {- org_id: org_id.clone(),- merchant_ids: vec![merchant_id.clone()],- };+ let auth_info = auth.platform.to_merchant_level_auth_info();let validator_response = request_validator(AnalyticsRequest {@@ -899,13 +867,13 @@ pub mod routes {).await?;let ex_rates = validator_response;- analytics::refunds::get_metrics(&state.pool, &ex_rates, &auth, req)+ analytics::refunds::get_metrics(&state.pool, &ex_rates, &auth_info, req).await.map(ApplicationResponse::Json)},&auth::JWTAuth {permission: Permission::MerchantAnalyticsRead,- allow_connected: false,+ allow_connected: true,allow_platform: false,},api_locking::LockAction::NotApplicable,@@ -936,10 +904,7 @@ pub mod routes {&req,payload,|state, auth: AuthenticationData, req, _| async move {- let org_id = auth.platform.get_processor().get_account().get_org_id();- let auth: AuthInfo = AuthInfo::OrgLevel {- org_id: org_id.clone(),- };+ let auth_info = auth.platform.to_org_level_auth_info();let validator_response = request_validator(AnalyticsRequest {@@ -950,7 +915,7 @@ pub mod routes {).await?;let ex_rates = validator_response;- analytics::refunds::get_metrics(&state.pool, &ex_rates, &auth, req)+ analytics::refunds::get_metrics(&state.pool, &ex_rates, &auth_info, req).await.map(ApplicationResponse::Json)},@@ -961,7 +926,7 @@ pub mod routes {},&auth::JWTAuth {permission: Permission::OrganizationAnalyticsRead,- allow_connected: false,+ allow_connected: true,allow_platform: false,},req.headers(),@@ -994,19 +959,13 @@ pub mod routes {&req,payload,|state, auth: AuthenticationData, req, _| async move {- let org_id = auth.platform.get_processor().get_account().get_org_id();- let merchant_id = auth.platform.get_processor().get_account().get_id();let profile_id = auth.profile.ok_or(report!(UserErrors::JwtProfileIdMissing)).change_context(AnalyticsError::AccessForbiddenError)?.get_id().clone();- let auth: AuthInfo = AuthInfo::ProfileLevel {- org_id: org_id.clone(),- merchant_id: merchant_id.clone(),- profile_ids: vec![profile_id.clone()],- };+ let auth_info = auth.platform.to_profile_level_auth_info(profile_id);let validator_response = request_validator(AnalyticsRequest {@@ -1017,13 +976,13 @@ pub mod routes {).await?;let ex_rates = validator_response;- analytics::refunds::get_metrics(&state.pool, &ex_rates, &auth, req)+ analytics::refunds::get_metrics(&state.pool, &ex_rates, &auth_info, req).await.map(ApplicationResponse::Json)},&auth::JWTAuth {permission: Permission::ProfileAnalyticsRead,- allow_connected: false,+ allow_connected: true,allow_platform: false,},api_locking::LockAction::NotApplicable,@@ -1177,14 +1136,9 @@ pub mod routes {&req,payload,|state, auth: AuthenticationData, req, _| async move {- let org_id = auth.platform.get_processor().get_account().get_org_id();- let merchant_id = auth.platform.get_processor().get_account().get_id();- let auth: AuthInfo = AuthInfo::MerchantLevel {- org_id: org_id.clone(),- merchant_ids: vec![merchant_id.clone()],- };+ let auth_info = auth.platform.to_merchant_level_auth_info();- analytics::auth_events::get_metrics(&state.pool, &auth, req)+ analytics::auth_events::get_metrics(&state.pool, &auth_info, req).await.map(ApplicationResponse::Json)},@@ -1221,20 +1175,14 @@ pub mod routes {&req,payload,|state, auth: AuthenticationData, req, _| async move {- let org_id = auth.platform.get_processor().get_account().get_org_id();- let merchant_id = auth.platform.get_processor().get_account().get_id();let profile_id = auth.profile.ok_or(report!(UserErrors::JwtProfileIdMissing)).change_context(AnalyticsError::AccessForbiddenError)?.get_id().clone();- let auth: AuthInfo = AuthInfo::ProfileLevel {- org_id: org_id.clone(),- merchant_id: merchant_id.clone(),- profile_ids: vec![profile_id.clone()],- };- analytics::auth_events::get_metrics(&state.pool, &auth, req)+ let auth_info = auth.platform.to_profile_level_auth_info(profile_id);+ analytics::auth_events::get_metrics(&state.pool, &auth_info, req).await.map(ApplicationResponse::Json)},@@ -1271,11 +1219,8 @@ pub mod routes {&req,payload,|state, auth: AuthenticationData, req, _| async move {- let org_id = auth.platform.get_processor().get_account().get_org_id();- let auth: AuthInfo = AuthInfo::OrgLevel {- org_id: org_id.clone(),- };- analytics::auth_events::get_metrics(&state.pool, &auth, req)+ let auth_info = auth.platform.to_org_level_auth_info();+ analytics::auth_events::get_metrics(&state.pool, &auth_info, req).await.map(ApplicationResponse::Json)},@@ -1308,13 +1253,8 @@ pub mod routes {&req,json_payload.into_inner(),|state, auth: AuthenticationData, req, _| async move {- let org_id = auth.platform.get_processor().get_account().get_org_id();- let merchant_id = auth.platform.get_processor().get_account().get_id();- let auth: AuthInfo = AuthInfo::MerchantLevel {- org_id: org_id.clone(),- merchant_ids: vec![merchant_id.clone()],- };- analytics::payments::get_filters(&state.pool, req, &auth)+ let auth_info = auth.platform.to_merchant_level_auth_info();+ analytics::payments::get_filters(&state.pool, req, &auth_info).await.map(ApplicationResponse::Json)},@@ -1340,14 +1280,8 @@ pub mod routes {&req,json_payload.into_inner(),|state, auth: AuthenticationData, req, _| async move {- let org_id = auth.platform.get_processor().get_account().get_org_id();- let merchant_id = auth.platform.get_processor().get_account().get_id();-- let auth: AuthInfo = AuthInfo::MerchantLevel {- org_id: org_id.clone(),- merchant_ids: vec![merchant_id.clone()],- };- analytics::auth_events::get_filters(&state.pool, req, &auth)+ let auth_info = auth.platform.to_merchant_level_auth_info();+ analytics::auth_events::get_filters(&state.pool, req, &auth_info).await.map(ApplicationResponse::Json)},@@ -1374,12 +1308,8 @@ pub mod routes {&req,json_payload.into_inner(),|state, auth: AuthenticationData, req, _| async move {- let org_id = auth.platform.get_processor().get_account().get_org_id();- let auth: AuthInfo = AuthInfo::OrgLevel {- org_id: org_id.clone(),- };-- analytics::auth_events::get_filters(&state.pool, req, &auth)+ let auth_info = auth.platform.to_org_level_auth_info();+ analytics::auth_events::get_filters(&state.pool, req, &auth_info).await.map(ApplicationResponse::Json)},@@ -1413,20 +1343,14 @@ pub mod routes {&req,json_payload.into_inner(),|state, auth: AuthenticationData, req, _| async move {- let org_id = auth.platform.get_processor().get_account().get_org_id();- let merchant_id = auth.platform.get_processor().get_account().get_id();let profile_id = auth.profile.ok_or(report!(UserErrors::JwtProfileIdMissing)).change_context(AnalyticsError::AccessForbiddenError)?.get_id().clone();- let auth: AuthInfo = AuthInfo::ProfileLevel {- org_id: org_id.clone(),- merchant_id: merchant_id.clone(),- profile_ids: vec![profile_id.clone()],- };- analytics::auth_events::get_filters(&state.pool, req, &auth)+ let auth_info = auth.platform.to_profile_level_auth_info(profile_id);+ analytics::auth_events::get_filters(&state.pool, req, &auth_info).await.map(ApplicationResponse::Json)},@@ -1453,11 +1377,8 @@ pub mod routes {&req,json_payload.into_inner(),|state, auth: AuthenticationData, req, _| async move {- let org_id = auth.platform.get_processor().get_account().get_org_id();- let auth: AuthInfo = AuthInfo::OrgLevel {- org_id: org_id.clone(),- };- analytics::payments::get_filters(&state.pool, req, &auth)+ let auth_info = auth.platform.to_org_level_auth_info();+ analytics::payments::get_filters(&state.pool, req, &auth_info).await.map(ApplicationResponse::Json)},@@ -1491,20 +1412,14 @@ pub mod routes {&req,json_payload.into_inner(),|state, auth: AuthenticationData, req, _| async move {- let org_id = auth.platform.get_processor().get_account().get_org_id();- let merchant_id = auth.platform.get_processor().get_account().get_id();let profile_id = auth.profile.ok_or(report!(UserErrors::JwtProfileIdMissing)).change_context(AnalyticsError::AccessForbiddenError)?.get_id().clone();- let auth: AuthInfo = AuthInfo::ProfileLevel {- org_id: org_id.clone(),- merchant_id: merchant_id.clone(),- profile_ids: vec![profile_id.clone()],- };- analytics::payments::get_filters(&state.pool, req, &auth)+ let auth_info = auth.platform.to_profile_level_auth_info(profile_id);+ analytics::payments::get_filters(&state.pool, req, &auth_info).await.map(ApplicationResponse::Json)},@@ -1519,7 +1434,7 @@ pub mod routes {}#[cfg(feature = "v1")]- pub async fn get_payment_intents_filters(+ pub async fn get_merchant_payment_intents_filters(state: web::Data<AppState>,req: actix_web::HttpRequest,json_payload: web::Json<GetPaymentIntentFiltersRequest>,@@ -1531,13 +1446,10 @@ pub mod routes {&req,json_payload.into_inner(),|state, auth: AuthenticationData, req, _| async move {- analytics::payment_intents::get_filters(- &state.pool,- req,- auth.platform.get_processor().get_account().get_id(),- )- .await- .map(ApplicationResponse::Json)+ let auth_info = auth.platform.to_merchant_level_auth_info();+ analytics::payment_intents::get_filters(&state.pool, req, &auth_info)+ .await+ .map(ApplicationResponse::Json)},auth::auth_type(&auth::PlatformOrgAdminAuth {@@ -1568,19 +1480,14 @@ pub mod routes {&req,json_payload.into_inner(),|state, auth: AuthenticationData, req: GetRefundFilterRequest, _| async move {- let org_id = auth.platform.get_processor().get_account().get_org_id();- let merchant_id = auth.platform.get_processor().get_account().get_id();- let auth: AuthInfo = AuthInfo::MerchantLevel {- org_id: org_id.clone(),- merchant_ids: vec![merchant_id.clone()],- };- analytics::refunds::get_filters(&state.pool, req, &auth)+ let auth_info = auth.platform.to_merchant_level_auth_info();+ analytics::refunds::get_filters(&state.pool, req, &auth_info).await.map(ApplicationResponse::Json)},&auth::JWTAuth {permission: Permission::MerchantAnalyticsRead,- allow_connected: false,+ allow_connected: true,allow_platform: false,},api_locking::LockAction::NotApplicable,@@ -1601,11 +1508,8 @@ pub mod routes {&req,json_payload.into_inner(),|state, auth: AuthenticationData, req: GetRefundFilterRequest, _| async move {- let org_id = auth.platform.get_processor().get_account().get_org_id();- let auth: AuthInfo = AuthInfo::OrgLevel {- org_id: org_id.clone(),- };- analytics::refunds::get_filters(&state.pool, req, &auth)+ let auth_info = auth.platform.to_org_level_auth_info();+ analytics::refunds::get_filters(&state.pool, req, &auth_info).await.map(ApplicationResponse::Json)},@@ -1616,7 +1520,7 @@ pub mod routes {},&auth::JWTAuth {permission: Permission::OrganizationAnalyticsRead,- allow_connected: false,+ allow_connected: true,allow_platform: false,},req.headers(),@@ -1639,26 +1543,20 @@ pub mod routes {&req,json_payload.into_inner(),|state, auth: AuthenticationData, req: GetRefundFilterRequest, _| async move {- let org_id = auth.platform.get_processor().get_account().get_org_id();- let merchant_id = auth.platform.get_processor().get_account().get_id();let profile_id = auth.profile.ok_or(report!(UserErrors::JwtProfileIdMissing)).change_context(AnalyticsError::AccessForbiddenError)?.get_id().clone();- let auth: AuthInfo = AuthInfo::ProfileLevel {- org_id: org_id.clone(),- merchant_id: merchant_id.clone(),- profile_ids: vec![profile_id.clone()],- };- analytics::refunds::get_filters(&state.pool, req, &auth)+ let auth_info = auth.platform.to_profile_level_auth_info(profile_id);+ analytics::refunds::get_filters(&state.pool, req, &auth_info).await.map(ApplicationResponse::Json)},&auth::JWTAuth {permission: Permission::ProfileAnalyticsRead,- allow_connected: false,+ allow_connected: true,allow_platform: false,},api_locking::LockAction::NotApplicable,@@ -1915,15 +1813,10 @@ pub mod routes {..payload};- let org_id = auth.platform.get_processor().get_account().get_org_id();- let merchant_id = auth.platform.get_processor().get_account().get_id();let lambda_req = GenerateReportRequest {request: payload,- merchant_id: Some(merchant_id.clone()),- auth: AuthInfo::MerchantLevel {- org_id: org_id.clone(),- merchant_ids: vec![merchant_id.clone()],- },+ merchant_id: Some(auth.platform.get_processor().get_account().get_id().clone()),+ auth: auth.platform.to_merchant_level_auth_info(),email: user_email,};@@ -2008,13 +1901,10 @@ pub mod routes {..payload};- let org_id = auth.platform.get_processor().get_account().get_org_id();let lambda_req = GenerateReportRequest {request: payload,merchant_id: None,- auth: AuthInfo::OrgLevel {- org_id: org_id.clone(),- },+ auth: auth.platform.to_org_level_auth_info(),email: user_email,};@@ -2099,8 +1989,6 @@ pub mod routes {..payload};- let org_id = auth.platform.get_processor().get_account().get_org_id();- let merchant_id = auth.platform.get_processor().get_account().get_id();let profile_id = auth.profile.ok_or(report!(UserErrors::JwtProfileIdMissing))@@ -2109,12 +1997,8 @@ pub mod routes {.clone();let lambda_req = GenerateReportRequest {request: payload,- merchant_id: Some(merchant_id.clone()),- auth: AuthInfo::ProfileLevel {- org_id: org_id.clone(),- merchant_id: merchant_id.clone(),- profile_ids: vec![profile_id.clone()],- },+ merchant_id: Some(auth.platform.get_processor().get_account().get_id().clone()),+ auth: auth.platform.to_profile_level_auth_info(profile_id),email: user_email,};@@ -2198,15 +2082,10 @@ pub mod routes {..payload};- let org_id = auth.platform.get_processor().get_account().get_org_id();- let merchant_id = auth.platform.get_processor().get_account().get_id();let lambda_req = GenerateReportRequest {request: payload,- merchant_id: Some(merchant_id.clone()),- auth: AuthInfo::MerchantLevel {- org_id: org_id.clone(),- merchant_ids: vec![merchant_id.clone()],- },+ merchant_id: Some(auth.platform.get_processor().get_account().get_id().clone()),+ auth: auth.platform.to_merchant_level_auth_info(),email: user_email,};@@ -2290,13 +2169,10 @@ pub mod routes {..payload};- let org_id = auth.platform.get_processor().get_account().get_org_id();let lambda_req = GenerateReportRequest {request: payload,merchant_id: None,- auth: AuthInfo::OrgLevel {- org_id: org_id.clone(),- },+ auth: auth.platform.to_org_level_auth_info(),email: user_email,};@@ -2381,8 +2257,6 @@ pub mod routes {..payload};- let org_id = auth.platform.get_processor().get_account().get_org_id();- let merchant_id = auth.platform.get_processor().get_account().get_id();let profile_id = auth.profile.ok_or(report!(UserErrors::JwtProfileIdMissing))@@ -2391,12 +2265,8 @@ pub mod routes {.clone();let lambda_req = GenerateReportRequest {request: payload,- merchant_id: Some(merchant_id.clone()),- auth: AuthInfo::ProfileLevel {- org_id: org_id.clone(),- merchant_id: merchant_id.clone(),- profile_ids: vec![profile_id.clone()],- },+ merchant_id: Some(auth.platform.get_processor().get_account().get_id().clone()),+ auth: auth.platform.to_profile_level_auth_info(profile_id),email: user_email,};@@ -2481,15 +2351,10 @@ pub mod routes {..payload};- let org_id = auth.platform.get_processor().get_account().get_org_id();- let merchant_id = auth.platform.get_processor().get_account().get_id();let lambda_req = GenerateReportRequest {request: payload,- merchant_id: Some(merchant_id.clone()),- auth: AuthInfo::MerchantLevel {- org_id: org_id.clone(),- merchant_ids: vec![merchant_id.clone()],- },+ merchant_id: Some(auth.platform.get_processor().get_account().get_id().clone()),+ auth: auth.platform.to_merchant_level_auth_info(),email: user_email,};@@ -2574,13 +2439,10 @@ pub mod routes {..payload};- let org_id = auth.platform.get_processor().get_account().get_org_id();let lambda_req = GenerateReportRequest {request: payload,merchant_id: None,- auth: AuthInfo::OrgLevel {- org_id: org_id.clone(),- },+ auth: auth.platform.to_org_level_auth_info(),email: user_email,};@@ -2664,8 +2526,6 @@ pub mod routes {emails: optional_emails,..payload};- let org_id = auth.platform.get_processor().get_account().get_org_id();- let merchant_id = auth.platform.get_processor().get_account().get_id();let profile_id = auth.profile.ok_or(report!(UserErrors::JwtProfileIdMissing))@@ -2674,12 +2534,8 @@ pub mod routes {.clone();let lambda_req = GenerateReportRequest {request: payload,- merchant_id: Some(merchant_id.clone()),- auth: AuthInfo::ProfileLevel {- org_id: org_id.clone(),- merchant_id: merchant_id.clone(),- profile_ids: vec![profile_id.clone()],- },+ merchant_id: Some(auth.platform.get_processor().get_account().get_id().clone()),+ auth: auth.platform.to_profile_level_auth_info(profile_id),email: user_email,};@@ -2763,15 +2619,10 @@ pub mod routes {..payload};- let org_id = auth.platform.get_processor().get_account().get_org_id();- let merchant_id = auth.platform.get_processor().get_account().get_id();let lambda_req = GenerateReportRequest {request: payload,- merchant_id: Some(merchant_id.clone()),- auth: AuthInfo::MerchantLevel {- org_id: org_id.clone(),- merchant_ids: vec![merchant_id.clone()],- },+ merchant_id: Some(auth.platform.get_processor().get_account().get_id().clone()),+ auth: auth.platform.to_merchant_level_auth_info(),email: user_email,};@@ -2855,13 +2706,10 @@ pub mod routes {..payload};- let org_id = auth.platform.get_processor().get_account().get_org_id();let lambda_req = GenerateReportRequest {request: payload,merchant_id: None,- auth: AuthInfo::OrgLevel {- org_id: org_id.clone(),- },+ auth: auth.platform.to_org_level_auth_info(),email: user_email,};@@ -2944,8 +2792,6 @@ pub mod routes {emails: optional_emails,..payload};- let org_id = auth.platform.get_processor().get_account().get_org_id();- let merchant_id = auth.platform.get_processor().get_account().get_id();let profile_id = {#[cfg(feature = "v1")]{@@ -2962,12 +2808,8 @@ pub mod routes {};let lambda_req = GenerateReportRequest {request: payload,- merchant_id: Some(merchant_id.clone()),- auth: AuthInfo::ProfileLevel {- org_id: org_id.clone(),- merchant_id: merchant_id.clone(),- profile_ids: vec![profile_id.clone()],- },+ merchant_id: Some(auth.platform.get_processor().get_account().get_id().clone()),+ auth: auth.platform.to_profile_level_auth_info(profile_id),email: user_email,};@@ -3052,15 +2894,10 @@ pub mod routes {..payload};- let org_id = auth.platform.get_processor().get_account().get_org_id();- let merchant_id = auth.platform.get_processor().get_account().get_id();let lambda_req = GenerateReportRequest {request: payload,- merchant_id: Some(merchant_id.clone()),- auth: AuthInfo::MerchantLevel {- org_id: org_id.clone(),- merchant_ids: vec![merchant_id.clone()],- },+ merchant_id: Some(auth.platform.get_processor().get_account().get_id().clone()),+ auth: auth.platform.to_merchant_level_auth_info(),email: user_email,};@@ -3145,13 +2982,10 @@ pub mod routes {..payload};- let org_id = auth.platform.get_processor().get_account().get_org_id();let lambda_req = GenerateReportRequest {request: payload,merchant_id: None,- auth: AuthInfo::OrgLevel {- org_id: org_id.clone(),- },+ auth: auth.platform.to_org_level_auth_info(),email: user_email,};@@ -3235,8 +3069,6 @@ pub mod routes {emails: optional_emails,..payload};- let org_id = auth.platform.get_processor().get_account().get_org_id();- let merchant_id = auth.platform.get_processor().get_account().get_id();let profile_id = auth.profile.ok_or(report!(UserErrors::JwtProfileIdMissing))@@ -3245,12 +3077,8 @@ pub mod routes {.clone();let lambda_req = GenerateReportRequest {request: payload,- merchant_id: Some(merchant_id.clone()),- auth: AuthInfo::ProfileLevel {- org_id: org_id.clone(),- merchant_id: merchant_id.clone(),- profile_ids: vec![profile_id.clone()],- },+ merchant_id: Some(auth.platform.get_processor().get_account().get_id().clone()),+ auth: auth.platform.to_profile_level_auth_info(profile_id),email: user_email,};@@ -3460,13 +3288,7 @@ pub mod routes {let req_merchant_id = auth.platform.get_processor().get_account().get_id().clone();common_utils::metrics::utils::record_operation_time(Box::pin(async move {- let merchant_id = auth.platform.get_processor().get_account().get_id();- let org_id = auth.platform.get_processor().get_account().get_org_id();-- let auth_info = vec![AuthInfo::MerchantLevel {- org_id: org_id.clone(),- merchant_ids: vec![merchant_id.clone()],- }];+ let auth_info = vec![auth.platform.to_merchant_level_auth_info()];let filters: SearchFilters = (&constraints).into();@@ -3532,9 +3354,6 @@ pub mod routes {let req_merchant_id = auth.platform.get_processor().get_account().get_id().clone();common_utils::metrics::utils::record_operation_time(Box::pin(async move {- let merchant_id = auth.platform.get_processor().get_account().get_id();- let org_id = auth.platform.get_processor().get_account().get_org_id();-let profile_id = auth.profile.ok_or(report!(UserErrors::JwtProfileIdMissing))@@ -3542,11 +3361,7 @@ pub mod routes {.get_id().clone();- let auth_info = vec![AuthInfo::ProfileLevel {- org_id: org_id.clone(),- merchant_id: merchant_id.clone(),- profile_ids: vec![profile_id.clone()],- }];+ let auth_info = vec![auth.platform.to_profile_level_auth_info(profile_id)];let filters: SearchFilters = (&constraints).into();@@ -3707,10 +3522,12 @@ pub mod routes {org_id: user_role.org_id.clone()?,merchant_id: user_role.merchant_id.clone()?,profile_ids: vec![user_role.profile_id.clone()?],+ processor_merchant_id: None,}),EntityType::Merchant => Some(AuthInfo::MerchantLevel {org_id: user_role.org_id.clone()?,merchant_ids: vec![user_role.merchant_id.clone()?],+ processor_merchant_ids: None,}),EntityType::Organization => Some(AuthInfo::OrgLevel {org_id: user_role.org_id.clone()?,@@ -3861,10 +3678,12 @@ pub mod routes {org_id: user_role.org_id.clone()?,merchant_id: user_role.merchant_id.clone()?,profile_ids: vec![user_role.profile_id.clone()?],+ processor_merchant_id: None,}),EntityType::Merchant => Some(AuthInfo::MerchantLevel {org_id: user_role.org_id.clone()?,merchant_ids: vec![user_role.merchant_id.clone()?],+ processor_merchant_ids: None,}),EntityType::Organization => Some(AuthInfo::OrgLevel {org_id: user_role.org_id.clone()?,@@ -3908,13 +3727,8 @@ pub mod routes {&req,json_payload.into_inner(),|state, auth: AuthenticationData, req, _| async move {- let org_id = auth.platform.get_processor().get_account().get_org_id();- let merchant_id = auth.platform.get_processor().get_account().get_id();- let auth: AuthInfo = AuthInfo::MerchantLevel {- org_id: org_id.clone(),- merchant_ids: vec![merchant_id.clone()],- };- analytics::disputes::get_filters(&state.pool, req, &auth)+ let auth_info = auth.platform.to_merchant_level_auth_info();+ analytics::disputes::get_filters(&state.pool, req, &auth_info).await.map(ApplicationResponse::Json)},@@ -3941,20 +3755,14 @@ pub mod routes {&req,json_payload.into_inner(),|state, auth: AuthenticationData, req, _| async move {- let org_id = auth.platform.get_processor().get_account().get_org_id();- let merchant_id = auth.platform.get_processor().get_account().get_id();let profile_id = auth.profile.ok_or(report!(UserErrors::JwtProfileIdMissing)).change_context(AnalyticsError::AccessForbiddenError)?.get_id().clone();- let auth: AuthInfo = AuthInfo::ProfileLevel {- org_id: org_id.clone(),- merchant_id: merchant_id.clone(),- profile_ids: vec![profile_id.clone()],- };- analytics::disputes::get_filters(&state.pool, req, &auth)+ let auth_info = auth.platform.to_profile_level_auth_info(profile_id);+ analytics::disputes::get_filters(&state.pool, req, &auth_info).await.map(ApplicationResponse::Json)},@@ -3981,11 +3789,8 @@ pub mod routes {&req,json_payload.into_inner(),|state, auth: AuthenticationData, req, _| async move {- let org_id = auth.platform.get_processor().get_account().get_org_id();- let auth: AuthInfo = AuthInfo::OrgLevel {- org_id: org_id.clone(),- };- analytics::disputes::get_filters(&state.pool, req, &auth)+ let auth_info = auth.platform.to_org_level_auth_info();+ analytics::disputes::get_filters(&state.pool, req, &auth_info).await.map(ApplicationResponse::Json)},@@ -4028,13 +3833,8 @@ pub mod routes {&req,payload,|state, auth: AuthenticationData, req, _| async move {- let org_id = auth.platform.get_processor().get_account().get_org_id();- let merchant_id = auth.platform.get_processor().get_account().get_id();- let auth: AuthInfo = AuthInfo::MerchantLevel {- org_id: org_id.clone(),- merchant_ids: vec![merchant_id.clone()],- };- analytics::disputes::get_metrics(&state.pool, &auth, req)+ let auth_info = auth.platform.to_merchant_level_auth_info();+ analytics::disputes::get_metrics(&state.pool, &auth_info, req).await.map(ApplicationResponse::Json)},@@ -4071,20 +3871,14 @@ pub mod routes {&req,payload,|state, auth: AuthenticationData, req, _| async move {- let org_id = auth.platform.get_processor().get_account().get_org_id();- let merchant_id = auth.platform.get_processor().get_account().get_id();let profile_id = auth.profile.ok_or(report!(UserErrors::JwtProfileIdMissing)).change_context(AnalyticsError::AccessForbiddenError)?.get_id().clone();- let auth: AuthInfo = AuthInfo::ProfileLevel {- org_id: org_id.clone(),- merchant_id: merchant_id.clone(),- profile_ids: vec![profile_id.clone()],- };- analytics::disputes::get_metrics(&state.pool, &auth, req)+ let auth_info = auth.platform.to_profile_level_auth_info(profile_id);+ analytics::disputes::get_metrics(&state.pool, &auth_info, req).await.map(ApplicationResponse::Json)},@@ -4121,11 +3915,8 @@ pub mod routes {&req,payload,|state, auth: AuthenticationData, req, _| async move {- let org_id = auth.platform.get_processor().get_account().get_org_id();- let auth: AuthInfo = AuthInfo::OrgLevel {- org_id: org_id.clone(),- };- analytics::disputes::get_metrics(&state.pool, &auth, req)+ let auth_info = auth.platform.to_org_level_auth_info();+ analytics::disputes::get_metrics(&state.pool, &auth_info, req).await.map(ApplicationResponse::Json)},@@ -4159,13 +3950,8 @@ pub mod routes {&req,payload,|state, auth: AuthenticationData, req, _| async move {- let org_id = auth.platform.get_processor().get_account().get_org_id();- let merchant_id = auth.platform.get_processor().get_account().get_id();- let auth: AuthInfo = AuthInfo::MerchantLevel {- org_id: org_id.clone(),- merchant_ids: vec![merchant_id.clone()],- };- analytics::payment_intents::get_sankey(&state.pool, &auth, req)+ let auth_info = auth.platform.to_merchant_level_auth_info();+ analytics::payment_intents::get_sankey(&state.pool, &auth_info, req).await.map(ApplicationResponse::Json)},@@ -4192,19 +3978,14 @@ pub mod routes {&req,payload,|state, auth: AuthenticationData, req, _| async move {- let org_id = auth.platform.get_processor().get_account().get_org_id();- let merchant_id = auth.platform.get_processor().get_account().get_id();- let auth: AuthInfo = AuthInfo::MerchantLevel {- org_id: org_id.clone(),- merchant_ids: vec![merchant_id.clone()],- };- analytics::auth_events::get_sankey(&state.pool, &auth, req)+ let auth_info = auth.platform.to_merchant_level_auth_info();+ analytics::auth_events::get_sankey(&state.pool, &auth_info, req).await.map(ApplicationResponse::Json)},&auth::JWTAuth {permission: Permission::MerchantAnalyticsRead,- allow_connected: false,+ allow_connected: true,allow_platform: false,},api_locking::LockAction::NotApplicable,@@ -4226,11 +4007,8 @@ pub mod routes {&req,payload,|state, auth: AuthenticationData, req, _| async move {- let org_id = auth.platform.get_processor().get_account().get_org_id();- let auth: AuthInfo = AuthInfo::OrgLevel {- org_id: org_id.clone(),- };- analytics::auth_events::get_sankey(&state.pool, &auth, req)+ let auth_info = auth.platform.to_org_level_auth_info();+ analytics::auth_events::get_sankey(&state.pool, &auth_info, req).await.map(ApplicationResponse::Json)},@@ -4241,7 +4019,7 @@ pub mod routes {},&auth::JWTAuth {permission: Permission::OrganizationAnalyticsRead,- allow_connected: false,+ allow_connected: true,allow_platform: false,},req.headers(),@@ -4265,26 +4043,20 @@ pub mod routes {&req,payload,|state, auth: AuthenticationData, req, _| async move {- let org_id = auth.platform.get_processor().get_account().get_org_id();- let merchant_id = auth.platform.get_processor().get_account().get_id();let profile_id = auth.profile.ok_or(report!(UserErrors::JwtProfileIdMissing)).change_context(AnalyticsError::AccessForbiddenError)?.get_id().clone();- let auth: AuthInfo = AuthInfo::ProfileLevel {- org_id: org_id.clone(),- merchant_id: merchant_id.clone(),- profile_ids: vec![profile_id.clone()],- };- analytics::auth_events::get_sankey(&state.pool, &auth, req)+ let auth_info = auth.platform.to_profile_level_auth_info(profile_id);+ analytics::auth_events::get_sankey(&state.pool, &auth_info, req).await.map(ApplicationResponse::Json)},&auth::JWTAuth {permission: Permission::ProfileAnalyticsRead,- allow_connected: false,+ allow_connected: true,allow_platform: false,},api_locking::LockAction::NotApplicable,@@ -4306,11 +4078,8 @@ pub mod routes {&req,payload,|state, auth: AuthenticationData, req, _| async move {- let org_id = auth.platform.get_processor().get_account().get_org_id();- let auth: AuthInfo = AuthInfo::OrgLevel {- org_id: org_id.clone(),- };- analytics::payment_intents::get_sankey(&state.pool, &auth, req)+ let auth_info = auth.platform.to_org_level_auth_info();+ analytics::payment_intents::get_sankey(&state.pool, &auth_info, req).await.map(ApplicationResponse::Json)},@@ -4345,20 +4114,14 @@ pub mod routes {&req,payload,|state: crate::routes::SessionState, auth: AuthenticationData, req, _| async move {- let org_id = auth.platform.get_processor().get_account().get_org_id();- let merchant_id = auth.platform.get_processor().get_account().get_id();let profile_id = auth.profile.ok_or(report!(UserErrors::JwtProfileIdMissing)).change_context(AnalyticsError::AccessForbiddenError)?.get_id().clone();- let auth: AuthInfo = AuthInfo::ProfileLevel {- org_id: org_id.clone(),- merchant_id: merchant_id.clone(),- profile_ids: vec![profile_id.clone()],- };- analytics::payment_intents::get_sankey(&state.pool, &auth, req)+ let auth_info = auth.platform.to_profile_level_auth_info(profile_id);+ analytics::payment_intents::get_sankey(&state.pool, &auth_info, req).await.map(ApplicationResponse::Json)},