mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-29 17:19:15 +08:00
feat(analytics): modified authentication queries and added generate report for authentications (#7483)
Co-authored-by: Sandeep Kumar <sandeep.kumar@Sandeep-Kumar-LVF93XQXPC.local>
This commit is contained in:
@ -165,6 +165,7 @@ pub async fn get_filters(
|
|||||||
.filter_map(|fil: AuthEventFilterRow| match dim {
|
.filter_map(|fil: AuthEventFilterRow| match dim {
|
||||||
AuthEventDimensions::AuthenticationStatus => fil.authentication_status.map(|i| i.as_ref().to_string()),
|
AuthEventDimensions::AuthenticationStatus => fil.authentication_status.map(|i| i.as_ref().to_string()),
|
||||||
AuthEventDimensions::TransactionStatus => fil.trans_status.map(|i| i.as_ref().to_string()),
|
AuthEventDimensions::TransactionStatus => fil.trans_status.map(|i| i.as_ref().to_string()),
|
||||||
|
AuthEventDimensions::AuthenticationType => fil.authentication_type.map(|i| i.as_ref().to_string()),
|
||||||
AuthEventDimensions::ErrorMessage => fil.error_message,
|
AuthEventDimensions::ErrorMessage => fil.error_message,
|
||||||
AuthEventDimensions::AuthenticationConnector => fil.authentication_connector.map(|i| i.as_ref().to_string()),
|
AuthEventDimensions::AuthenticationConnector => fil.authentication_connector.map(|i| i.as_ref().to_string()),
|
||||||
AuthEventDimensions::MessageVersion => fil.message_version,
|
AuthEventDimensions::MessageVersion => fil.message_version,
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
use api_models::analytics::{auth_events::AuthEventDimensions, Granularity, TimeRange};
|
use api_models::analytics::{auth_events::AuthEventDimensions, Granularity, TimeRange};
|
||||||
|
use common_enums::DecoupledAuthenticationType;
|
||||||
use common_utils::errors::ReportSwitchExt;
|
use common_utils::errors::ReportSwitchExt;
|
||||||
use diesel_models::enums::{AuthenticationConnectors, AuthenticationStatus, TransactionStatus};
|
use diesel_models::enums::{AuthenticationConnectors, AuthenticationStatus, TransactionStatus};
|
||||||
use error_stack::ResultExt;
|
use error_stack::ResultExt;
|
||||||
@ -54,6 +55,7 @@ where
|
|||||||
pub struct AuthEventFilterRow {
|
pub struct AuthEventFilterRow {
|
||||||
pub authentication_status: Option<DBEnumWrapper<AuthenticationStatus>>,
|
pub authentication_status: Option<DBEnumWrapper<AuthenticationStatus>>,
|
||||||
pub trans_status: Option<DBEnumWrapper<TransactionStatus>>,
|
pub trans_status: Option<DBEnumWrapper<TransactionStatus>>,
|
||||||
|
pub authentication_type: Option<DBEnumWrapper<DecoupledAuthenticationType>>,
|
||||||
pub error_message: Option<String>,
|
pub error_message: Option<String>,
|
||||||
pub authentication_connector: Option<DBEnumWrapper<AuthenticationConnectors>>,
|
pub authentication_connector: Option<DBEnumWrapper<AuthenticationConnectors>>,
|
||||||
pub message_version: Option<String>,
|
pub message_version: Option<String>,
|
||||||
|
|||||||
@ -41,6 +41,7 @@ pub struct AuthEventMetricRow {
|
|||||||
pub count: Option<i64>,
|
pub count: Option<i64>,
|
||||||
pub authentication_status: Option<DBEnumWrapper<storage_enums::AuthenticationStatus>>,
|
pub authentication_status: Option<DBEnumWrapper<storage_enums::AuthenticationStatus>>,
|
||||||
pub trans_status: Option<DBEnumWrapper<storage_enums::TransactionStatus>>,
|
pub trans_status: Option<DBEnumWrapper<storage_enums::TransactionStatus>>,
|
||||||
|
pub authentication_type: Option<DBEnumWrapper<storage_enums::DecoupledAuthenticationType>>,
|
||||||
pub error_message: Option<String>,
|
pub error_message: Option<String>,
|
||||||
pub authentication_connector: Option<DBEnumWrapper<storage_enums::AuthenticationConnectors>>,
|
pub authentication_connector: Option<DBEnumWrapper<storage_enums::AuthenticationConnectors>>,
|
||||||
pub message_version: Option<String>,
|
pub message_version: Option<String>,
|
||||||
|
|||||||
@ -70,7 +70,10 @@ where
|
|||||||
.switch()?;
|
.switch()?;
|
||||||
|
|
||||||
query_builder
|
query_builder
|
||||||
.add_negative_filter_clause("authentication_status", AuthenticationStatus::Pending)
|
.add_filter_in_range_clause(
|
||||||
|
"authentication_status",
|
||||||
|
&[AuthenticationStatus::Success, AuthenticationStatus::Failed],
|
||||||
|
)
|
||||||
.switch()?;
|
.switch()?;
|
||||||
filters.set_filter_clause(&mut query_builder).switch()?;
|
filters.set_filter_clause(&mut query_builder).switch()?;
|
||||||
time_range
|
time_range
|
||||||
@ -103,6 +106,7 @@ where
|
|||||||
AuthEventMetricsBucketIdentifier::new(
|
AuthEventMetricsBucketIdentifier::new(
|
||||||
i.authentication_status.as_ref().map(|i| i.0),
|
i.authentication_status.as_ref().map(|i| i.0),
|
||||||
i.trans_status.as_ref().map(|i| i.0.clone()),
|
i.trans_status.as_ref().map(|i| i.0.clone()),
|
||||||
|
i.authentication_type.as_ref().map(|i| i.0),
|
||||||
i.error_message.clone(),
|
i.error_message.clone(),
|
||||||
i.authentication_connector.as_ref().map(|i| i.0),
|
i.authentication_connector.as_ref().map(|i| i.0),
|
||||||
i.message_version.clone(),
|
i.message_version.clone(),
|
||||||
|
|||||||
@ -96,6 +96,7 @@ where
|
|||||||
AuthEventMetricsBucketIdentifier::new(
|
AuthEventMetricsBucketIdentifier::new(
|
||||||
i.authentication_status.as_ref().map(|i| i.0),
|
i.authentication_status.as_ref().map(|i| i.0),
|
||||||
i.trans_status.as_ref().map(|i| i.0.clone()),
|
i.trans_status.as_ref().map(|i| i.0.clone()),
|
||||||
|
i.authentication_type.as_ref().map(|i| i.0),
|
||||||
i.error_message.clone(),
|
i.error_message.clone(),
|
||||||
i.authentication_connector.as_ref().map(|i| i.0),
|
i.authentication_connector.as_ref().map(|i| i.0),
|
||||||
i.message_version.clone(),
|
i.message_version.clone(),
|
||||||
|
|||||||
@ -12,8 +12,8 @@ use time::PrimitiveDateTime;
|
|||||||
use super::AuthEventMetricRow;
|
use super::AuthEventMetricRow;
|
||||||
use crate::{
|
use crate::{
|
||||||
query::{
|
query::{
|
||||||
Aggregate, FilterTypes, GroupByClause, QueryBuilder, QueryFilter, SeriesBucket, ToSql,
|
Aggregate, FilterTypes, GroupByClause, Order, QueryBuilder, QueryFilter, SeriesBucket,
|
||||||
Window,
|
ToSql, Window,
|
||||||
},
|
},
|
||||||
types::{AnalyticsCollection, AnalyticsDataSource, MetricsError, MetricsResult},
|
types::{AnalyticsCollection, AnalyticsDataSource, MetricsError, MetricsResult},
|
||||||
};
|
};
|
||||||
@ -45,11 +45,9 @@ where
|
|||||||
for dim in dimensions.iter() {
|
for dim in dimensions.iter() {
|
||||||
query_builder.add_select_column(dim).switch()?;
|
query_builder.add_select_column(dim).switch()?;
|
||||||
}
|
}
|
||||||
|
|
||||||
query_builder
|
query_builder
|
||||||
.add_select_column(Aggregate::Count {
|
.add_select_column("sum(sign_flag) AS count")
|
||||||
field: None,
|
|
||||||
alias: Some("count"),
|
|
||||||
})
|
|
||||||
.switch()?;
|
.switch()?;
|
||||||
|
|
||||||
query_builder
|
query_builder
|
||||||
@ -94,6 +92,11 @@ where
|
|||||||
.switch()?;
|
.switch()?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
query_builder
|
||||||
|
.add_order_by_clause("count", Order::Descending)
|
||||||
|
.attach_printable("Error adding order by clause")
|
||||||
|
.switch()?;
|
||||||
|
|
||||||
if let Some(granularity) = granularity {
|
if let Some(granularity) = granularity {
|
||||||
granularity
|
granularity
|
||||||
.set_group_by_clause(&mut query_builder)
|
.set_group_by_clause(&mut query_builder)
|
||||||
@ -112,6 +115,7 @@ where
|
|||||||
AuthEventMetricsBucketIdentifier::new(
|
AuthEventMetricsBucketIdentifier::new(
|
||||||
i.authentication_status.as_ref().map(|i| i.0),
|
i.authentication_status.as_ref().map(|i| i.0),
|
||||||
i.trans_status.as_ref().map(|i| i.0.clone()),
|
i.trans_status.as_ref().map(|i| i.0.clone()),
|
||||||
|
i.authentication_type.as_ref().map(|i| i.0),
|
||||||
i.error_message.clone(),
|
i.error_message.clone(),
|
||||||
i.authentication_connector.as_ref().map(|i| i.0),
|
i.authentication_connector.as_ref().map(|i| i.0),
|
||||||
i.message_version.clone(),
|
i.message_version.clone(),
|
||||||
|
|||||||
@ -107,6 +107,7 @@ where
|
|||||||
AuthEventMetricsBucketIdentifier::new(
|
AuthEventMetricsBucketIdentifier::new(
|
||||||
i.authentication_status.as_ref().map(|i| i.0),
|
i.authentication_status.as_ref().map(|i| i.0),
|
||||||
i.trans_status.as_ref().map(|i| i.0.clone()),
|
i.trans_status.as_ref().map(|i| i.0.clone()),
|
||||||
|
i.authentication_type.as_ref().map(|i| i.0),
|
||||||
i.error_message.clone(),
|
i.error_message.clone(),
|
||||||
i.authentication_connector.as_ref().map(|i| i.0),
|
i.authentication_connector.as_ref().map(|i| i.0),
|
||||||
i.message_version.clone(),
|
i.message_version.clone(),
|
||||||
|
|||||||
@ -101,6 +101,7 @@ where
|
|||||||
AuthEventMetricsBucketIdentifier::new(
|
AuthEventMetricsBucketIdentifier::new(
|
||||||
i.authentication_status.as_ref().map(|i| i.0),
|
i.authentication_status.as_ref().map(|i| i.0),
|
||||||
i.trans_status.as_ref().map(|i| i.0.clone()),
|
i.trans_status.as_ref().map(|i| i.0.clone()),
|
||||||
|
i.authentication_type.as_ref().map(|i| i.0),
|
||||||
i.error_message.clone(),
|
i.error_message.clone(),
|
||||||
i.authentication_connector.as_ref().map(|i| i.0),
|
i.authentication_connector.as_ref().map(|i| i.0),
|
||||||
i.message_version.clone(),
|
i.message_version.clone(),
|
||||||
|
|||||||
@ -4,6 +4,7 @@ use api_models::analytics::{
|
|||||||
auth_events::{AuthEventDimensions, AuthEventFilters, AuthEventMetricsBucketIdentifier},
|
auth_events::{AuthEventDimensions, AuthEventFilters, AuthEventMetricsBucketIdentifier},
|
||||||
Granularity, TimeRange,
|
Granularity, TimeRange,
|
||||||
};
|
};
|
||||||
|
use common_enums::{AuthenticationStatus, DecoupledAuthenticationType};
|
||||||
use common_utils::errors::ReportSwitchExt;
|
use common_utils::errors::ReportSwitchExt;
|
||||||
use error_stack::ResultExt;
|
use error_stack::ResultExt;
|
||||||
use time::PrimitiveDateTime;
|
use time::PrimitiveDateTime;
|
||||||
@ -67,11 +68,17 @@ where
|
|||||||
.switch()?;
|
.switch()?;
|
||||||
|
|
||||||
query_builder
|
query_builder
|
||||||
.add_filter_clause("trans_status", "C".to_string())
|
.add_filter_clause(
|
||||||
|
"authentication_type",
|
||||||
|
DecoupledAuthenticationType::Challenge,
|
||||||
|
)
|
||||||
.switch()?;
|
.switch()?;
|
||||||
|
|
||||||
query_builder
|
query_builder
|
||||||
.add_negative_filter_clause("authentication_status", "pending")
|
.add_filter_in_range_clause(
|
||||||
|
"authentication_status",
|
||||||
|
&[AuthenticationStatus::Success, AuthenticationStatus::Failed],
|
||||||
|
)
|
||||||
.switch()?;
|
.switch()?;
|
||||||
filters.set_filter_clause(&mut query_builder).switch()?;
|
filters.set_filter_clause(&mut query_builder).switch()?;
|
||||||
time_range
|
time_range
|
||||||
@ -104,6 +111,7 @@ where
|
|||||||
AuthEventMetricsBucketIdentifier::new(
|
AuthEventMetricsBucketIdentifier::new(
|
||||||
i.authentication_status.as_ref().map(|i| i.0),
|
i.authentication_status.as_ref().map(|i| i.0),
|
||||||
i.trans_status.as_ref().map(|i| i.0.clone()),
|
i.trans_status.as_ref().map(|i| i.0.clone()),
|
||||||
|
i.authentication_type.as_ref().map(|i| i.0),
|
||||||
i.error_message.clone(),
|
i.error_message.clone(),
|
||||||
i.authentication_connector.as_ref().map(|i| i.0),
|
i.authentication_connector.as_ref().map(|i| i.0),
|
||||||
i.message_version.clone(),
|
i.message_version.clone(),
|
||||||
|
|||||||
@ -4,6 +4,7 @@ use api_models::analytics::{
|
|||||||
auth_events::{AuthEventDimensions, AuthEventFilters, AuthEventMetricsBucketIdentifier},
|
auth_events::{AuthEventDimensions, AuthEventFilters, AuthEventMetricsBucketIdentifier},
|
||||||
Granularity, TimeRange,
|
Granularity, TimeRange,
|
||||||
};
|
};
|
||||||
|
use common_enums::DecoupledAuthenticationType;
|
||||||
use common_utils::errors::ReportSwitchExt;
|
use common_utils::errors::ReportSwitchExt;
|
||||||
use error_stack::ResultExt;
|
use error_stack::ResultExt;
|
||||||
use time::PrimitiveDateTime;
|
use time::PrimitiveDateTime;
|
||||||
@ -67,7 +68,10 @@ where
|
|||||||
.switch()?;
|
.switch()?;
|
||||||
|
|
||||||
query_builder
|
query_builder
|
||||||
.add_filter_clause("trans_status", "C".to_string())
|
.add_filter_clause(
|
||||||
|
"authentication_type",
|
||||||
|
DecoupledAuthenticationType::Challenge,
|
||||||
|
)
|
||||||
.switch()?;
|
.switch()?;
|
||||||
filters.set_filter_clause(&mut query_builder).switch()?;
|
filters.set_filter_clause(&mut query_builder).switch()?;
|
||||||
time_range
|
time_range
|
||||||
@ -99,6 +103,7 @@ where
|
|||||||
AuthEventMetricsBucketIdentifier::new(
|
AuthEventMetricsBucketIdentifier::new(
|
||||||
i.authentication_status.as_ref().map(|i| i.0),
|
i.authentication_status.as_ref().map(|i| i.0),
|
||||||
i.trans_status.as_ref().map(|i| i.0.clone()),
|
i.trans_status.as_ref().map(|i| i.0.clone()),
|
||||||
|
i.authentication_type.as_ref().map(|i| i.0),
|
||||||
i.error_message.clone(),
|
i.error_message.clone(),
|
||||||
i.authentication_connector.as_ref().map(|i| i.0),
|
i.authentication_connector.as_ref().map(|i| i.0),
|
||||||
i.message_version.clone(),
|
i.message_version.clone(),
|
||||||
|
|||||||
@ -4,7 +4,7 @@ use api_models::analytics::{
|
|||||||
auth_events::{AuthEventDimensions, AuthEventFilters, AuthEventMetricsBucketIdentifier},
|
auth_events::{AuthEventDimensions, AuthEventFilters, AuthEventMetricsBucketIdentifier},
|
||||||
Granularity, TimeRange,
|
Granularity, TimeRange,
|
||||||
};
|
};
|
||||||
use common_enums::AuthenticationStatus;
|
use common_enums::{AuthenticationStatus, DecoupledAuthenticationType};
|
||||||
use common_utils::errors::ReportSwitchExt;
|
use common_utils::errors::ReportSwitchExt;
|
||||||
use error_stack::ResultExt;
|
use error_stack::ResultExt;
|
||||||
use time::PrimitiveDateTime;
|
use time::PrimitiveDateTime;
|
||||||
@ -72,7 +72,10 @@ where
|
|||||||
.switch()?;
|
.switch()?;
|
||||||
|
|
||||||
query_builder
|
query_builder
|
||||||
.add_filter_clause("trans_status", "C".to_string())
|
.add_filter_clause(
|
||||||
|
"authentication_type",
|
||||||
|
DecoupledAuthenticationType::Challenge,
|
||||||
|
)
|
||||||
.switch()?;
|
.switch()?;
|
||||||
filters.set_filter_clause(&mut query_builder).switch()?;
|
filters.set_filter_clause(&mut query_builder).switch()?;
|
||||||
time_range
|
time_range
|
||||||
@ -105,6 +108,7 @@ where
|
|||||||
AuthEventMetricsBucketIdentifier::new(
|
AuthEventMetricsBucketIdentifier::new(
|
||||||
i.authentication_status.as_ref().map(|i| i.0),
|
i.authentication_status.as_ref().map(|i| i.0),
|
||||||
i.trans_status.as_ref().map(|i| i.0.clone()),
|
i.trans_status.as_ref().map(|i| i.0.clone()),
|
||||||
|
i.authentication_type.as_ref().map(|i| i.0),
|
||||||
i.error_message.clone(),
|
i.error_message.clone(),
|
||||||
i.authentication_connector.as_ref().map(|i| i.0),
|
i.authentication_connector.as_ref().map(|i| i.0),
|
||||||
i.message_version.clone(),
|
i.message_version.clone(),
|
||||||
|
|||||||
@ -4,6 +4,7 @@ use api_models::analytics::{
|
|||||||
auth_events::{AuthEventDimensions, AuthEventFilters, AuthEventMetricsBucketIdentifier},
|
auth_events::{AuthEventDimensions, AuthEventFilters, AuthEventMetricsBucketIdentifier},
|
||||||
Granularity, TimeRange,
|
Granularity, TimeRange,
|
||||||
};
|
};
|
||||||
|
use common_enums::DecoupledAuthenticationType;
|
||||||
use common_utils::errors::ReportSwitchExt;
|
use common_utils::errors::ReportSwitchExt;
|
||||||
use error_stack::ResultExt;
|
use error_stack::ResultExt;
|
||||||
use time::PrimitiveDateTime;
|
use time::PrimitiveDateTime;
|
||||||
@ -67,7 +68,10 @@ where
|
|||||||
.switch()?;
|
.switch()?;
|
||||||
|
|
||||||
query_builder
|
query_builder
|
||||||
.add_filter_clause("trans_status", "Y".to_string())
|
.add_filter_clause(
|
||||||
|
"authentication_type",
|
||||||
|
DecoupledAuthenticationType::Frictionless,
|
||||||
|
)
|
||||||
.switch()?;
|
.switch()?;
|
||||||
filters.set_filter_clause(&mut query_builder).switch()?;
|
filters.set_filter_clause(&mut query_builder).switch()?;
|
||||||
time_range
|
time_range
|
||||||
@ -100,6 +104,7 @@ where
|
|||||||
AuthEventMetricsBucketIdentifier::new(
|
AuthEventMetricsBucketIdentifier::new(
|
||||||
i.authentication_status.as_ref().map(|i| i.0),
|
i.authentication_status.as_ref().map(|i| i.0),
|
||||||
i.trans_status.as_ref().map(|i| i.0.clone()),
|
i.trans_status.as_ref().map(|i| i.0.clone()),
|
||||||
|
i.authentication_type.as_ref().map(|i| i.0),
|
||||||
i.error_message.clone(),
|
i.error_message.clone(),
|
||||||
i.authentication_connector.as_ref().map(|i| i.0),
|
i.authentication_connector.as_ref().map(|i| i.0),
|
||||||
i.message_version.clone(),
|
i.message_version.clone(),
|
||||||
|
|||||||
@ -4,7 +4,7 @@ use api_models::analytics::{
|
|||||||
auth_events::{AuthEventDimensions, AuthEventFilters, AuthEventMetricsBucketIdentifier},
|
auth_events::{AuthEventDimensions, AuthEventFilters, AuthEventMetricsBucketIdentifier},
|
||||||
Granularity, TimeRange,
|
Granularity, TimeRange,
|
||||||
};
|
};
|
||||||
use common_enums::AuthenticationStatus;
|
use common_enums::{AuthenticationStatus, DecoupledAuthenticationType};
|
||||||
use common_utils::errors::ReportSwitchExt;
|
use common_utils::errors::ReportSwitchExt;
|
||||||
use error_stack::ResultExt;
|
use error_stack::ResultExt;
|
||||||
use time::PrimitiveDateTime;
|
use time::PrimitiveDateTime;
|
||||||
@ -68,7 +68,10 @@ where
|
|||||||
.switch()?;
|
.switch()?;
|
||||||
|
|
||||||
query_builder
|
query_builder
|
||||||
.add_filter_clause("trans_status", "Y".to_string())
|
.add_filter_clause(
|
||||||
|
"authentication_type",
|
||||||
|
DecoupledAuthenticationType::Frictionless,
|
||||||
|
)
|
||||||
.switch()?;
|
.switch()?;
|
||||||
|
|
||||||
query_builder
|
query_builder
|
||||||
@ -105,6 +108,7 @@ where
|
|||||||
AuthEventMetricsBucketIdentifier::new(
|
AuthEventMetricsBucketIdentifier::new(
|
||||||
i.authentication_status.as_ref().map(|i| i.0),
|
i.authentication_status.as_ref().map(|i| i.0),
|
||||||
i.trans_status.as_ref().map(|i| i.0.clone()),
|
i.trans_status.as_ref().map(|i| i.0.clone()),
|
||||||
|
i.authentication_type.as_ref().map(|i| i.0),
|
||||||
i.error_message.clone(),
|
i.error_message.clone(),
|
||||||
i.authentication_connector.as_ref().map(|i| i.0),
|
i.authentication_connector.as_ref().map(|i| i.0),
|
||||||
i.message_version.clone(),
|
i.message_version.clone(),
|
||||||
|
|||||||
@ -1123,6 +1123,7 @@ pub struct ReportConfig {
|
|||||||
pub payment_function: String,
|
pub payment_function: String,
|
||||||
pub refund_function: String,
|
pub refund_function: String,
|
||||||
pub dispute_function: String,
|
pub dispute_function: String,
|
||||||
|
pub authentication_function: String,
|
||||||
pub region: String,
|
pub region: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1151,6 +1152,7 @@ pub enum AnalyticsFlow {
|
|||||||
GeneratePaymentReport,
|
GeneratePaymentReport,
|
||||||
GenerateDisputeReport,
|
GenerateDisputeReport,
|
||||||
GenerateRefundReport,
|
GenerateRefundReport,
|
||||||
|
GenerateAuthenticationReport,
|
||||||
GetApiEventMetrics,
|
GetApiEventMetrics,
|
||||||
GetApiEventFilters,
|
GetApiEventFilters,
|
||||||
GetConnectorEvents,
|
GetConnectorEvents,
|
||||||
|
|||||||
@ -19,7 +19,9 @@ use api_models::{
|
|||||||
},
|
},
|
||||||
refunds::RefundStatus,
|
refunds::RefundStatus,
|
||||||
};
|
};
|
||||||
use common_enums::{AuthenticationConnectors, AuthenticationStatus, TransactionStatus};
|
use common_enums::{
|
||||||
|
AuthenticationConnectors, AuthenticationStatus, DecoupledAuthenticationType, TransactionStatus,
|
||||||
|
};
|
||||||
use common_utils::{
|
use common_utils::{
|
||||||
errors::{CustomResult, ParsingError},
|
errors::{CustomResult, ParsingError},
|
||||||
id_type::{MerchantId, OrganizationId, ProfileId},
|
id_type::{MerchantId, OrganizationId, ProfileId},
|
||||||
@ -506,6 +508,7 @@ impl_to_sql_for_to_string!(
|
|||||||
TransactionStatus,
|
TransactionStatus,
|
||||||
AuthenticationStatus,
|
AuthenticationStatus,
|
||||||
AuthenticationConnectors,
|
AuthenticationConnectors,
|
||||||
|
DecoupledAuthenticationType,
|
||||||
Flow,
|
Flow,
|
||||||
&String,
|
&String,
|
||||||
&bool,
|
&bool,
|
||||||
|
|||||||
@ -4,7 +4,9 @@ use api_models::{
|
|||||||
analytics::{frm::FrmTransactionType, refunds::RefundType},
|
analytics::{frm::FrmTransactionType, refunds::RefundType},
|
||||||
enums::{DisputeStage, DisputeStatus},
|
enums::{DisputeStage, DisputeStatus},
|
||||||
};
|
};
|
||||||
use common_enums::{AuthenticationConnectors, AuthenticationStatus, TransactionStatus};
|
use common_enums::{
|
||||||
|
AuthenticationConnectors, AuthenticationStatus, DecoupledAuthenticationType, TransactionStatus,
|
||||||
|
};
|
||||||
use common_utils::{
|
use common_utils::{
|
||||||
errors::{CustomResult, ParsingError},
|
errors::{CustomResult, ParsingError},
|
||||||
DbConnectionParams,
|
DbConnectionParams,
|
||||||
@ -100,6 +102,7 @@ db_type!(DisputeStatus);
|
|||||||
db_type!(AuthenticationStatus);
|
db_type!(AuthenticationStatus);
|
||||||
db_type!(TransactionStatus);
|
db_type!(TransactionStatus);
|
||||||
db_type!(AuthenticationConnectors);
|
db_type!(AuthenticationConnectors);
|
||||||
|
db_type!(DecoupledAuthenticationType);
|
||||||
|
|
||||||
impl<'q, Type> Encode<'q, Postgres> for DBEnumWrapper<Type>
|
impl<'q, Type> Encode<'q, Postgres> for DBEnumWrapper<Type>
|
||||||
where
|
where
|
||||||
@ -208,6 +211,11 @@ impl<'a> FromRow<'a, PgRow> for super::auth_events::metrics::AuthEventMetricRow
|
|||||||
ColumnNotFound(_) => Ok(Default::default()),
|
ColumnNotFound(_) => Ok(Default::default()),
|
||||||
e => Err(e),
|
e => Err(e),
|
||||||
})?;
|
})?;
|
||||||
|
let authentication_type: Option<DBEnumWrapper<DecoupledAuthenticationType>> =
|
||||||
|
row.try_get("authentication_type").or_else(|e| match e {
|
||||||
|
ColumnNotFound(_) => Ok(Default::default()),
|
||||||
|
e => Err(e),
|
||||||
|
})?;
|
||||||
let error_message: Option<String> = row.try_get("error_message").or_else(|e| match e {
|
let error_message: Option<String> = row.try_get("error_message").or_else(|e| match e {
|
||||||
ColumnNotFound(_) => Ok(Default::default()),
|
ColumnNotFound(_) => Ok(Default::default()),
|
||||||
e => Err(e),
|
e => Err(e),
|
||||||
@ -237,6 +245,7 @@ impl<'a> FromRow<'a, PgRow> for super::auth_events::metrics::AuthEventMetricRow
|
|||||||
Ok(Self {
|
Ok(Self {
|
||||||
authentication_status,
|
authentication_status,
|
||||||
trans_status,
|
trans_status,
|
||||||
|
authentication_type,
|
||||||
error_message,
|
error_message,
|
||||||
authentication_connector,
|
authentication_connector,
|
||||||
message_version,
|
message_version,
|
||||||
@ -259,6 +268,11 @@ impl<'a> FromRow<'a, PgRow> for super::auth_events::filters::AuthEventFilterRow
|
|||||||
ColumnNotFound(_) => Ok(Default::default()),
|
ColumnNotFound(_) => Ok(Default::default()),
|
||||||
e => Err(e),
|
e => Err(e),
|
||||||
})?;
|
})?;
|
||||||
|
let authentication_type: Option<DBEnumWrapper<DecoupledAuthenticationType>> =
|
||||||
|
row.try_get("authentication_type").or_else(|e| match e {
|
||||||
|
ColumnNotFound(_) => Ok(Default::default()),
|
||||||
|
e => Err(e),
|
||||||
|
})?;
|
||||||
let error_message: Option<String> = row.try_get("error_message").or_else(|e| match e {
|
let error_message: Option<String> = row.try_get("error_message").or_else(|e| match e {
|
||||||
ColumnNotFound(_) => Ok(Default::default()),
|
ColumnNotFound(_) => Ok(Default::default()),
|
||||||
e => Err(e),
|
e => Err(e),
|
||||||
@ -277,6 +291,7 @@ impl<'a> FromRow<'a, PgRow> for super::auth_events::filters::AuthEventFilterRow
|
|||||||
Ok(Self {
|
Ok(Self {
|
||||||
authentication_status,
|
authentication_status,
|
||||||
trans_status,
|
trans_status,
|
||||||
|
authentication_type,
|
||||||
error_message,
|
error_message,
|
||||||
authentication_connector,
|
authentication_connector,
|
||||||
message_version,
|
message_version,
|
||||||
|
|||||||
@ -3,7 +3,9 @@ use std::{
|
|||||||
hash::{Hash, Hasher},
|
hash::{Hash, Hasher},
|
||||||
};
|
};
|
||||||
|
|
||||||
use common_enums::{AuthenticationConnectors, AuthenticationStatus, TransactionStatus};
|
use common_enums::{
|
||||||
|
AuthenticationConnectors, AuthenticationStatus, DecoupledAuthenticationType, TransactionStatus,
|
||||||
|
};
|
||||||
|
|
||||||
use super::{NameDescription, TimeRange};
|
use super::{NameDescription, TimeRange};
|
||||||
|
|
||||||
@ -14,6 +16,8 @@ pub struct AuthEventFilters {
|
|||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub trans_status: Vec<TransactionStatus>,
|
pub trans_status: Vec<TransactionStatus>,
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
|
pub authentication_type: Vec<DecoupledAuthenticationType>,
|
||||||
|
#[serde(default)]
|
||||||
pub error_message: Vec<String>,
|
pub error_message: Vec<String>,
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub authentication_connector: Vec<AuthenticationConnectors>,
|
pub authentication_connector: Vec<AuthenticationConnectors>,
|
||||||
@ -42,6 +46,7 @@ pub enum AuthEventDimensions {
|
|||||||
#[strum(serialize = "trans_status")]
|
#[strum(serialize = "trans_status")]
|
||||||
#[serde(rename = "trans_status")]
|
#[serde(rename = "trans_status")]
|
||||||
TransactionStatus,
|
TransactionStatus,
|
||||||
|
AuthenticationType,
|
||||||
ErrorMessage,
|
ErrorMessage,
|
||||||
AuthenticationConnector,
|
AuthenticationConnector,
|
||||||
MessageVersion,
|
MessageVersion,
|
||||||
@ -101,6 +106,7 @@ pub mod metric_behaviour {
|
|||||||
pub struct ChallengeAttemptCount;
|
pub struct ChallengeAttemptCount;
|
||||||
pub struct ChallengeSuccessCount;
|
pub struct ChallengeSuccessCount;
|
||||||
pub struct AuthenticationErrorMessage;
|
pub struct AuthenticationErrorMessage;
|
||||||
|
pub struct AuthenticationFunnel;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<AuthEventMetrics> for NameDescription {
|
impl From<AuthEventMetrics> for NameDescription {
|
||||||
@ -125,6 +131,7 @@ impl From<AuthEventDimensions> for NameDescription {
|
|||||||
pub struct AuthEventMetricsBucketIdentifier {
|
pub struct AuthEventMetricsBucketIdentifier {
|
||||||
pub authentication_status: Option<AuthenticationStatus>,
|
pub authentication_status: Option<AuthenticationStatus>,
|
||||||
pub trans_status: Option<TransactionStatus>,
|
pub trans_status: Option<TransactionStatus>,
|
||||||
|
pub authentication_type: Option<DecoupledAuthenticationType>,
|
||||||
pub error_message: Option<String>,
|
pub error_message: Option<String>,
|
||||||
pub authentication_connector: Option<AuthenticationConnectors>,
|
pub authentication_connector: Option<AuthenticationConnectors>,
|
||||||
pub message_version: Option<String>,
|
pub message_version: Option<String>,
|
||||||
@ -140,6 +147,7 @@ impl AuthEventMetricsBucketIdentifier {
|
|||||||
pub fn new(
|
pub fn new(
|
||||||
authentication_status: Option<AuthenticationStatus>,
|
authentication_status: Option<AuthenticationStatus>,
|
||||||
trans_status: Option<TransactionStatus>,
|
trans_status: Option<TransactionStatus>,
|
||||||
|
authentication_type: Option<DecoupledAuthenticationType>,
|
||||||
error_message: Option<String>,
|
error_message: Option<String>,
|
||||||
authentication_connector: Option<AuthenticationConnectors>,
|
authentication_connector: Option<AuthenticationConnectors>,
|
||||||
message_version: Option<String>,
|
message_version: Option<String>,
|
||||||
@ -148,6 +156,7 @@ impl AuthEventMetricsBucketIdentifier {
|
|||||||
Self {
|
Self {
|
||||||
authentication_status,
|
authentication_status,
|
||||||
trans_status,
|
trans_status,
|
||||||
|
authentication_type,
|
||||||
error_message,
|
error_message,
|
||||||
authentication_connector,
|
authentication_connector,
|
||||||
message_version,
|
message_version,
|
||||||
@ -161,6 +170,7 @@ impl Hash for AuthEventMetricsBucketIdentifier {
|
|||||||
fn hash<H: Hasher>(&self, state: &mut H) {
|
fn hash<H: Hasher>(&self, state: &mut H) {
|
||||||
self.authentication_status.hash(state);
|
self.authentication_status.hash(state);
|
||||||
self.trans_status.hash(state);
|
self.trans_status.hash(state);
|
||||||
|
self.authentication_type.hash(state);
|
||||||
self.authentication_connector.hash(state);
|
self.authentication_connector.hash(state);
|
||||||
self.message_version.hash(state);
|
self.message_version.hash(state);
|
||||||
self.error_message.hash(state);
|
self.error_message.hash(state);
|
||||||
|
|||||||
@ -114,6 +114,10 @@ pub enum SdkEventNames {
|
|||||||
ThreeDsMethod,
|
ThreeDsMethod,
|
||||||
LoaderChanged,
|
LoaderChanged,
|
||||||
DisplayThreeDsSdk,
|
DisplayThreeDsSdk,
|
||||||
|
ThreeDsSdkInit,
|
||||||
|
AreqParamsGeneration,
|
||||||
|
ChallengePresented,
|
||||||
|
ChallengeComplete,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub mod metric_behaviour {
|
pub mod metric_behaviour {
|
||||||
|
|||||||
@ -90,6 +90,10 @@ pub mod routes {
|
|||||||
web::resource("report/payments")
|
web::resource("report/payments")
|
||||||
.route(web::post().to(generate_merchant_payment_report)),
|
.route(web::post().to(generate_merchant_payment_report)),
|
||||||
)
|
)
|
||||||
|
.service(
|
||||||
|
web::resource("report/authentications")
|
||||||
|
.route(web::post().to(generate_merchant_authentication_report)),
|
||||||
|
)
|
||||||
.service(
|
.service(
|
||||||
web::resource("metrics/sdk_events")
|
web::resource("metrics/sdk_events")
|
||||||
.route(web::post().to(get_sdk_event_metrics)),
|
.route(web::post().to(get_sdk_event_metrics)),
|
||||||
@ -190,6 +194,11 @@ pub mod routes {
|
|||||||
web::resource("report/payments")
|
web::resource("report/payments")
|
||||||
.route(web::post().to(generate_merchant_payment_report)),
|
.route(web::post().to(generate_merchant_payment_report)),
|
||||||
)
|
)
|
||||||
|
.service(
|
||||||
|
web::resource("report/authentications").route(
|
||||||
|
web::post().to(generate_merchant_authentication_report),
|
||||||
|
),
|
||||||
|
)
|
||||||
.service(
|
.service(
|
||||||
web::resource("metrics/api_events")
|
web::resource("metrics/api_events")
|
||||||
.route(web::post().to(get_merchant_api_events_metrics)),
|
.route(web::post().to(get_merchant_api_events_metrics)),
|
||||||
@ -252,6 +261,10 @@ pub mod routes {
|
|||||||
web::resource("report/payments")
|
web::resource("report/payments")
|
||||||
.route(web::post().to(generate_org_payment_report)),
|
.route(web::post().to(generate_org_payment_report)),
|
||||||
)
|
)
|
||||||
|
.service(
|
||||||
|
web::resource("report/authentications")
|
||||||
|
.route(web::post().to(generate_org_authentication_report)),
|
||||||
|
)
|
||||||
.service(
|
.service(
|
||||||
web::resource("metrics/sankey")
|
web::resource("metrics/sankey")
|
||||||
.route(web::post().to(get_org_sankey)),
|
.route(web::post().to(get_org_sankey)),
|
||||||
@ -306,6 +319,11 @@ pub mod routes {
|
|||||||
web::resource("report/payments")
|
web::resource("report/payments")
|
||||||
.route(web::post().to(generate_profile_payment_report)),
|
.route(web::post().to(generate_profile_payment_report)),
|
||||||
)
|
)
|
||||||
|
.service(
|
||||||
|
web::resource("report/authentications").route(
|
||||||
|
web::post().to(generate_profile_authentication_report),
|
||||||
|
),
|
||||||
|
)
|
||||||
.service(
|
.service(
|
||||||
web::resource("api_event_logs")
|
web::resource("api_event_logs")
|
||||||
.route(web::get().to(get_profile_api_events)),
|
.route(web::get().to(get_profile_api_events)),
|
||||||
@ -1746,6 +1764,7 @@ pub mod routes {
|
|||||||
))
|
))
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "v1")]
|
#[cfg(feature = "v1")]
|
||||||
pub async fn generate_org_payment_report(
|
pub async fn generate_org_payment_report(
|
||||||
state: web::Data<AppState>,
|
state: web::Data<AppState>,
|
||||||
@ -1850,6 +1869,161 @@ pub mod routes {
|
|||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "v1")]
|
||||||
|
pub async fn generate_merchant_authentication_report(
|
||||||
|
state: web::Data<AppState>,
|
||||||
|
req: actix_web::HttpRequest,
|
||||||
|
json_payload: web::Json<ReportRequest>,
|
||||||
|
) -> impl Responder {
|
||||||
|
let flow = AnalyticsFlow::GenerateAuthenticationReport;
|
||||||
|
Box::pin(api::server_wrap(
|
||||||
|
flow,
|
||||||
|
state.clone(),
|
||||||
|
&req,
|
||||||
|
json_payload.into_inner(),
|
||||||
|
|state, (auth, user_id): auth::AuthenticationDataWithUserId, payload, _| async move {
|
||||||
|
let user = UserInterface::find_user_by_id(&*state.global_store, &user_id)
|
||||||
|
.await
|
||||||
|
.change_context(AnalyticsError::UnknownError)?;
|
||||||
|
|
||||||
|
let user_email = UserEmail::from_pii_email(user.email)
|
||||||
|
.change_context(AnalyticsError::UnknownError)?
|
||||||
|
.get_secret();
|
||||||
|
|
||||||
|
let org_id = auth.merchant_account.get_org_id();
|
||||||
|
let merchant_id = auth.merchant_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()],
|
||||||
|
},
|
||||||
|
email: user_email,
|
||||||
|
};
|
||||||
|
|
||||||
|
let json_bytes =
|
||||||
|
serde_json::to_vec(&lambda_req).map_err(|_| AnalyticsError::UnknownError)?;
|
||||||
|
invoke_lambda(
|
||||||
|
&state.conf.report_download_config.authentication_function,
|
||||||
|
&state.conf.report_download_config.region,
|
||||||
|
&json_bytes,
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.map(ApplicationResponse::Json)
|
||||||
|
},
|
||||||
|
&auth::JWTAuth {
|
||||||
|
permission: Permission::MerchantReportRead,
|
||||||
|
},
|
||||||
|
api_locking::LockAction::NotApplicable,
|
||||||
|
))
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "v1")]
|
||||||
|
pub async fn generate_org_authentication_report(
|
||||||
|
state: web::Data<AppState>,
|
||||||
|
req: actix_web::HttpRequest,
|
||||||
|
json_payload: web::Json<ReportRequest>,
|
||||||
|
) -> impl Responder {
|
||||||
|
let flow = AnalyticsFlow::GenerateAuthenticationReport;
|
||||||
|
Box::pin(api::server_wrap(
|
||||||
|
flow,
|
||||||
|
state.clone(),
|
||||||
|
&req,
|
||||||
|
json_payload.into_inner(),
|
||||||
|
|state, (auth, user_id): auth::AuthenticationDataWithUserId, payload, _| async move {
|
||||||
|
let user = UserInterface::find_user_by_id(&*state.global_store, &user_id)
|
||||||
|
.await
|
||||||
|
.change_context(AnalyticsError::UnknownError)?;
|
||||||
|
|
||||||
|
let user_email = UserEmail::from_pii_email(user.email)
|
||||||
|
.change_context(AnalyticsError::UnknownError)?
|
||||||
|
.get_secret();
|
||||||
|
|
||||||
|
let org_id = auth.merchant_account.get_org_id();
|
||||||
|
let lambda_req = GenerateReportRequest {
|
||||||
|
request: payload,
|
||||||
|
merchant_id: None,
|
||||||
|
auth: AuthInfo::OrgLevel {
|
||||||
|
org_id: org_id.clone(),
|
||||||
|
},
|
||||||
|
email: user_email,
|
||||||
|
};
|
||||||
|
|
||||||
|
let json_bytes =
|
||||||
|
serde_json::to_vec(&lambda_req).map_err(|_| AnalyticsError::UnknownError)?;
|
||||||
|
invoke_lambda(
|
||||||
|
&state.conf.report_download_config.authentication_function,
|
||||||
|
&state.conf.report_download_config.region,
|
||||||
|
&json_bytes,
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.map(ApplicationResponse::Json)
|
||||||
|
},
|
||||||
|
&auth::JWTAuth {
|
||||||
|
permission: Permission::OrganizationReportRead,
|
||||||
|
},
|
||||||
|
api_locking::LockAction::NotApplicable,
|
||||||
|
))
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "v1")]
|
||||||
|
pub async fn generate_profile_authentication_report(
|
||||||
|
state: web::Data<AppState>,
|
||||||
|
req: actix_web::HttpRequest,
|
||||||
|
json_payload: web::Json<ReportRequest>,
|
||||||
|
) -> impl Responder {
|
||||||
|
let flow = AnalyticsFlow::GenerateAuthenticationReport;
|
||||||
|
Box::pin(api::server_wrap(
|
||||||
|
flow,
|
||||||
|
state.clone(),
|
||||||
|
&req,
|
||||||
|
json_payload.into_inner(),
|
||||||
|
|state, (auth, user_id): auth::AuthenticationDataWithUserId, payload, _| async move {
|
||||||
|
let user = UserInterface::find_user_by_id(&*state.global_store, &user_id)
|
||||||
|
.await
|
||||||
|
.change_context(AnalyticsError::UnknownError)?;
|
||||||
|
|
||||||
|
let user_email = UserEmail::from_pii_email(user.email)
|
||||||
|
.change_context(AnalyticsError::UnknownError)?
|
||||||
|
.get_secret();
|
||||||
|
let org_id = auth.merchant_account.get_org_id();
|
||||||
|
let merchant_id = auth.merchant_account.get_id();
|
||||||
|
let profile_id = auth
|
||||||
|
.profile_id
|
||||||
|
.ok_or(report!(UserErrors::JwtProfileIdMissing))
|
||||||
|
.change_context(AnalyticsError::AccessForbiddenError)?;
|
||||||
|
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()],
|
||||||
|
},
|
||||||
|
email: user_email,
|
||||||
|
};
|
||||||
|
|
||||||
|
let json_bytes =
|
||||||
|
serde_json::to_vec(&lambda_req).map_err(|_| AnalyticsError::UnknownError)?;
|
||||||
|
invoke_lambda(
|
||||||
|
&state.conf.report_download_config.authentication_function,
|
||||||
|
&state.conf.report_download_config.region,
|
||||||
|
&json_bytes,
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.map(ApplicationResponse::Json)
|
||||||
|
},
|
||||||
|
&auth::JWTAuth {
|
||||||
|
permission: Permission::ProfileReportRead,
|
||||||
|
},
|
||||||
|
api_locking::LockAction::NotApplicable,
|
||||||
|
))
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
/// # Panics
|
/// # Panics
|
||||||
///
|
///
|
||||||
/// Panics if `json_payload` array does not contain one `GetApiEventMetricRequest` element.
|
/// Panics if `json_payload` array does not contain one `GetApiEventMetricRequest` element.
|
||||||
|
|||||||
Reference in New Issue
Block a user