From 90a24625ce312e4e7681cf4cc470e6365a052f8a Mon Sep 17 00:00:00 2001 From: ivor-juspay <138492857+ivor-juspay@users.noreply.github.com> Date: Wed, 31 Jan 2024 17:09:35 +0530 Subject: [PATCH] chore(connector_events_fields): added refund_id, dispute_id to connector events (#3424) Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com> Co-authored-by: Sampras Lopes --- .../clickhouse/scripts/connector_events.sql | 12 +++++++-- .../analytics/src/connector_events/events.rs | 25 +++++++++++++------ .../src/analytics/connector_events.rs | 11 +++----- .../core/fraud_check/flows/checkout_flow.rs | 2 ++ .../fraud_check/flows/fulfillment_flow.rs | 2 ++ .../core/fraud_check/flows/record_return.rs | 2 ++ .../src/core/fraud_check/flows/sale_flow.rs | 2 ++ .../fraud_check/flows/transaction_flow.rs | 2 ++ crates/router/src/core/mandate/utils.rs | 2 ++ crates/router/src/core/payments/helpers.rs | 2 ++ .../router/src/core/payments/transformers.rs | 2 ++ crates/router/src/core/utils.rs | 14 +++++++++++ crates/router/src/core/webhooks/utils.rs | 2 ++ .../router/src/events/connector_api_logs.rs | 6 +++++ crates/router/src/services/api.rs | 2 ++ crates/router/src/types.rs | 7 ++++++ .../router/src/types/api/verify_connector.rs | 2 ++ crates/router/tests/connectors/aci.rs | 4 +++ crates/router/tests/connectors/utils.rs | 2 ++ 19 files changed, 85 insertions(+), 18 deletions(-) diff --git a/crates/analytics/docs/clickhouse/scripts/connector_events.sql b/crates/analytics/docs/clickhouse/scripts/connector_events.sql index 5821cd035567..4a53f9edb0bf 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 096520777eeb..47044811a8bf 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::(pool) diff --git a/crates/api_models/src/analytics/connector_events.rs b/crates/api_models/src/analytics/connector_events.rs index b2974b0a3392..7d7e4ae2a8bc 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, + pub dispute_id: Option, } 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 7f8993af5270..8b3eed45f9e8 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( 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 bd0ba3e4f7f4..2de6aaab7c73 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( 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 5b05e6015023..1b4b2fc9fc35 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 016d5ec955d2..ef8dddde9554 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 08b490480434..75d37f942798 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 45c05a3077fd..4d3aadc3c456 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, + dispute_id: Option, status_code: u16, } @@ -34,6 +36,8 @@ impl ConnectorEvent { merchant_id: String, request_id: Option<&RequestId>, latency: u128, + refund_id: Option, + dispute_id: Option, 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 4251679d5d39..aec0b9bde9e9 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 531ca849a352..10e13a6af579 100644 --- a/crates/router/src/types.rs +++ b/crates/router/src/types.rs @@ -319,6 +319,9 @@ pub struct RouterData { pub apple_pay_flow: Option, pub frm_metadata: Option, + + pub dispute_id: Option, + pub refund_id: Option, } #[derive(Debug, Clone, serde::Deserialize)] @@ -1467,6 +1470,8 @@ impl From<(&RouterData, 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 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 fbd942305845..c03f492e8b8a 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 c820b7acd6e4..d3f8147fb262 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() -> types::RefundsRouterData { 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 ed3cdbe31b52..844777e2dcab 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, } }