Skip to content

Commit

Permalink
chore(connector_events_fields): added refund_id, dispute_id to connec…
Browse files Browse the repository at this point in the history
…tor events (juspay#3424)

Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
Co-authored-by: Sampras Lopes <[email protected]>
  • Loading branch information
3 people authored Jan 31, 2024
1 parent 7575341 commit 90a2462
Show file tree
Hide file tree
Showing 19 changed files with 85 additions and 18 deletions.
12 changes: 10 additions & 2 deletions crates/analytics/docs/clickhouse/scripts/connector_events.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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
Expand All @@ -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,
Expand All @@ -70,6 +76,8 @@ SELECT
now() as inserted_at,
latency,
method,
refund_id,
dispute_id
FROM
connector_events_queue
where length(_error) = 0;
Expand Down
25 changes: 17 additions & 8 deletions crates/analytics/src/connector_events/events.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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)
Expand Down
11 changes: 3 additions & 8 deletions crates/api_models/src/analytics/connector_events.rs
Original file line number Diff line number Diff line change
@@ -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>,
}
2 changes: 2 additions & 0 deletions crates/router/src/core/fraud_check/flows/checkout_flow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions crates/router/src/core/fraud_check/flows/fulfillment_flow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
2 changes: 2 additions & 0 deletions crates/router/src/core/fraud_check/flows/record_return.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions crates/router/src/core/fraud_check/flows/sale_flow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions crates/router/src/core/fraud_check/flows/transaction_flow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions crates/router/src/core/mandate/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions crates/router/src/core/payments/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}

Expand Down
2 changes: 2 additions & 0 deletions crates/router/src/core/payments/transformers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ where
external_latency: None,
apple_pay_flow,
frm_metadata: None,
refund_id: None,
dispute_id: None,
};

Ok(router_data)
Expand Down
14 changes: 14 additions & 0 deletions crates/router/src/core/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down
2 changes: 2 additions & 0 deletions crates/router/src/core/webhooks/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
6 changes: 6 additions & 0 deletions crates/router/src/events/connector_api_logs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand All @@ -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 {
Expand All @@ -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,
}
}
Expand Down
2 changes: 2 additions & 0 deletions crates/router/src/services/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);

Expand Down
7 changes: 7 additions & 0 deletions crates/router/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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(),
}
}
}
Expand Down Expand Up @@ -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,
}
}
}
2 changes: 2 additions & 0 deletions crates/router/src/types/api/verify_connector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ impl VerifyConnectorData {
external_latency: None,
apple_pay_flow: None,
frm_metadata: None,
refund_id: None,
dispute_id: None,
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions crates/router/tests/connectors/aci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}

Expand Down Expand Up @@ -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,
}
}

Expand Down
2 changes: 2 additions & 0 deletions crates/router/tests/connectors/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,8 @@ pub trait ConnectorActions: Connector {
apple_pay_flow: None,
external_latency: None,
frm_metadata: None,
refund_id: None,
dispute_id: None,
}
}

Expand Down

0 comments on commit 90a2462

Please sign in to comment.