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): add compatibility for payout with anaylitics api (#10479)

Sakil Mostak31a88598bbf2
diff --git a/crates/analytics/src/api_event/events.rs b/crates/analytics/src/api_event/events.rs
index cbe597c408..db6dfd0de4 100644
--- a/crates/analytics/src/api_event/events.rs
+++ b/crates/analytics/src/api_event/events.rs
@@ -102,6 +102,27 @@ where
)
.switch()?;
}
+ QueryType::Payout { payout_id } => {
+ query_builder
+ .add_filter_clause("payout_id", &payout_id)
+ .switch()?;
+
+ query_builder
+ .add_filter_in_range_clause(
+ "api_flow",
+ &[
+ Flow::PayoutsCreate,
+ Flow::PayoutsConfirm,
+ Flow::PayoutsFulfill,
+ Flow::PayoutsCancel,
+ Flow::PayoutsRetrieve,
+ Flow::PayoutLinkInitiate,
+ Flow::PayoutsUpdate,
+ Flow::PayoutsCancel,
+ ],
+ )
+ .switch()?;
+ }
}
//TODO!: update the execute_query function to return reports instead of plain errors...
query_builder
diff --git a/crates/analytics/src/connector_events/events.rs b/crates/analytics/src/connector_events/events.rs
index 3c04bab1a4..8cab4cfb60 100644
--- a/crates/analytics/src/connector_events/events.rs
+++ b/crates/analytics/src/connector_events/events.rs
@@ -30,9 +30,11 @@ where
.add_filter_clause("merchant_id", merchant_id)
.switch()?;
- query_builder
- .add_filter_clause("payment_id", &query_param.payment_id)
- .switch()?;
+ if let Some(payment_id) = query_param.payment_id {
+ query_builder
+ .add_filter_clause("payment_id", &payment_id)
+ .switch()?;
+ }
if let Some(refund_id) = query_param.refund_id {
query_builder
@@ -46,6 +48,12 @@ where
.switch()?;
}
+ if let Some(payout_id) = query_param.payout_id {
+ query_builder
+ .add_filter_clause("payout_id", &payout_id)
+ .switch()?;
+ }
+
//TODO!: update the execute_query function to return reports instead of plain errors...
query_builder
.execute_query::<ConnectorEventsResult, _>(pool)
diff --git a/crates/analytics/src/outgoing_webhook_event/events.rs b/crates/analytics/src/outgoing_webhook_event/events.rs
index 05fd9afd52..684c633489 100644
--- a/crates/analytics/src/outgoing_webhook_event/events.rs
+++ b/crates/analytics/src/outgoing_webhook_event/events.rs
@@ -30,9 +30,17 @@ where
.add_filter_clause("merchant_id", merchant_id)
.switch()?;
- query_builder
- .add_filter_clause("payment_id", &query_param.payment_id)
- .switch()?;
+ if let Some(payment_id) = query_param.payment_id {
+ query_builder
+ .add_filter_clause("payment_id", &payment_id)
+ .switch()?;
+ }
+
+ if let Some(payout_id) = query_param.payout_id {
+ query_builder
+ .add_filter_clause("payout_id", &payout_id)
+ .switch()?;
+ }
if let Some(event_id) = query_param.event_id {
query_builder
diff --git a/crates/analytics/src/query.rs b/crates/analytics/src/query.rs
index 3e4f79254d..f8453eca39 100644
--- a/crates/analytics/src/query.rs
+++ b/crates/analytics/src/query.rs
@@ -454,6 +454,12 @@ impl<T: AnalyticsDataSource> ToSql<T> for &common_utils::id_type::PaymentId {
}
}
+impl<T: AnalyticsDataSource> ToSql<T> for &common_utils::id_type::PayoutId {
+ fn to_sql(&self, _table_engine: &TableEngine) -> error_stack::Result<String, ParsingError> {
+ Ok(self.get_string_repr().to_owned())
+ }
+}
+
impl<T: AnalyticsDataSource> ToSql<T> for common_utils::id_type::CustomerId {
fn to_sql(&self, _table_engine: &TableEngine) -> error_stack::Result<String, ParsingError> {
Ok(self.get_string_repr().to_owned())
diff --git a/crates/api_models/src/analytics/api_event.rs b/crates/api_models/src/analytics/api_event.rs
index ac8c014ed9..28b5b079e7 100644
--- a/crates/api_models/src/analytics/api_event.rs
+++ b/crates/api_models/src/analytics/api_event.rs
@@ -30,6 +30,9 @@ pub enum QueryType {
payment_id: common_utils::id_type::PaymentId,
dispute_id: String,
},
+ Payout {
+ payout_id: common_utils::id_type::PayoutId,
+ },
}
#[derive(
diff --git a/crates/api_models/src/analytics/connector_events.rs b/crates/api_models/src/analytics/connector_events.rs
index c72d7d6e51..f208ef2dac 100644
--- a/crates/api_models/src/analytics/connector_events.rs
+++ b/crates/api_models/src/analytics/connector_events.rs
@@ -1,6 +1,7 @@
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
pub struct ConnectorEventsRequest {
- pub payment_id: common_utils::id_type::PaymentId,
+ pub payment_id: Option<common_utils::id_type::PaymentId>,
+ pub payout_id: Option<common_utils::id_type::PayoutId>,
pub refund_id: Option<String>,
pub dispute_id: Option<String>,
}
diff --git a/crates/api_models/src/analytics/outgoing_webhook_event.rs b/crates/api_models/src/analytics/outgoing_webhook_event.rs
index e2373ca5ca..6b74608b99 100644
--- a/crates/api_models/src/analytics/outgoing_webhook_event.rs
+++ b/crates/api_models/src/analytics/outgoing_webhook_event.rs
@@ -1,6 +1,7 @@
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
pub struct OutgoingWebhookLogsRequest {
- pub payment_id: common_utils::id_type::PaymentId,
+ pub payment_id: Option<common_utils::id_type::PaymentId>,
+ pub payout_id: Option<common_utils::id_type::PayoutId>,
pub event_id: Option<String>,
pub refund_id: Option<String>,
pub dispute_id: Option<String>,
diff --git a/crates/router/src/analytics.rs b/crates/router/src/analytics.rs
index a09729b26c..409c3cf280 100644
--- a/crates/router/src/analytics.rs
+++ b/crates/router/src/analytics.rs
@@ -1656,18 +1656,19 @@ pub mod routes {
&req,
json_payload.into_inner(),
|state, auth: AuthenticationData, req, _| async move {
- let payment_id = match req.query_param.clone() {
- QueryType::Payment { payment_id } => payment_id,
- QueryType::Refund { payment_id, .. } => payment_id,
- QueryType::Dispute { payment_id, .. } => payment_id,
+ let (payment_id, payout_id) = match req.query_param.clone() {
+ QueryType::Payment { payment_id } => (Some(payment_id), None),
+ QueryType::Refund { payment_id, .. } => (Some(payment_id), None),
+ QueryType::Dispute { payment_id, .. } => (Some(payment_id), None),
+ QueryType::Payout { payout_id } => (None, Some(payout_id)),
};
#[cfg(feature = "v1")]
let profile_id = auth.profile.map(|profile| profile.get_id().clone());
#[cfg(feature = "v2")]
let profile_id = Some(auth.profile.get_id().clone());
-
- utils::check_if_profile_id_is_present_in_payment_intent(
+ utils::check_if_profile_id_is_present_in_intent_table(
payment_id,
+ payout_id,
&state,
auth.platform.get_processor(),
profile_id,
@@ -1708,8 +1709,9 @@ pub mod routes {
let profile_id = auth.profile.map(|profile| profile.get_id().clone());
#[cfg(feature = "v2")]
let profile_id = Some(auth.profile.get_id().clone());
- utils::check_if_profile_id_is_present_in_payment_intent(
+ utils::check_if_profile_id_is_present_in_intent_table(
req.payment_id.clone(),
+ req.payout_id.clone(),
&state,
auth.platform.get_processor(),
profile_id,
@@ -2637,8 +2639,9 @@ pub mod routes {
let profile_id = auth.profile.map(|profile| profile.get_id().clone());
#[cfg(feature = "v2")]
let profile_id = Some(auth.profile.get_id().clone());
- utils::check_if_profile_id_is_present_in_payment_intent(
+ utils::check_if_profile_id_is_present_in_intent_table(
req.payment_id.clone(),
+ req.payout_id.clone(),
&state,
auth.platform.get_processor(),
profile_id,
diff --git a/crates/router/src/core/verification/utils.rs b/crates/router/src/core/verification/utils.rs
index 785861a533..bb3a55c54b 100644
--- a/crates/router/src/core/verification/utils.rs
+++ b/crates/router/src/core/verification/utils.rs
@@ -1,4 +1,7 @@
-use common_utils::{errors::CustomResult, id_type::PaymentId};
+use common_utils::{
+ errors::CustomResult,
+ id_type::{PaymentId, PayoutId},
+};
use error_stack::{Report, ResultExt};
use crate::{
@@ -136,6 +139,49 @@ pub async fn check_if_profile_id_is_present_in_payment_intent(
todo!()
}
+#[cfg(feature = "v2")]
+pub async fn check_if_profile_id_is_present_in_intent_table(
+ payment_id: Option<PaymentId>,
+ payout_id: Option<PayoutId>,
+ state: &SessionState,
+ processor: &domain::Processor,
+ profile_id: Option<common_utils::id_type::ProfileId>,
+) -> CustomResult<(), errors::ApiErrorResponse> {
+ todo!()
+}
+
+#[cfg(feature = "v2")]
+pub async fn check_if_profile_id_is_present_in_payouts(
+ payout_id: PayoutId,
+ state: &SessionState,
+ processor: &domain::Processor,
+ profile_id: Option<common_utils::id_type::ProfileId>,
+) -> CustomResult<(), errors::ApiErrorResponse> {
+ todo!()
+}
+
+#[cfg(feature = "v1")]
+pub async fn check_if_profile_id_is_present_in_intent_table(
+ payment_id: Option<PaymentId>,
+ payout_id: Option<PayoutId>,
+ state: &SessionState,
+ processor: &domain::Processor,
+ profile_id: Option<common_utils::id_type::ProfileId>,
+) -> CustomResult<(), errors::ApiErrorResponse> {
+ match (payment_id, payout_id) {
+ (Some(payment_id), _) => {
+ check_if_profile_id_is_present_in_payment_intent(
+ payment_id, state, processor, profile_id,
+ )
+ .await
+ }
+ (None, Some(payout_id)) => {
+ check_if_profile_id_is_present_in_payouts(payout_id, state, processor, profile_id).await
+ }
+ (None, None) => Err(errors::ApiErrorResponse::Unauthorized.into()),
+ }
+}
+
#[cfg(feature = "v1")]
pub async fn check_if_profile_id_is_present_in_payment_intent(
payment_id: PaymentId,
@@ -155,3 +201,23 @@ pub async fn check_if_profile_id_is_present_in_payment_intent(
.change_context(errors::ApiErrorResponse::Unauthorized)?;
utils::validate_profile_id_from_auth_layer(profile_id, &payment_intent)
}
+
+#[cfg(feature = "v1")]
+pub async fn check_if_profile_id_is_present_in_payouts(
+ payout_id: PayoutId,
+ state: &SessionState,
+ processor: &domain::Processor,
+ profile_id: Option<common_utils::id_type::ProfileId>,
+) -> CustomResult<(), errors::ApiErrorResponse> {
+ let db = &*state.store;
+ let payouts = db
+ .find_payout_by_merchant_id_payout_id(
+ processor.get_account().get_id(),
+ &payout_id,
+ processor.get_account().storage_scheme,
+ )
+ .await
+ .change_context(errors::ApiErrorResponse::Unauthorized)?;
+
+ utils::validate_profile_id_from_auth_layer(profile_id, &payouts)
+}