feat(analytics): add first_attempt as a filter for PaymentFilters (#6604)

This commit is contained in:
Sandeep Kumar
2024-11-24 18:32:46 +05:30
committed by GitHub
parent 8d0639ea6f
commit 9460041b2a
5 changed files with 19 additions and 0 deletions

View File

@ -64,4 +64,5 @@ pub struct PaymentFilterRow {
pub card_last_4: Option<String>, pub card_last_4: Option<String>,
pub card_issuer: Option<String>, pub card_issuer: Option<String>,
pub error_reason: Option<String>, pub error_reason: Option<String>,
pub first_attempt: Option<bool>,
} }

View File

@ -104,6 +104,11 @@ where
.add_filter_in_range_clause(PaymentDimensions::ErrorReason, &self.error_reason) .add_filter_in_range_clause(PaymentDimensions::ErrorReason, &self.error_reason)
.attach_printable("Error adding error reason filter")?; .attach_printable("Error adding error reason filter")?;
} }
if !self.first_attempt.is_empty() {
builder
.add_filter_in_range_clause("first_attempt", &self.first_attempt)
.attach_printable("Error adding first attempt filter")?;
}
Ok(()) Ok(())
} }
} }

View File

@ -457,6 +457,12 @@ impl<T: AnalyticsDataSource> ToSql<T> for common_utils::id_type::CustomerId {
} }
} }
impl<T: AnalyticsDataSource> ToSql<T> for bool {
fn to_sql(&self, _table_engine: &TableEngine) -> error_stack::Result<String, ParsingError> {
Ok(self.to_string().to_owned())
}
}
/// Implement `ToSql` on arrays of types that impl `ToString`. /// Implement `ToSql` on arrays of types that impl `ToString`.
macro_rules! impl_to_sql_for_to_string { macro_rules! impl_to_sql_for_to_string {
($($type:ty),+) => { ($($type:ty),+) => {

View File

@ -569,6 +569,10 @@ impl<'a> FromRow<'a, PgRow> for super::payments::filters::PaymentFilterRow {
ColumnNotFound(_) => Ok(Default::default()), ColumnNotFound(_) => Ok(Default::default()),
e => Err(e), e => Err(e),
})?; })?;
let first_attempt: Option<bool> = row.try_get("first_attempt").or_else(|e| match e {
ColumnNotFound(_) => Ok(Default::default()),
e => Err(e),
})?;
Ok(Self { Ok(Self {
currency, currency,
status, status,
@ -584,6 +588,7 @@ impl<'a> FromRow<'a, PgRow> for super::payments::filters::PaymentFilterRow {
card_last_4, card_last_4,
card_issuer, card_issuer,
error_reason, error_reason,
first_attempt,
}) })
} }
} }

View File

@ -41,6 +41,8 @@ pub struct PaymentFilters {
pub card_issuer: Vec<String>, pub card_issuer: Vec<String>,
#[serde(default)] #[serde(default)]
pub error_reason: Vec<String>, pub error_reason: Vec<String>,
#[serde(default)]
pub first_attempt: Vec<bool>,
} }
#[derive( #[derive(