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(webhooks): add payment methods related flows to analytics event tracking and IncomingWebhookReceive flow to refunds analytics filter (#10549)

Venu Madhav Bandarupallia61d8f181638
diff --git a/crates/analytics/src/api_event/events.rs b/crates/analytics/src/api_event/events.rs
index 3003288ddd..cbe597c408 100644
--- a/crates/analytics/src/api_event/events.rs
+++ b/crates/analytics/src/api_event/events.rs
@@ -53,6 +53,9 @@ where
Flow::AttachDisputeEvidence,
Flow::RetrieveDisputeEvidence,
Flow::IncomingWebhookReceive,
+ Flow::PaymentMethodsList,
+ Flow::CustomerPaymentMethodsList,
+ Flow::PaymentsSessionToken,
],
)
.switch()?;
@@ -68,7 +71,14 @@ where
.add_filter_clause("refund_id", refund_id)
.switch()?;
query_builder
- .add_filter_in_range_clause("api_flow", &[Flow::RefundsCreate, Flow::RefundsUpdate])
+ .add_filter_in_range_clause(
+ "api_flow",
+ &[
+ Flow::RefundsCreate,
+ Flow::RefundsUpdate,
+ Flow::IncomingWebhookReceive,
+ ],
+ )
.switch()?;
}
QueryType::Dispute {
diff --git a/crates/api_models/src/webhooks.rs b/crates/api_models/src/webhooks.rs
index 26d3e28e4e..8f8e500184 100644
--- a/crates/api_models/src/webhooks.rs
+++ b/crates/api_models/src/webhooks.rs
@@ -177,7 +177,7 @@ pub enum WebhookResponseTracker {
#[cfg(feature = "v2")]
Refund {
payment_id: common_utils::id_type::GlobalPaymentId,
- refund_id: String,
+ refund_id: common_utils::id_type::GlobalRefundId,
status: common_enums::RefundStatus,
},
#[cfg(feature = "v1")]
@@ -222,6 +222,14 @@ impl WebhookResponseTracker {
}
}
+ #[cfg(feature = "v1")]
+ pub fn get_refund_id(&self) -> Option<String> {
+ match self {
+ Self::Refund { refund_id, .. } => Some(refund_id.to_owned()),
+ _ => None,
+ }
+ }
+
#[cfg(feature = "v1")]
pub fn get_payment_method_id(&self) -> Option<String> {
match self {
@@ -251,6 +259,14 @@ impl WebhookResponseTracker {
Self::Relay { .. } => None,
}
}
+
+ #[cfg(feature = "v2")]
+ pub fn get_refund_id(&self) -> Option<common_utils::id_type::GlobalRefundId> {
+ match self {
+ Self::Refund { refund_id, .. } => Some(refund_id.to_owned()),
+ _ => None,
+ }
+ }
}
impl From<IncomingWebhookEvent> for WebhookFlow {
diff --git a/crates/common_utils/src/events.rs b/crates/common_utils/src/events.rs
index f7651e22bd..3f35443ee5 100644
--- a/crates/common_utils/src/events.rs
+++ b/crates/common_utils/src/events.rs
@@ -74,6 +74,7 @@ pub enum ApiEventsType {
Webhooks {
connector: String,
payment_id: Option<id_type::PaymentId>,
+ refund_id: Option<String>,
},
#[cfg(feature = "v1")]
NetworkTokenWebhook {
@@ -83,6 +84,7 @@ pub enum ApiEventsType {
Webhooks {
connector: id_type::MerchantConnectorAccountId,
payment_id: Option<id_type::GlobalPaymentId>,
+ refund_id: Option<id_type::GlobalRefundId>,
},
Routing,
Subscription,
diff --git a/crates/router/src/core/webhooks/incoming.rs b/crates/router/src/core/webhooks/incoming.rs
index 1d2ac0f935..ce8b3a1f7a 100644
--- a/crates/router/src/core/webhooks/incoming.rs
+++ b/crates/router/src/core/webhooks/incoming.rs
@@ -108,6 +108,7 @@ pub async fn incoming_webhooks_wrapper<W: types::OutgoingWebhookType>(
let api_event = ApiEventsType::Webhooks {
connector: connector_name_or_mca_id.to_string(),
payment_id: webhooks_response_tracker.get_payment_id(),
+ refund_id: webhooks_response_tracker.get_refund_id(),
};
let response_value = serde_json::to_value(&webhooks_response_tracker)
.change_context(errors::ApiErrorResponse::InternalServerError)
diff --git a/crates/router/src/core/webhooks/incoming_v2.rs b/crates/router/src/core/webhooks/incoming_v2.rs
index 53da2ee3b9..e619f89628 100644
--- a/crates/router/src/core/webhooks/incoming_v2.rs
+++ b/crates/router/src/core/webhooks/incoming_v2.rs
@@ -92,6 +92,7 @@ pub async fn incoming_webhooks_wrapper<W: types::OutgoingWebhookType>(
let api_event = ApiEventsType::Webhooks {
connector: connector_id.clone(),
payment_id: webhooks_response_tracker.get_payment_id(),
+ refund_id: webhooks_response_tracker.get_refund_id(),
};
let response_value = serde_json::to_value(&webhooks_response_tracker)
.change_context(errors::ApiErrorResponse::InternalServerError)