mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-27 19:46:48 +08:00
feat(analytics): Add refund sessionized metrics for Analytics V2 dashboard (#6616)
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
This commit is contained in:
@ -12,7 +12,7 @@ use self::{
|
||||
frm::{FrmDimensions, FrmMetrics},
|
||||
payment_intents::{PaymentIntentDimensions, PaymentIntentMetrics},
|
||||
payments::{PaymentDimensions, PaymentDistributions, PaymentMetrics},
|
||||
refunds::{RefundDimensions, RefundMetrics},
|
||||
refunds::{RefundDimensions, RefundDistributions, RefundMetrics},
|
||||
sdk_events::{SdkEventDimensions, SdkEventMetrics},
|
||||
};
|
||||
pub mod active_payments;
|
||||
@ -73,7 +73,7 @@ pub struct GetPaymentMetricRequest {
|
||||
#[serde(default)]
|
||||
pub filters: payments::PaymentFilters,
|
||||
pub metrics: HashSet<PaymentMetrics>,
|
||||
pub distribution: Option<Distribution>,
|
||||
pub distribution: Option<PaymentDistributionBody>,
|
||||
#[serde(default)]
|
||||
pub delta: bool,
|
||||
}
|
||||
@ -98,11 +98,18 @@ impl Into<u64> for QueryLimit {
|
||||
|
||||
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct Distribution {
|
||||
pub struct PaymentDistributionBody {
|
||||
pub distribution_for: PaymentDistributions,
|
||||
pub distribution_cardinality: QueryLimit,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct RefundDistributionBody {
|
||||
pub distribution_for: RefundDistributions,
|
||||
pub distribution_cardinality: QueryLimit,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct ReportRequest {
|
||||
@ -142,6 +149,7 @@ pub struct GetRefundMetricRequest {
|
||||
#[serde(default)]
|
||||
pub filters: refunds::RefundFilters,
|
||||
pub metrics: HashSet<RefundMetrics>,
|
||||
pub distribution: Option<RefundDistributionBody>,
|
||||
#[serde(default)]
|
||||
pub delta: bool,
|
||||
}
|
||||
@ -230,8 +238,12 @@ pub struct PaymentIntentsAnalyticsMetadata {
|
||||
|
||||
#[derive(Debug, serde::Serialize)]
|
||||
pub struct RefundsAnalyticsMetadata {
|
||||
pub total_refund_success_rate: Option<f64>,
|
||||
pub total_refund_processed_amount: Option<u64>,
|
||||
pub total_refund_processed_amount_in_usd: Option<u64>,
|
||||
pub total_refund_processed_count: Option<u64>,
|
||||
pub total_refund_reason_count: Option<u64>,
|
||||
pub total_refund_error_message_count: Option<u64>,
|
||||
}
|
||||
#[derive(Debug, serde::Deserialize, serde::Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
|
||||
@ -43,6 +43,10 @@ pub struct RefundFilters {
|
||||
pub refund_type: Vec<RefundType>,
|
||||
#[serde(default)]
|
||||
pub profile_id: Vec<id_type::ProfileId>,
|
||||
#[serde(default)]
|
||||
pub refund_reason: Vec<String>,
|
||||
#[serde(default)]
|
||||
pub refund_error_message: Vec<String>,
|
||||
}
|
||||
|
||||
#[derive(
|
||||
@ -67,6 +71,8 @@ pub enum RefundDimensions {
|
||||
Connector,
|
||||
RefundType,
|
||||
ProfileId,
|
||||
RefundReason,
|
||||
RefundErrorMessage,
|
||||
}
|
||||
|
||||
#[derive(
|
||||
@ -92,6 +98,44 @@ pub enum RefundMetrics {
|
||||
SessionizedRefundCount,
|
||||
SessionizedRefundSuccessCount,
|
||||
SessionizedRefundProcessedAmount,
|
||||
SessionizedRefundReason,
|
||||
SessionizedRefundErrorMessage,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, serde::Serialize)]
|
||||
pub struct ReasonsResult {
|
||||
pub reason: String,
|
||||
pub count: i64,
|
||||
pub percentage: f64,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, serde::Serialize)]
|
||||
pub struct ErrorMessagesResult {
|
||||
pub error_message: String,
|
||||
pub count: i64,
|
||||
pub percentage: f64,
|
||||
}
|
||||
|
||||
#[derive(
|
||||
Clone,
|
||||
Copy,
|
||||
Debug,
|
||||
Hash,
|
||||
PartialEq,
|
||||
Eq,
|
||||
serde::Serialize,
|
||||
serde::Deserialize,
|
||||
strum::Display,
|
||||
strum::EnumIter,
|
||||
strum::AsRefStr,
|
||||
)]
|
||||
#[strum(serialize_all = "snake_case")]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum RefundDistributions {
|
||||
#[strum(serialize = "refund_reason")]
|
||||
SessionizedRefundReason,
|
||||
#[strum(serialize = "refund_error_message")]
|
||||
SessionizedRefundErrorMessage,
|
||||
}
|
||||
|
||||
pub mod metric_behaviour {
|
||||
@ -124,9 +168,10 @@ pub struct RefundMetricsBucketIdentifier {
|
||||
pub currency: Option<Currency>,
|
||||
pub refund_status: Option<String>,
|
||||
pub connector: Option<String>,
|
||||
|
||||
pub refund_type: Option<String>,
|
||||
pub profile_id: Option<String>,
|
||||
pub refund_reason: Option<String>,
|
||||
pub refund_error_message: Option<String>,
|
||||
#[serde(rename = "time_range")]
|
||||
pub time_bucket: TimeRange,
|
||||
#[serde(rename = "time_bucket")]
|
||||
@ -141,6 +186,8 @@ impl Hash for RefundMetricsBucketIdentifier {
|
||||
self.connector.hash(state);
|
||||
self.refund_type.hash(state);
|
||||
self.profile_id.hash(state);
|
||||
self.refund_reason.hash(state);
|
||||
self.refund_error_message.hash(state);
|
||||
self.time_bucket.hash(state);
|
||||
}
|
||||
}
|
||||
@ -155,12 +202,15 @@ impl PartialEq for RefundMetricsBucketIdentifier {
|
||||
}
|
||||
|
||||
impl RefundMetricsBucketIdentifier {
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn new(
|
||||
currency: Option<Currency>,
|
||||
refund_status: Option<String>,
|
||||
connector: Option<String>,
|
||||
refund_type: Option<String>,
|
||||
profile_id: Option<String>,
|
||||
refund_reason: Option<String>,
|
||||
refund_error_message: Option<String>,
|
||||
normalized_time_range: TimeRange,
|
||||
) -> Self {
|
||||
Self {
|
||||
@ -169,6 +219,8 @@ impl RefundMetricsBucketIdentifier {
|
||||
connector,
|
||||
refund_type,
|
||||
profile_id,
|
||||
refund_reason,
|
||||
refund_error_message,
|
||||
time_bucket: normalized_time_range,
|
||||
start_time: normalized_time_range.start_time,
|
||||
}
|
||||
@ -176,11 +228,18 @@ impl RefundMetricsBucketIdentifier {
|
||||
}
|
||||
#[derive(Debug, serde::Serialize)]
|
||||
pub struct RefundMetricsBucketValue {
|
||||
pub successful_refunds: Option<u32>,
|
||||
pub total_refunds: Option<u32>,
|
||||
pub refund_success_rate: Option<f64>,
|
||||
pub refund_count: Option<u64>,
|
||||
pub refund_success_count: Option<u64>,
|
||||
pub refund_processed_amount: Option<u64>,
|
||||
pub refund_processed_amount_in_usd: Option<u64>,
|
||||
pub refund_processed_count: Option<u64>,
|
||||
pub refund_reason_distribution: Option<Vec<ReasonsResult>>,
|
||||
pub refund_error_message_distribution: Option<Vec<ErrorMessagesResult>>,
|
||||
pub refund_reason_count: Option<u64>,
|
||||
pub refund_error_message_count: Option<u64>,
|
||||
}
|
||||
#[derive(Debug, serde::Serialize)]
|
||||
pub struct RefundMetricsBucketResponse {
|
||||
|
||||
Reference in New Issue
Block a user