Skip to content

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

feat(analytics): infer payout_audit table for payout analytics (#10842)

Sakil Mostak4593f6ab852f
diff --git a/crates/analytics/src/api_event/events.rs b/crates/analytics/src/api_event/events.rs
index db6dfd0de4..6354201261 100644
--- a/crates/analytics/src/api_event/events.rs
+++ b/crates/analytics/src/api_event/events.rs
@@ -26,7 +26,12 @@ where
Aggregate<&'static str>: ToSql<T>,
Window<&'static str>: ToSql<T>,
{
- let mut query_builder: QueryBuilder<T> = QueryBuilder::new(AnalyticsCollection::ApiEvents);
+ let mut query_builder: QueryBuilder<T> = match query_param.query_param.clone() {
+ QueryType::Payout { .. } => QueryBuilder::new(AnalyticsCollection::ApiPayoutEvents),
+ QueryType::Payment { .. } | QueryType::Refund { .. } | QueryType::Dispute { .. } => {
+ QueryBuilder::new(AnalyticsCollection::ApiEvents)
+ }
+ };
query_builder.add_select_column("*").switch()?;
query_builder
diff --git a/crates/analytics/src/clickhouse.rs b/crates/analytics/src/clickhouse.rs
index 383c18e6f0..2f6bfc7b0f 100644
--- a/crates/analytics/src/clickhouse.rs
+++ b/crates/analytics/src/clickhouse.rs
@@ -150,10 +150,13 @@ impl AnalyticsDataSource for ClickhouseClient {
AnalyticsCollection::SdkEvents
| AnalyticsCollection::SdkEventsAnalytics
| AnalyticsCollection::ApiEvents
+ | AnalyticsCollection::ApiPayoutEvents
| AnalyticsCollection::ConnectorEvents
+ | AnalyticsCollection::ConnectorPayoutEvents
| AnalyticsCollection::RoutingEvents
| AnalyticsCollection::ApiEventsAnalytics
| AnalyticsCollection::OutgoingWebhookEvent
+ | AnalyticsCollection::OutgoingWebhookPayoutEvent
| AnalyticsCollection::ActivePaymentsAnalytics => TableEngine::BasicTree,
}
}
@@ -475,11 +478,16 @@ impl ToSql<ClickhouseClient> for AnalyticsCollection {
Self::SdkEvents => Ok("sdk_events_audit".to_string()),
Self::SdkEventsAnalytics => Ok("sdk_events".to_string()),
Self::ApiEvents => Ok("api_events_audit".to_string()),
+ Self::ApiPayoutEvents => Ok("api_events_payout_audit".to_string()),
Self::ApiEventsAnalytics => Ok("api_events".to_string()),
Self::PaymentIntent => Ok("payment_intents".to_string()),
Self::PaymentIntentSessionized => Ok("sessionizer_payment_intents".to_string()),
Self::ConnectorEvents => Ok("connector_events_audit".to_string()),
+ Self::ConnectorPayoutEvents => Ok("connector_events_payout_audit".to_string()),
Self::OutgoingWebhookEvent => Ok("outgoing_webhook_events_audit".to_string()),
+ Self::OutgoingWebhookPayoutEvent => {
+ Ok("outgoing_webhook_events_payout_audit".to_string())
+ }
Self::Dispute => Ok("dispute".to_string()),
Self::DisputeSessionized => Ok("sessionizer_dispute".to_string()),
Self::ActivePaymentsAnalytics => Ok("active_payments".to_string()),
diff --git a/crates/analytics/src/connector_events/events.rs b/crates/analytics/src/connector_events/events.rs
index 8cab4cfb60..97f29b2111 100644
--- a/crates/analytics/src/connector_events/events.rs
+++ b/crates/analytics/src/connector_events/events.rs
@@ -22,8 +22,10 @@ where
Aggregate<&'static str>: ToSql<T>,
Window<&'static str>: ToSql<T>,
{
- let mut query_builder: QueryBuilder<T> =
- QueryBuilder::new(AnalyticsCollection::ConnectorEvents);
+ let mut query_builder: QueryBuilder<T> = match query_param.payment_id {
+ Some(_) => QueryBuilder::new(AnalyticsCollection::ConnectorEvents),
+ None => QueryBuilder::new(AnalyticsCollection::ConnectorPayoutEvents),
+ };
query_builder.add_select_column("*").switch()?;
query_builder
diff --git a/crates/analytics/src/outgoing_webhook_event/events.rs b/crates/analytics/src/outgoing_webhook_event/events.rs
index 684c633489..807dfc9dda 100644
--- a/crates/analytics/src/outgoing_webhook_event/events.rs
+++ b/crates/analytics/src/outgoing_webhook_event/events.rs
@@ -22,8 +22,10 @@ where
Aggregate<&'static str>: ToSql<T>,
Window<&'static str>: ToSql<T>,
{
- let mut query_builder: QueryBuilder<T> =
- QueryBuilder::new(AnalyticsCollection::OutgoingWebhookEvent);
+ let mut query_builder: QueryBuilder<T> = match query_param.payment_id.as_ref() {
+ Some(_) => QueryBuilder::new(AnalyticsCollection::OutgoingWebhookEvent),
+ None => QueryBuilder::new(AnalyticsCollection::OutgoingWebhookPayoutEvent),
+ };
query_builder.add_select_column("*").switch()?;
query_builder
diff --git a/crates/analytics/src/sqlx.rs b/crates/analytics/src/sqlx.rs
index c7b704d0e8..b44988a833 100644
--- a/crates/analytics/src/sqlx.rs
+++ b/crates/analytics/src/sqlx.rs
@@ -1455,6 +1455,8 @@ impl ToSql<SqlxClient> for AnalyticsCollection {
.attach_printable("SdkEvents table is not implemented for Sqlx"))?,
Self::ApiEvents => Err(error_stack::report!(ParsingError::UnknownError)
.attach_printable("ApiEvents table is not implemented for Sqlx"))?,
+ Self::ApiPayoutEvents => Err(error_stack::report!(ParsingError::UnknownError)
+ .attach_printable("ApiPayoutEvents table is not implemented for Sqlx"))?,
Self::FraudCheck => Ok("fraud_check".to_string()),
Self::PaymentIntent => Ok("payment_intent".to_string()),
Self::PaymentIntentSessionized => Err(error_stack::report!(
@@ -1463,12 +1465,18 @@ impl ToSql<SqlxClient> for AnalyticsCollection {
.attach_printable("PaymentIntentSessionized table is not implemented for Sqlx"))?,
Self::ConnectorEvents => Err(error_stack::report!(ParsingError::UnknownError)
.attach_printable("ConnectorEvents table is not implemented for Sqlx"))?,
+ Self::ConnectorPayoutEvents => Err(error_stack::report!(ParsingError::UnknownError)
+ .attach_printable("ConnectorPayoutEvents table is not implemented for Sqlx"))?,
Self::ApiEventsAnalytics => Err(error_stack::report!(ParsingError::UnknownError)
.attach_printable("ApiEvents table is not implemented for Sqlx"))?,
Self::ActivePaymentsAnalytics => Err(error_stack::report!(ParsingError::UnknownError)
.attach_printable("ActivePaymentsAnalytics table is not implemented for Sqlx"))?,
Self::OutgoingWebhookEvent => Err(error_stack::report!(ParsingError::UnknownError)
.attach_printable("OutgoingWebhookEvents table is not implemented for Sqlx"))?,
+ Self::OutgoingWebhookPayoutEvent => Err(error_stack::report!(
+ ParsingError::UnknownError
+ )
+ .attach_printable("OutgoingWebhookPayoutEvents table is not implemented for Sqlx"))?,
Self::Dispute => Ok("dispute".to_string()),
Self::DisputeSessionized => Err(error_stack::report!(ParsingError::UnknownError)
.attach_printable("DisputeSessionized table is not implemented for Sqlx"))?,
diff --git a/crates/analytics/src/types.rs b/crates/analytics/src/types.rs
index 4f9a7655ed..7f0db8dd2a 100644
--- a/crates/analytics/src/types.rs
+++ b/crates/analytics/src/types.rs
@@ -34,10 +34,13 @@ pub enum AnalyticsCollection {
SdkEvents,
SdkEventsAnalytics,
ApiEvents,
+ ApiPayoutEvents,
PaymentIntent,
PaymentIntentSessionized,
ConnectorEvents,
+ ConnectorPayoutEvents,
OutgoingWebhookEvent,
+ OutgoingWebhookPayoutEvent,
Authentications,
Dispute,
DisputeSessionized,