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

chore(connector_events_fields): added refund_id, dispute_id to connector events (#3424)

ivor-juspay90a24625ce31
diff --git a/crates/analytics/docs/clickhouse/scripts/connector_events.sql b/crates/analytics/docs/clickhouse/scripts/connector_events.sql
index 5821cd0355..4a53f9edb0 100644
--- a/crates/analytics/docs/clickhouse/scripts/connector_events.sql
+++ b/crates/analytics/docs/clickhouse/scripts/connector_events.sql
@@ -10,7 +10,9 @@ CREATE TABLE connector_events_queue (
`status_code` UInt32,
`created_at` DateTime64(3),
`latency` UInt128,
- `method` LowCardinality(String)
+ `method` LowCardinality(String),
+ `refund_id` Nullable(String),
+ `dispute_id` Nullable(String)
) ENGINE = Kafka SETTINGS kafka_broker_list = 'kafka0:29092',
kafka_topic_list = 'hyperswitch-connector-api-events',
kafka_group_name = 'hyper-c1',
@@ -32,6 +34,8 @@ CREATE TABLE connector_events_dist (
`inserted_at` DateTime64(3),
`latency` UInt128,
`method` LowCardinality(String),
+ `refund_id` Nullable(String),
+ `dispute_id` Nullable(String),
INDEX flowIndex flowTYPE bloom_filter GRANULARITY 1,
INDEX connectorIndex connector_name TYPE bloom_filter GRANULARITY 1,
INDEX statusIndex status_code TYPE bloom_filter GRANULARITY 1
@@ -54,7 +58,9 @@ CREATE MATERIALIZED VIEW connector_events_mv TO connector_events_dist (
`status_code` UInt32,
`created_at` DateTime64(3),
`latency` UInt128,
- `method` LowCardinality(String)
+ `method` LowCardinality(String),
+ `refund_id` Nullable(String),
+ `dispute_id` Nullable(String)
) AS
SELECT
merchant_id,
@@ -70,6 +76,8 @@ SELECT
now() as inserted_at,
latency,
method,
+ refund_id,
+ dispute_id
FROM
connector_events_queue
where length(_error) = 0;
diff --git a/crates/analytics/src/connector_events/events.rs b/crates/analytics/src/connector_events/events.rs
index 096520777e..47044811a8 100644
--- a/crates/analytics/src/connector_events/events.rs
+++ b/crates/analytics/src/connector_events/events.rs
@@ -1,7 +1,4 @@
-use api_models::analytics::{
- connector_events::{ConnectorEventsRequest, QueryType},
- Granularity,
-};
+use api_models::analytics::{connector_events::ConnectorEventsRequest, Granularity};
use common_utils::errors::ReportSwitchExt;
use error_stack::ResultExt;
use time::PrimitiveDateTime;
@@ -32,11 +29,23 @@ where
query_builder
.add_filter_clause("merchant_id", merchant_id)
.switch()?;
- match query_param.query_param {
- QueryType::Payment { payment_id } => query_builder
- .add_filter_clause("payment_id", payment_id)
- .switch()?,
+
+ query_builder
+ .add_filter_clause("payment_id", query_param.payment_id)
+ .switch()?;
+
+ if let Some(refund_id) = query_param.refund_id {
+ query_builder
+ .add_filter_clause("refund_id", &refund_id)
+ .switch()?;
+ }
+
+ if let Some(dispute_id) = query_param.dispute_id {
+ query_builder
+ .add_filter_clause("dispute_id", &dispute_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/api_models/src/analytics/connector_events.rs b/crates/api_models/src/analytics/connector_events.rs
index b2974b0a33..7d7e4ae2a8 100644
--- a/crates/api_models/src/analytics/connector_events.rs
+++ b/crates/api_models/src/analytics/connector_events.rs
@@ -1,11 +1,6 @@
-#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
-#[serde(tag = "type")]
-pub enum QueryType {
- Payment { payment_id: String },
-}
-
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
pub struct ConnectorEventsRequest {
- #[serde(flatten)]
- pub query_param: QueryType,
+ pub payment_id: String,
+ pub refund_id: Option<String>,
+ pub dispute_id: Option<String>,
}
diff --git a/crates/router/src/core/fraud_check/flows/checkout_flow.rs b/crates/router/src/core/fraud_check/flows/checkout_flow.rs
index 7f8993af52..8b3eed45f9 100644
--- a/crates/router/src/core/fraud_check/flows/checkout_flow.rs
+++ b/crates/router/src/core/fraud_check/flows/checkout_flow.rs
@@ -119,6 +119,8 @@ impl ConstructFlowSpecificData<frm_api::Checkout, FraudCheckCheckoutData, FraudC
connector_api_version: None,
apple_pay_flow: None,
frm_metadata: self.frm_metadata.clone(),
+ refund_id: None,
+ dispute_id: None,
};
Ok(router_data)
diff --git a/crates/router/src/core/fraud_check/flows/fulfillment_flow.rs b/crates/router/src/core/fraud_check/flows/fulfillment_flow.rs
index 79b6811a6e..706a0f9142 100644
--- a/crates/router/src/core/fraud_check/flows/fulfillment_flow.rs
+++ b/crates/router/src/core/fraud_check/flows/fulfillment_flow.rs
@@ -106,6 +106,8 @@ pub async fn construct_fulfillment_router_data<'a>(
external_latency: None,
apple_pay_flow: None,
frm_metadata: None,
+ refund_id: None,
+ dispute_id: None,
};
Ok(router_data)
}
diff --git a/crates/router/src/core/fraud_check/flows/record_return.rs b/crates/router/src/core/fraud_check/flows/record_return.rs
index bd0ba3e4f7..2de6aaab7c 100644
--- a/crates/router/src/core/fraud_check/flows/record_return.rs
+++ b/crates/router/src/core/fraud_check/flows/record_return.rs
@@ -97,6 +97,8 @@ impl ConstructFlowSpecificData<RecordReturn, FraudCheckRecordReturnData, FraudCh
connector_api_version: None,
apple_pay_flow: None,
frm_metadata: None,
+ refund_id: None,
+ dispute_id: None,
};
Ok(router_data)
diff --git a/crates/router/src/core/fraud_check/flows/sale_flow.rs b/crates/router/src/core/fraud_check/flows/sale_flow.rs
index 9c2708b28b..dfe7057004 100644
--- a/crates/router/src/core/fraud_check/flows/sale_flow.rs
+++ b/crates/router/src/core/fraud_check/flows/sale_flow.rs
@@ -93,6 +93,8 @@ impl ConstructFlowSpecificData<frm_api::Sale, FraudCheckSaleData, FraudCheckResp
connector_api_version: None,
apple_pay_flow: None,
frm_metadata: None,
+ refund_id: None,
+ dispute_id: None,
};
Ok(router_data)
diff --git a/crates/router/src/core/fraud_check/flows/transaction_flow.rs b/crates/router/src/core/fraud_check/flows/transaction_flow.rs
index 5eaa17d329..a84d9a771b 100644
--- a/crates/router/src/core/fraud_check/flows/transaction_flow.rs
+++ b/crates/router/src/core/fraud_check/flows/transaction_flow.rs
@@ -109,6 +109,8 @@ impl
connector_api_version: None,
apple_pay_flow: None,
frm_metadata: None,
+ refund_id: None,
+ dispute_id: None,
};
Ok(router_data)
diff --git a/crates/router/src/core/mandate/utils.rs b/crates/router/src/core/mandate/utils.rs
index 25267db1a9..4863edd6fc 100644
--- a/crates/router/src/core/mandate/utils.rs
+++ b/crates/router/src/core/mandate/utils.rs
@@ -70,6 +70,8 @@ pub async fn construct_mandate_revoke_router_data(
payout_method_data: None,
#[cfg(feature = "payouts")]
quote_id: None,
+ refund_id: None,
+ dispute_id: None,
};
Ok(router_data)
diff --git a/crates/router/src/core/payments/helpers.rs b/crates/router/src/core/payments/helpers.rs
index 520582eb22..fe4a7757ec 100644
--- a/crates/router/src/core/payments/helpers.rs
+++ b/crates/router/src/core/payments/helpers.rs
@@ -2997,6 +2997,8 @@ pub fn router_data_type_conversion<F1, F2, Req1, Req2, Res1, Res2>(
external_latency: router_data.external_latency,
apple_pay_flow: router_data.apple_pay_flow,
frm_metadata: router_data.frm_metadata,
+ refund_id: router_data.refund_id,
+ dispute_id: router_data.dispute_id,
}
}
diff --git a/crates/router/src/core/payments/transformers.rs b/crates/router/src/core/payments/transformers.rs
index 5b05e60150..1b4b2fc9fc 100644
--- a/crates/router/src/core/payments/transformers.rs
+++ b/crates/router/src/core/payments/transformers.rs
@@ -167,6 +167,8 @@ where
external_latency: None,
apple_pay_flow,
frm_metadata: None,
+ refund_id: None,
+ dispute_id: None,
};
Ok(router_data)
diff --git a/crates/router/src/core/utils.rs b/crates/router/src/core/utils.rs
index 016d5ec955..ef8dddde95 100644
--- a/crates/router/src/core/utils.rs
+++ b/crates/router/src/core/utils.rs
@@ -176,6 +176,8 @@ pub async fn construct_payout_router_data<'a, F>(
external_latency: None,
apple_pay_flow: None,
frm_metadata: None,
+ refund_id: None,
+ dispute_id: None,
};
Ok(router_data)
@@ -328,6 +330,8 @@ pub async fn construct_refund_router_data<'a, F>(
external_latency: None,
apple_pay_flow: None,
frm_metadata: None,
+ refund_id: Some(refund.refund_id.clone()),
+ dispute_id: None,
};
Ok(router_data)
@@ -558,6 +562,8 @@ pub async fn construct_accept_dispute_router_data<'a>(
external_latency: None,
apple_pay_flow: None,
frm_metadata: None,
+ dispute_id: Some(dispute.dispute_id.clone()),
+ refund_id: None,
};
Ok(router_data)
}
@@ -646,6 +652,8 @@ pub async fn construct_submit_evidence_router_data<'a>(
external_latency: None,
apple_pay_flow: None,
frm_metadata: None,
+ refund_id: None,
+ dispute_id: Some(dispute.dispute_id.clone()),
};
Ok(router_data)
}
@@ -740,6 +748,8 @@ pub async fn construct_upload_file_router_data<'a>(
external_latency: None,
apple_pay_flow: None,
frm_metadata: None,
+ refund_id: None,
+ dispute_id: None,
};
Ok(router_data)
}
@@ -831,6 +841,8 @@ pub async fn construct_defend_dispute_router_data<'a>(
external_latency: None,
apple_pay_flow: None,
frm_metadata: None,
+ refund_id: None,
+ dispute_id: Some(dispute.dispute_id.clone()),
};
Ok(router_data)
}
@@ -915,6 +927,8 @@ pub async fn construct_retrieve_file_router_data<'a>(
external_latency: None,
apple_pay_flow: None,
frm_metadata: None,
+ refund_id: None,
+ dispute_id: None,
};
Ok(router_data)
}
diff --git a/crates/router/src/core/webhooks/utils.rs b/crates/router/src/core/webhooks/utils.rs
index 08b4904804..75d37f9427 100644
--- a/crates/router/src/core/webhooks/utils.rs
+++ b/crates/router/src/core/webhooks/utils.rs
@@ -114,6 +114,8 @@ pub async fn construct_webhook_router_data<'a>(
external_latency: None,
apple_pay_flow: None,
frm_metadata: None,
+ refund_id: None,
+ dispute_id: None,
};
Ok(router_data)
}
diff --git a/crates/router/src/events/connector_api_logs.rs b/crates/router/src/events/connector_api_logs.rs
index 45c05a3077..4d3aadc3c4 100644
--- a/crates/router/src/events/connector_api_logs.rs
+++ b/crates/router/src/events/connector_api_logs.rs
@@ -18,6 +18,8 @@ pub struct ConnectorEvent {
created_at: i128,
request_id: String,
latency: u128,
+ refund_id: Option<String>,
+ dispute_id: Option<String>,
status_code: u16,
}
@@ -34,6 +36,8 @@ impl ConnectorEvent {
merchant_id: String,
request_id: Option<&RequestId>,
latency: u128,
+ refund_id: Option<String>,
+ dispute_id: Option<String>,
status_code: u16,
) -> Self {
Self {
@@ -54,6 +58,8 @@ impl ConnectorEvent {
.map(|i| i.as_hyphenated().to_string())
.unwrap_or("NO_REQUEST_ID".to_string()),
latency,
+ refund_id,
+ dispute_id,
status_code,
}
}
diff --git a/crates/router/src/services/api.rs b/crates/router/src/services/api.rs
index 4251679d5d..aec0b9bde9 100644
--- a/crates/router/src/services/api.rs
+++ b/crates/router/src/services/api.rs
@@ -400,6 +400,8 @@ where
req.merchant_id.clone(),
state.request_id.as_ref(),
external_latency,
+ req.refund_id.clone(),
+ req.dispute_id.clone(),
status_code,
);
diff --git a/crates/router/src/types.rs b/crates/router/src/types.rs
index 531ca849a3..10e13a6af5 100644
--- a/crates/router/src/types.rs
+++ b/crates/router/src/types.rs
@@ -319,6 +319,9 @@ pub struct RouterData<Flow, Request, Response> {
pub apple_pay_flow: Option<storage_enums::ApplePayFlow>,
pub frm_metadata: Option<serde_json::Value>,
+
+ pub dispute_id: Option<String>,
+ pub refund_id: Option<String>,
}
#[derive(Debug, Clone, serde::Deserialize)]
@@ -1467,6 +1470,8 @@ impl<F1, F2, T1, T2> From<(&RouterData<F1, T1, PaymentsResponseData>, T2)>
external_latency: data.external_latency,
apple_pay_flow: data.apple_pay_flow.clone(),
frm_metadata: data.frm_metadata.clone(),
+ dispute_id: data.dispute_id.clone(),
+ refund_id: data.refund_id.clone(),
}
}
}
@@ -1523,6 +1528,8 @@ impl<F1, F2>
external_latency: data.external_latency,
apple_pay_flow: None,
frm_metadata: None,
+ refund_id: None,
+ dispute_id: None,
}
}
}
diff --git a/crates/router/src/types/api/verify_connector.rs b/crates/router/src/types/api/verify_connector.rs
index fbd9423058..c03f492e8b 100644
--- a/crates/router/src/types/api/verify_connector.rs
+++ b/crates/router/src/types/api/verify_connector.rs
@@ -103,6 +103,8 @@ impl VerifyConnectorData {
external_latency: None,
apple_pay_flow: None,
frm_metadata: None,
+ refund_id: None,
+ dispute_id: None,
}
}
}
diff --git a/crates/router/tests/connectors/aci.rs b/crates/router/tests/connectors/aci.rs
index c820b7acd6..d3f8147fb2 100644
--- a/crates/router/tests/connectors/aci.rs
+++ b/crates/router/tests/connectors/aci.rs
@@ -98,6 +98,8 @@ fn construct_payment_router_data() -> types::PaymentsAuthorizeRouterData {
apple_pay_flow: None,
external_latency: None,
frm_metadata: None,
+ refund_id: None,
+ dispute_id: None,
}
}
@@ -157,6 +159,8 @@ fn construct_refund_router_data<F>() -> types::RefundsRouterData<F> {
apple_pay_flow: None,
external_latency: None,
frm_metadata: None,
+ refund_id: None,
+ dispute_id: None,
}
}
diff --git a/crates/router/tests/connectors/utils.rs b/crates/router/tests/connectors/utils.rs
index ed3cdbe31b..844777e2dc 100644
--- a/crates/router/tests/connectors/utils.rs
+++ b/crates/router/tests/connectors/utils.rs
@@ -524,6 +524,8 @@ pub trait ConnectorActions: Connector {
apple_pay_flow: None,
external_latency: None,
frm_metadata: None,
+ refund_id: None,
+ dispute_id: None,
}
}