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 processor_merchant_id and created_by fields to clickhouse tables (#11608)

Apoorv Dixit63409c82ee24
diff --git a/crates/analytics/docs/clickhouse/scripts/authentications.sql b/crates/analytics/docs/clickhouse/scripts/authentications.sql
index 1eddcd03f0..0477e74465 100644
--- a/crates/analytics/docs/clickhouse/scripts/authentications.sql
+++ b/crates/analytics/docs/clickhouse/scripts/authentications.sql
@@ -36,6 +36,8 @@ CREATE TABLE authentication_queue (
`directory_server_id` Nullable(String),
`acquirer_country_code` Nullable(String),
`organization_id` String,
+ `processor_merchant_id` Nullable(String),
+ `created_by` Nullable(String),
`sign_flag` Int8,
`mcc` Nullable(String),
`amount` Nullable(UInt32),
@@ -104,6 +106,8 @@ CREATE TABLE authentications (
`directory_server_id` Nullable(String),
`acquirer_country_code` Nullable(String),
`organization_id` String,
+ `processor_merchant_id` Nullable(String),
+ `created_by` Nullable(String),
`sign_flag` Int8,
`mcc` Nullable(String),
`amount` Nullable(UInt32),
@@ -174,6 +178,8 @@ CREATE MATERIALIZED VIEW authentication_mv TO authentications (
`directory_server_id` Nullable(String),
`acquirer_country_code` Nullable(String),
`organization_id` String,
+ `processor_merchant_id` Nullable(String),
+ `created_by` Nullable(String),
`sign_flag` Int8,
`mcc` Nullable(String),
`amount` Nullable(UInt32),
@@ -237,6 +243,8 @@ SELECT
directory_server_id,
acquirer_country_code,
organization_id,
+ processor_merchant_id,
+ created_by,
sign_flag,
mcc,
amount,
diff --git a/crates/analytics/docs/clickhouse/scripts/disputes.sql b/crates/analytics/docs/clickhouse/scripts/disputes.sql
index 3bd993d31c..d41d3afdfb 100644
--- a/crates/analytics/docs/clickhouse/scripts/disputes.sql
+++ b/crates/analytics/docs/clickhouse/scripts/disputes.sql
@@ -21,6 +21,8 @@ CREATE TABLE dispute_queue (
`profile_id` Nullable(String),
`merchant_connector_id` Nullable(String),
`organization_id` String,
+ `processor_merchant_id` Nullable(String),
+ `created_by` Nullable(String),
`sign_flag` Int8
) ENGINE = Kafka SETTINGS kafka_broker_list = 'kafka0:29092',
kafka_topic_list = 'hyperswitch-dispute-events',
@@ -52,6 +54,8 @@ CREATE TABLE dispute (
`merchant_connector_id` Nullable(String),
`inserted_at` DateTime DEFAULT now() CODEC(T64, LZ4),
`organization_id` String,
+ `processor_merchant_id` Nullable(String),
+ `created_by` Nullable(String),
`sign_flag` Int8,
INDEX connectorIndex connector TYPE bloom_filter GRANULARITY 1,
INDEX disputeStatusIndex dispute_status TYPE bloom_filter GRANULARITY 1,
@@ -83,6 +87,8 @@ CREATE MATERIALIZED VIEW dispute_mv TO dispute (
`profile_id` Nullable(String),
`merchant_connector_id` Nullable(String),
`organization_id` String,
+ `processor_merchant_id` Nullable(String),
+ `created_by` Nullable(String),
`inserted_at` DateTime64(3),
`sign_flag` Int8
) AS
@@ -109,6 +115,8 @@ SELECT
profile_id,
merchant_connector_id,
organization_id,
+ processor_merchant_id,
+ created_by,
now() AS inserted_at,
sign_flag
FROM
diff --git a/crates/analytics/docs/clickhouse/scripts/fraud_check.sql b/crates/analytics/docs/clickhouse/scripts/fraud_check.sql
index 30788a2a0f..fa0ab47b36 100644
--- a/crates/analytics/docs/clickhouse/scripts/fraud_check.sql
+++ b/crates/analytics/docs/clickhouse/scripts/fraud_check.sql
@@ -20,6 +20,8 @@ CREATE TABLE fraud_check_queue (
`modified_at` DateTime CODEC(T64, LZ4),
`last_step` LowCardinality(String),
`payment_capture_method` LowCardinality(String),
+ `processor_merchant_id` Nullable(String),
+ `created_by` Nullable(String),
`sign_flag` Int8
) ENGINE = Kafka SETTINGS kafka_broker_list = 'kafka0:29092',
kafka_topic_list = 'hyperswitch-fraud-check-events',
@@ -49,6 +51,8 @@ CREATE TABLE fraud_check (
`modified_at` DateTime DEFAULT now() CODEC(T64, LZ4),
`last_step` LowCardinality(String),
`payment_capture_method` LowCardinality(String),
+ `processor_merchant_id` Nullable(String),
+ `created_by` Nullable(String),
`sign_flag` Int8,
INDEX frmNameIndex frm_name TYPE bloom_filter GRANULARITY 1,
INDEX frmStatusIndex frm_status TYPE bloom_filter GRANULARITY 1,
@@ -81,6 +85,8 @@ CREATE MATERIALIZED VIEW fraud_check_mv TO fraud_check (
`modified_at` DateTime64(3),
`last_step` LowCardinality(String),
`payment_capture_method` LowCardinality(String),
+ `processor_merchant_id` Nullable(String),
+ `created_by` Nullable(String),
`sign_flag` Int8
) AS
SELECT
@@ -105,6 +111,8 @@ SELECT
modified_at,
last_step,
payment_capture_method,
+ processor_merchant_id,
+ created_by,
sign_flag
FROM
fraud_check_queue
diff --git a/crates/analytics/docs/clickhouse/scripts/payment_attempts.sql b/crates/analytics/docs/clickhouse/scripts/payment_attempts.sql
index 742bbf9825..17f1a22ddb 100644
--- a/crates/analytics/docs/clickhouse/scripts/payment_attempts.sql
+++ b/crates/analytics/docs/clickhouse/scripts/payment_attempts.sql
@@ -48,6 +48,7 @@ CREATE TABLE payment_attempt_queue (
`signature_network` Nullable(String),
`is_issuer_regulated` Nullable(Bool),
`processor_merchant_id` Nullable(String),
+ `created_by` Nullable(String),
`sign_flag` Int8
) ENGINE = Kafka SETTINGS kafka_broker_list = 'kafka0:29092',
kafka_topic_list = 'hyperswitch-payment-attempt-events',
@@ -106,6 +107,7 @@ CREATE TABLE payment_attempts (
`signature_network` Nullable(String),
`is_issuer_regulated` Nullable(Bool),
`processor_merchant_id` Nullable(String),
+ `created_by` Nullable(String),
`sign_flag` Int8,
INDEX connectorIndex connector TYPE bloom_filter GRANULARITY 1,
INDEX paymentMethodIndex payment_method TYPE bloom_filter GRANULARITY 1,
@@ -167,6 +169,7 @@ CREATE MATERIALIZED VIEW payment_attempt_mv TO payment_attempts (
`signature_network` Nullable(String),
`is_issuer_regulated` Nullable(Bool),
`processor_merchant_id` Nullable(String),
+ `created_by` Nullable(String),
`sign_flag` Int8
) AS
SELECT
@@ -220,6 +223,7 @@ SELECT
signature_network,
is_issuer_regulated,
processor_merchant_id,
+ created_by,
sign_flag
FROM
payment_attempt_queue
diff --git a/crates/analytics/docs/clickhouse/scripts/payment_intents.sql b/crates/analytics/docs/clickhouse/scripts/payment_intents.sql
index d71a284f2d..fc0c460b39 100644
--- a/crates/analytics/docs/clickhouse/scripts/payment_intents.sql
+++ b/crates/analytics/docs/clickhouse/scripts/payment_intents.sql
@@ -25,6 +25,7 @@ CREATE TABLE payment_intents_queue
`last_synced` Nullable(DateTime) CODEC(T64, LZ4),
`organization_id` String,
`processor_merchant_id` Nullable(String),
+ `created_by` Nullable(String),
`sign_flag` Int8
) ENGINE = Kafka SETTINGS kafka_broker_list = 'kafka0:29092',
kafka_topic_list = 'hyperswitch-payment-intent-events',
@@ -60,6 +61,7 @@ CREATE TABLE payment_intents
`inserted_at` DateTime DEFAULT now() CODEC(T64, LZ4),
`organization_id` String,
`processor_merchant_id` Nullable(String),
+ `created_by` Nullable(String),
`sign_flag` Int8,
INDEX connectorIndex connector_id TYPE bloom_filter GRANULARITY 1,
INDEX currencyIndex currency TYPE bloom_filter GRANULARITY 1,
@@ -99,6 +101,7 @@ CREATE MATERIALIZED VIEW payment_intents_mv TO payment_intents
`inserted_at` DateTime64(3),
`organization_id` String,
`processor_merchant_id` Nullable(String),
+ `created_by` Nullable(String),
`sign_flag` Int8
) AS
SELECT
@@ -128,5 +131,6 @@ SELECT
now() AS inserted_at,
organization_id,
processor_merchant_id,
+ created_by,
sign_flag
FROM payment_intents_queue;
\ No newline at end of file
diff --git a/crates/analytics/docs/clickhouse/scripts/payouts.sql b/crates/analytics/docs/clickhouse/scripts/payouts.sql
index b7426c2983..1dbb4917c1 100644
--- a/crates/analytics/docs/clickhouse/scripts/payouts.sql
+++ b/crates/analytics/docs/clickhouse/scripts/payouts.sql
@@ -28,6 +28,8 @@ CREATE TABLE payout_queue (
`business_country` LowCardinality(Nullable(String)),
`business_label` Nullable(String),
`merchant_connector_id` Nullable(String),
+ `processor_merchant_id` Nullable(String),
+ `created_by` Nullable(String),
`sign_flag` Int8
) ENGINE = Kafka SETTINGS kafka_broker_list = 'kafka0:29092',
kafka_topic_list = 'hyperswitch-payout-events',
@@ -65,6 +67,8 @@ CREATE TABLE payout (
`business_country` LowCardinality(Nullable(String)),
`business_label` Nullable(String),
`merchant_connector_id` Nullable(String),
+ `processor_merchant_id` Nullable(String),
+ `created_by` Nullable(String),
`inserted_at` DateTime DEFAULT now() CODEC(T64, LZ4),
`sign_flag` Int8,
INDEX payoutTypeIndex payout_type TYPE bloom_filter GRANULARITY 1,
@@ -107,6 +111,8 @@ CREATE MATERIALIZED VIEW payout_mv TO payout (
`business_country` LowCardinality(Nullable(String)),
`business_label` Nullable(String),
`merchant_connector_id` Nullable(String),
+ `processor_merchant_id` Nullable(String),
+ `created_by` Nullable(String),
`inserted_at` DateTime DEFAULT now() CODEC(T64, LZ4),
`sign_flag` Int8,
) AS
@@ -140,6 +146,8 @@ SELECT
business_country,
business_label,
merchant_connector_id,
+ processor_merchant_id,
+ created_by,
now() as inserted_at,
sign_flag
FROM
diff --git a/crates/analytics/docs/clickhouse/scripts/refunds.sql b/crates/analytics/docs/clickhouse/scripts/refunds.sql
index 323caf1adb..297aa368a8 100644
--- a/crates/analytics/docs/clickhouse/scripts/refunds.sql
+++ b/crates/analytics/docs/clickhouse/scripts/refunds.sql
@@ -23,6 +23,8 @@ CREATE TABLE refund_queue (
`modified_at` DateTime,
`organization_id` String,
`profile_id` String,
+ `processor_merchant_id` Nullable(String),
+ `created_by` Nullable(String),
`sign_flag` Int8
) ENGINE = Kafka SETTINGS kafka_broker_list = 'kafka0:29092',
kafka_topic_list = 'hyperswitch-refund-events',
@@ -56,6 +58,8 @@ CREATE TABLE refunds (
`inserted_at` DateTime DEFAULT now() CODEC(T64, LZ4),
`organization_id` String,
`profile_id` String,
+ `processor_merchant_id` Nullable(String),
+ `created_by` Nullable(String),
`sign_flag` Int8,
INDEX connectorIndex connector TYPE bloom_filter GRANULARITY 1,
INDEX refundTypeIndex refund_type TYPE bloom_filter GRANULARITY 1,
@@ -91,6 +95,8 @@ CREATE MATERIALIZED VIEW refund_mv TO refunds (
`inserted_at` DateTime64(3),
`organization_id` String,
`profile_id` String,
+ `processor_merchant_id` Nullable(String),
+ `created_by` Nullable(String),
`sign_flag` Int8
) AS
SELECT
@@ -119,6 +125,8 @@ SELECT
now() AS inserted_at,
organization_id,
profile_id,
+ processor_merchant_id,
+ created_by,
sign_flag
FROM
refund_queue
diff --git a/crates/diesel_models/src/fraud_check.rs b/crates/diesel_models/src/fraud_check.rs
index 7f409b964e..d10531ae36 100644
--- a/crates/diesel_models/src/fraud_check.rs
+++ b/crates/diesel_models/src/fraud_check.rs
@@ -27,6 +27,8 @@ pub struct FraudCheck {
pub modified_at: PrimitiveDateTime,
pub last_step: FraudCheckLastStep,
pub payment_capture_method: Option<storage_enums::CaptureMethod>, // In postFrm, we are updating capture method from automatic to manual. To store the merchant actual capture method, we are storing the actual capture method in payment_capture_method. It will be useful while approving the FRM decision.
+ pub processor_merchant_id: Option<common_utils::id_type::MerchantId>,
+ pub created_by: Option<String>,
}
#[derive(router_derive::Setter, Clone, Debug, Insertable, router_derive::DebugAsDisplay)]
@@ -49,6 +51,8 @@ pub struct FraudCheckNew {
pub modified_at: PrimitiveDateTime,
pub last_step: FraudCheckLastStep,
pub payment_capture_method: Option<storage_enums::CaptureMethod>,
+ pub processor_merchant_id: Option<common_utils::id_type::MerchantId>,
+ pub created_by: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
diff --git a/crates/diesel_models/src/schema.rs b/crates/diesel_models/src/schema.rs
index 52976cd9d3..7013e26d71 100644
--- a/crates/diesel_models/src/schema.rs
+++ b/crates/diesel_models/src/schema.rs
@@ -641,6 +641,10 @@ diesel::table! {
#[max_length = 64]
last_step -> Varchar,
payment_capture_method -> Nullable<CaptureMethod>,
+ #[max_length = 64]
+ processor_merchant_id -> Nullable<Varchar>,
+ #[max_length = 255]
+ created_by -> Nullable<Varchar>,
}
}
diff --git a/crates/diesel_models/src/schema_v2.rs b/crates/diesel_models/src/schema_v2.rs
index 191ab4b83c..600ed9fc5f 100644
--- a/crates/diesel_models/src/schema_v2.rs
+++ b/crates/diesel_models/src/schema_v2.rs
@@ -652,6 +652,10 @@ diesel::table! {
#[max_length = 64]
last_step -> Varchar,
payment_capture_method -> Nullable<CaptureMethod>,
+ #[max_length = 64]
+ processor_merchant_id -> Nullable<Varchar>,
+ #[max_length = 255]
+ created_by -> Nullable<Varchar>,
}
}
diff --git a/crates/router/src/core/fraud_check/operation/fraud_check_post.rs b/crates/router/src/core/fraud_check/operation/fraud_check_post.rs
index ad8e51774a..58cf3f4d28 100644
--- a/crates/router/src/core/fraud_check/operation/fraud_check_post.rs
+++ b/crates/router/src/core/fraud_check/operation/fraud_check_post.rs
@@ -121,6 +121,9 @@ impl GetTracker<PaymentToFrmData> for FraudCheckPost {
frm_id: utils::generate_id(consts::ID_LENGTH, "frm"),
payment_id: payment_data.payment_intent.get_id().to_owned(),
merchant_id: payment_data.merchant_account.get_id().clone(),
+ processor_merchant_id: Some(
+ payment_data.payment_intent.processor_merchant_id.clone(),
+ ),
attempt_id: payment_data.payment_attempt.attempt_id.clone(),
created_at: common_utils::date_time::now(),
frm_name: frm_connector_details.connector_name,
@@ -135,6 +138,7 @@ impl GetTracker<PaymentToFrmData> for FraudCheckPost {
modified_at: common_utils::date_time::now(),
last_step: FraudCheckLastStep::Processing,
payment_capture_method: payment_data.payment_attempt.capture_method,
+ created_by: None,
})
.await
}
diff --git a/crates/router/src/core/fraud_check/operation/fraud_check_pre.rs b/crates/router/src/core/fraud_check/operation/fraud_check_pre.rs
index ec8e21983c..b96d1a6f85 100644
--- a/crates/router/src/core/fraud_check/operation/fraud_check_pre.rs
+++ b/crates/router/src/core/fraud_check/operation/fraud_check_pre.rs
@@ -111,6 +111,9 @@ impl GetTracker<PaymentToFrmData> for FraudCheckPre {
frm_id: Uuid::new_v4().simple().to_string(),
payment_id: payment_data.payment_intent.get_id().to_owned(),
merchant_id: payment_data.merchant_account.get_id().clone(),
+ processor_merchant_id: Some(
+ payment_data.payment_intent.processor_merchant_id.clone(),
+ ),
attempt_id: payment_data.payment_attempt.attempt_id.clone(),
created_at: common_utils::date_time::now(),
frm_name: frm_connector_details.connector_name,
@@ -125,6 +128,7 @@ impl GetTracker<PaymentToFrmData> for FraudCheckPre {
modified_at: common_utils::date_time::now(),
last_step: FraudCheckLastStep::Processing,
payment_capture_method: payment_data.payment_attempt.capture_method,
+ created_by: None,
})
.await
}
diff --git a/crates/router/src/services/kafka/dispute.rs b/crates/router/src/services/kafka/dispute.rs
index 7a30dbf88b..4bc9d5816f 100644
--- a/crates/router/src/services/kafka/dispute.rs
+++ b/crates/router/src/services/kafka/dispute.rs
@@ -1,7 +1,7 @@
use common_utils::{
ext_traits::StringExt,
id_type,
- types::{AmountConvertor, MinorUnit, StringMinorUnitForConnector},
+ types::{AmountConvertor, CreatedBy, MinorUnit, StringMinorUnitForConnector},
};
use diesel_models::enums as storage_enums;
use hyperswitch_masking::Secret;
@@ -39,7 +39,7 @@ pub struct KafkaDispute<'a> {
pub merchant_connector_id: Option<&'a id_type::MerchantConnectorAccountId>,
pub organization_id: &'a id_type::OrganizationId,
pub processor_merchant_id: Option<&'a id_type::MerchantId>,
- pub created_by: Option<&'a String>,
+ pub created_by: Option<CreatedBy>,
}
impl<'a> KafkaDispute<'a> {
@@ -83,7 +83,10 @@ impl<'a> KafkaDispute<'a> {
merchant_connector_id: dispute.merchant_connector_id.as_ref(),
organization_id: &dispute.organization_id,
processor_merchant_id: dispute.processor_merchant_id.as_ref(),
- created_by: dispute.created_by.as_ref(),
+ created_by: dispute
+ .created_by
+ .as_ref()
+ .and_then(|created_by| created_by.parse::<CreatedBy>().ok()),
}
}
}
diff --git a/crates/router/src/services/kafka/dispute_event.rs b/crates/router/src/services/kafka/dispute_event.rs
index 138d82cbe6..11a79ec56c 100644
--- a/crates/router/src/services/kafka/dispute_event.rs
+++ b/crates/router/src/services/kafka/dispute_event.rs
@@ -1,6 +1,6 @@
use common_utils::{
ext_traits::StringExt,
- types::{AmountConvertor, MinorUnit, StringMinorUnitForConnector},
+ types::{AmountConvertor, CreatedBy, MinorUnit, StringMinorUnitForConnector},
};
use diesel_models::enums as storage_enums;
use hyperswitch_masking::Secret;
@@ -38,6 +38,8 @@ pub struct KafkaDisputeEvent<'a> {
pub profile_id: Option<&'a common_utils::id_type::ProfileId>,
pub merchant_connector_id: Option<&'a common_utils::id_type::MerchantConnectorAccountId>,
pub organization_id: &'a common_utils::id_type::OrganizationId,
+ pub processor_merchant_id: Option<&'a common_utils::id_type::MerchantId>,
+ pub created_by: Option<CreatedBy>,
}
impl<'a> KafkaDisputeEvent<'a> {
@@ -80,6 +82,11 @@ impl<'a> KafkaDisputeEvent<'a> {
profile_id: dispute.profile_id.as_ref(),
merchant_connector_id: dispute.merchant_connector_id.as_ref(),
organization_id: &dispute.organization_id,
+ processor_merchant_id: dispute.processor_merchant_id.as_ref(),
+ created_by: dispute
+ .created_by
+ .as_ref()
+ .and_then(|created_by| created_by.parse::<CreatedBy>().ok()),
}
}
}
diff --git a/crates/router/src/services/kafka/fraud_check.rs b/crates/router/src/services/kafka/fraud_check.rs
index 3010f85753..ca270f27cd 100644
--- a/crates/router/src/services/kafka/fraud_check.rs
+++ b/crates/router/src/services/kafka/fraud_check.rs
@@ -1,4 +1,5 @@
// use diesel_models::enums as storage_enums;
+use common_utils::types::CreatedBy;
use diesel_models::{
enums as storage_enums,
enums::{FraudCheckLastStep, FraudCheckStatus, FraudCheckType},
@@ -27,6 +28,8 @@ pub struct KafkaFraudCheck<'a> {
pub modified_at: OffsetDateTime,
pub last_step: FraudCheckLastStep,
pub payment_capture_method: Option<storage_enums::CaptureMethod>, // In postFrm, we are updating capture method from automatic to manual. To store the merchant actual capture method, we are storing the actual capture method in payment_capture_method. It will be useful while approving the FRM decision.
+ pub processor_merchant_id: Option<&'a common_utils::id_type::MerchantId>,
+ pub created_by: Option<CreatedBy>,
}
impl<'a> KafkaFraudCheck<'a> {
@@ -49,6 +52,11 @@ impl<'a> KafkaFraudCheck<'a> {
modified_at: check.modified_at.assume_utc(),
last_step: check.last_step,
payment_capture_method: check.payment_capture_method,
+ processor_merchant_id: check.processor_merchant_id.as_ref(),
+ created_by: check
+ .created_by
+ .as_ref()
+ .and_then(|created_by| created_by.parse::<CreatedBy>().ok()),
}
}
}
diff --git a/crates/router/src/services/kafka/fraud_check_event.rs b/crates/router/src/services/kafka/fraud_check_event.rs
index 1948f27816..483949a092 100644
--- a/crates/router/src/services/kafka/fraud_check_event.rs
+++ b/crates/router/src/services/kafka/fraud_check_event.rs
@@ -1,3 +1,4 @@
+use common_utils::types::CreatedBy;
use diesel_models::{
enums as storage_enums,
enums::{FraudCheckLastStep, FraudCheckStatus, FraudCheckType},
@@ -26,6 +27,8 @@ pub struct KafkaFraudCheckEvent<'a> {
pub modified_at: OffsetDateTime,
pub last_step: FraudCheckLastStep,
pub payment_capture_method: Option<storage_enums::CaptureMethod>, // In postFrm, we are updating capture method from automatic to manual. To store the merchant actual capture method, we are storing the actual capture method in payment_capture_method. It will be useful while approving the FRM decision.
+ pub processor_merchant_id: Option<&'a common_utils::id_type::MerchantId>,
+ pub created_by: Option<CreatedBy>,
}
impl<'a> KafkaFraudCheckEvent<'a> {
@@ -48,6 +51,11 @@ impl<'a> KafkaFraudCheckEvent<'a> {
modified_at: check.modified_at.assume_utc(),
last_step: check.last_step,
payment_capture_method: check.payment_capture_method,
+ processor_merchant_id: check.processor_merchant_id.as_ref(),
+ created_by: check
+ .created_by
+ .as_ref()
+ .and_then(|created_by| created_by.parse::<CreatedBy>().ok()),
}
}
}
diff --git a/crates/router/src/services/kafka/payment_attempt.rs b/crates/router/src/services/kafka/payment_attempt.rs
index dfeb04dfe4..37e7935620 100644
--- a/crates/router/src/services/kafka/payment_attempt.rs
+++ b/crates/router/src/services/kafka/payment_attempt.rs
@@ -74,6 +74,7 @@ pub struct KafkaPaymentAttempt<'a> {
pub signature_network: Option<common_enums::CardNetwork>,
pub is_issuer_regulated: Option<bool>,
pub processor_merchant_id: &'a id_type::MerchantId,
+ pub created_by: Option<&'a common_utils::types::CreatedBy>,
}
#[cfg(feature = "v1")]
@@ -145,6 +146,7 @@ impl<'a> KafkaPaymentAttempt<'a> {
.and_then(|data| data.signature_network.clone()),
is_issuer_regulated: card_payment_method_data.and_then(|data| data.is_regulated),
processor_merchant_id: &attempt.processor_merchant_id,
+ created_by: attempt.created_by.as_ref(),
}
}
}
diff --git a/crates/router/src/services/kafka/payment_attempt_event.rs b/crates/router/src/services/kafka/payment_attempt_event.rs
index 7f24549502..79ac64c751 100644
--- a/crates/router/src/services/kafka/payment_attempt_event.rs
+++ b/crates/router/src/services/kafka/payment_attempt_event.rs
@@ -75,6 +75,7 @@ pub struct KafkaPaymentAttemptEvent<'a> {
pub signature_network: Option<common_enums::CardNetwork>,
pub is_issuer_regulated: Option<bool>,
pub processor_merchant_id: &'a id_type::MerchantId,
+ pub created_by: Option<&'a common_utils::types::CreatedBy>,
}
#[cfg(feature = "v1")]
@@ -146,6 +147,7 @@ impl<'a> KafkaPaymentAttemptEvent<'a> {
.and_then(|data| data.signature_network.clone()),
is_issuer_regulated: card_payment_method_data.and_then(|data| data.is_regulated),
processor_merchant_id: &attempt.processor_merchant_id,
+ created_by: attempt.created_by.as_ref(),
}
}
}
diff --git a/crates/router/src/services/kafka/payment_intent.rs b/crates/router/src/services/kafka/payment_intent.rs
index 8936be94d9..9826a8931b 100644
--- a/crates/router/src/services/kafka/payment_intent.rs
+++ b/crates/router/src/services/kafka/payment_intent.rs
@@ -58,6 +58,7 @@ pub struct KafkaPaymentIntent<'a> {
pub merchant_order_reference_id: Option<&'a String>,
pub organization_id: &'a id_type::OrganizationId,
pub processor_merchant_id: &'a id_type::MerchantId,
+ pub created_by: Option<&'a common_types::CreatedBy>,
#[serde(flatten)]
infra_values: Option<Value>,
}
@@ -105,6 +106,7 @@ impl<'a> KafkaPaymentIntent<'a> {
merchant_order_reference_id: intent.merchant_order_reference_id.as_ref(),
organization_id: &intent.organization_id,
processor_merchant_id: &intent.processor_merchant_id,
+ created_by: intent.created_by.as_ref(),
infra_values,
}
}
diff --git a/crates/router/src/services/kafka/payment_intent_event.rs b/crates/router/src/services/kafka/payment_intent_event.rs
index 66bbb17bb7..77bbe5a893 100644
--- a/crates/router/src/services/kafka/payment_intent_event.rs
+++ b/crates/router/src/services/kafka/payment_intent_event.rs
@@ -59,6 +59,7 @@ pub struct KafkaPaymentIntentEvent<'a> {
pub merchant_order_reference_id: Option<&'a String>,
pub organization_id: &'a id_type::OrganizationId,
pub processor_merchant_id: &'a id_type::MerchantId,
+ pub created_by: Option<&'a common_types::CreatedBy>,
#[serde(flatten)]
pub infra_values: Option<Value>,
}
@@ -196,6 +197,7 @@ impl<'a> KafkaPaymentIntentEvent<'a> {
merchant_order_reference_id: intent.merchant_order_reference_id.as_ref(),
organization_id: &intent.organization_id,
processor_merchant_id: &intent.processor_merchant_id,
+ created_by: intent.created_by.as_ref(),
infra_values: infra_values.clone(),
}
}
diff --git a/crates/router/src/services/kafka/refund.rs b/crates/router/src/services/kafka/refund.rs
index 76ddc7c39c..6c5a2334ba 100644
--- a/crates/router/src/services/kafka/refund.rs
+++ b/crates/router/src/services/kafka/refund.rs
@@ -4,7 +4,7 @@ use common_utils::pii;
use common_utils::types::{self, ChargeRefunds};
use common_utils::{
id_type,
- types::{ConnectorTransactionIdTrait, MinorUnit},
+ types::{ConnectorTransactionIdTrait, CreatedBy, MinorUnit},
};
use diesel_models::{enums as storage_enums, refund::Refund};
use time::OffsetDateTime;
@@ -41,7 +41,7 @@ pub struct KafkaRefund<'a> {
pub profile_id: Option<&'a id_type::ProfileId>,
pub organization_id: &'a id_type::OrganizationId,
pub processor_merchant_id: Option<&'a id_type::MerchantId>,
- pub created_by: Option<&'a String>,
+ pub created_by: Option<CreatedBy>,
}
#[cfg(feature = "v1")]
@@ -73,7 +73,10 @@ impl<'a> KafkaRefund<'a> {
profile_id: refund.profile_id.as_ref(),
organization_id: &refund.organization_id,
processor_merchant_id: refund.processor_merchant_id.as_ref(),
- created_by: refund.created_by.as_ref(),
+ created_by: refund
+ .created_by
+ .as_ref()
+ .and_then(|created_by| created_by.parse::<CreatedBy>().ok()),
}
}
}
@@ -120,7 +123,7 @@ pub struct KafkaRefund<'a> {
pub processor_refund_data: Option<&'a String>,
pub processor_transaction_data: Option<&'a String>,
pub processor_merchant_id: Option<&'a id_type::MerchantId>,
- pub created_by: Option<&'a String>,
+ pub created_by: Option<CreatedBy>,
}
#[cfg(feature = "v2")]
@@ -201,7 +204,9 @@ impl<'a> KafkaRefund<'a> {
processor_refund_data: processor_refund_data.as_ref(),
processor_transaction_data: processor_transaction_data.as_ref(),
processor_merchant_id: processor_merchant_id.as_ref(),
- created_by: created_by.as_ref(),
+ created_by: created_by
+ .as_ref()
+ .and_then(|created_by| created_by.parse::<CreatedBy>().ok()),
}
}
}
diff --git a/crates/router/src/services/kafka/refund_event.rs b/crates/router/src/services/kafka/refund_event.rs
index 5051bf899b..c646b10441 100644
--- a/crates/router/src/services/kafka/refund_event.rs
+++ b/crates/router/src/services/kafka/refund_event.rs
@@ -4,7 +4,7 @@ use common_utils::pii;
use common_utils::types::{self, ChargeRefunds};
use common_utils::{
id_type,
- types::{ConnectorTransactionIdTrait, MinorUnit},
+ types::{ConnectorTransactionIdTrait, CreatedBy, MinorUnit},
};
use diesel_models::{enums as storage_enums, refund::Refund};
use time::OffsetDateTime;
@@ -41,6 +41,8 @@ pub struct KafkaRefundEvent<'a> {
pub refund_error_code: Option<&'a String>,
pub profile_id: Option<&'a id_type::ProfileId>,
pub organization_id: &'a id_type::OrganizationId,
+ pub processor_merchant_id: Option<&'a id_type::MerchantId>,
+ pub created_by: Option<CreatedBy>,
}
#[cfg(feature = "v1")]
@@ -71,6 +73,11 @@ impl<'a> KafkaRefundEvent<'a> {
refund_error_code: refund.refund_error_code.as_ref(),
profile_id: refund.profile_id.as_ref(),
organization_id: &refund.organization_id,
+ processor_merchant_id: refund.processor_merchant_id.as_ref(),
+ created_by: refund
+ .created_by
+ .as_ref()
+ .and_then(|created_by| created_by.parse::<CreatedBy>().ok()),
}
}
}
@@ -117,6 +124,8 @@ pub struct KafkaRefundEvent<'a> {
pub unified_message: Option<&'a String>,
pub processor_refund_data: Option<&'a String>,
pub processor_transaction_data: Option<&'a String>,
+ pub processor_merchant_id: Option<&'a id_type::MerchantId>,
+ pub created_by: Option<CreatedBy>,
}
#[cfg(feature = "v2")]
@@ -196,6 +205,10 @@ impl<'a> KafkaRefundEvent<'a> {
unified_message: unified_message.as_ref(),
processor_refund_data: processor_refund_data.as_ref(),
processor_transaction_data: processor_transaction_data.as_ref(),
+ processor_merchant_id: processor_merchant_id.as_ref(),
+ created_by: created_by
+ .as_ref()
+ .and_then(|created_by| created_by.parse::<CreatedBy>().ok()),
}
}
}
diff --git a/migrations/2026-03-24-000001_add_processor_merchant_id_to_fraud_check/down.sql b/migrations/2026-03-24-000001_add_processor_merchant_id_to_fraud_check/down.sql
new file mode 100644
index 0000000000..85231ae3db
--- /dev/null
+++ b/migrations/2026-03-24-000001_add_processor_merchant_id_to_fraud_check/down.sql
@@ -0,0 +1,3 @@
+-- This file should undo anything in `up.sql`
+ALTER TABLE fraud_check DROP COLUMN IF EXISTS processor_merchant_id;
+ALTER TABLE fraud_check DROP COLUMN IF EXISTS created_by;
diff --git a/migrations/2026-03-24-000001_add_processor_merchant_id_to_fraud_check/up.sql b/migrations/2026-03-24-000001_add_processor_merchant_id_to_fraud_check/up.sql
new file mode 100644
index 0000000000..fc16e6e05a
--- /dev/null
+++ b/migrations/2026-03-24-000001_add_processor_merchant_id_to_fraud_check/up.sql
@@ -0,0 +1,6 @@
+-- Your SQL goes here
+ALTER TABLE fraud_check ADD COLUMN IF NOT EXISTS processor_merchant_id VARCHAR(64);
+ALTER TABLE fraud_check ADD COLUMN IF NOT EXISTS created_by VARCHAR(255);
+
+-- This backfill should be executed after deployment is complete.
+UPDATE fraud_check SET processor_merchant_id = merchant_id WHERE processor_merchant_id IS NULL;