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
Rust adyenbeginner-friendlyfeaturedfinancefintechhacktoberfesthigh-performanceopen-sourceorchestrationpaymentpayment-gatewaypayment-integrationpayment-processingpaymentspayments-platformrestful-apirustsdkstripeworks-with-react
feat: added kafka events for authentication create and update (#4991)
Vrishab Srivatsa10e9121341fe
diff --git a/config/config.example.toml b/config/config.example.tomlindex 9bdf0b8072..8845aed80c 100644--- a/config/config.example.toml+++ b/config/config.example.toml@@ -587,17 +587,18 @@ enabled = true # Switch to enable or disable PayPal onboardsource = "logs" # The event sink to push events supports kafka or logs (stdout)[events.kafka]-brokers = [] # Kafka broker urls for bootstrapping the client-intent_analytics_topic = "topic" # Kafka topic to be used for PaymentIntent events-attempt_analytics_topic = "topic" # Kafka topic to be used for PaymentAttempt events-refund_analytics_topic = "topic" # Kafka topic to be used for Refund events-api_logs_topic = "topic" # Kafka topic to be used for incoming api events-connector_logs_topic = "topic" # Kafka topic to be used for connector api events-outgoing_webhook_logs_topic = "topic" # Kafka topic to be used for outgoing webhook events-dispute_analytics_topic = "topic" # Kafka topic to be used for Dispute events-audit_events_topic = "topic" # Kafka topic to be used for Payment Audit events-payout_analytics_topic = "topic" # Kafka topic to be used for Payouts and PayoutAttempt events-consolidated_events_topic = "topic" # Kafka topic to be used for Consolidated events+brokers = [] # Kafka broker urls for bootstrapping the client+intent_analytics_topic = "topic" # Kafka topic to be used for PaymentIntent events+attempt_analytics_topic = "topic" # Kafka topic to be used for PaymentAttempt events+refund_analytics_topic = "topic" # Kafka topic to be used for Refund events+api_logs_topic = "topic" # Kafka topic to be used for incoming api events+connector_logs_topic = "topic" # Kafka topic to be used for connector api events+outgoing_webhook_logs_topic = "topic" # Kafka topic to be used for outgoing webhook events+dispute_analytics_topic = "topic" # Kafka topic to be used for Dispute events+audit_events_topic = "topic" # Kafka topic to be used for Payment Audit events+payout_analytics_topic = "topic" # Kafka topic to be used for Payouts and PayoutAttempt events+consolidated_events_topic = "topic" # Kafka topic to be used for Consolidated events+authentication_analytics_topic = "topic" # Kafka topic to be used for Authentication events# File storage configuration[file_storage]diff --git a/config/deployments/env_specific.toml b/config/deployments/env_specific.tomlindex ccb26042f5..ebbae551ea 100644--- a/config/deployments/env_specific.toml+++ b/config/deployments/env_specific.toml@@ -71,17 +71,18 @@ sts_role_session_name = "" # An identifier for the assumed role session, used tosource = "logs" # The event sink to push events supports kafka or logs (stdout)[events.kafka]-brokers = [] # Kafka broker urls for bootstrapping the client-intent_analytics_topic = "topic" # Kafka topic to be used for PaymentIntent events-attempt_analytics_topic = "topic" # Kafka topic to be used for PaymentAttempt events-refund_analytics_topic = "topic" # Kafka topic to be used for Refund events-api_logs_topic = "topic" # Kafka topic to be used for incoming api events-connector_logs_topic = "topic" # Kafka topic to be used for connector api events-outgoing_webhook_logs_topic = "topic" # Kafka topic to be used for outgoing webhook events-dispute_analytics_topic = "topic" # Kafka topic to be used for Dispute events-audit_events_topic = "topic" # Kafka topic to be used for Payment Audit events-payout_analytics_topic = "topic" # Kafka topic to be used for Payouts and PayoutAttempt events-consolidated_events_topic = "topic" # Kafka topic to be used for Consolidated events+brokers = [] # Kafka broker urls for bootstrapping the client+intent_analytics_topic = "topic" # Kafka topic to be used for PaymentIntent events+attempt_analytics_topic = "topic" # Kafka topic to be used for PaymentAttempt events+refund_analytics_topic = "topic" # Kafka topic to be used for Refund events+api_logs_topic = "topic" # Kafka topic to be used for incoming api events+connector_logs_topic = "topic" # Kafka topic to be used for connector api events+outgoing_webhook_logs_topic = "topic" # Kafka topic to be used for outgoing webhook events+dispute_analytics_topic = "topic" # Kafka topic to be used for Dispute events+audit_events_topic = "topic" # Kafka topic to be used for Payment Audit events+payout_analytics_topic = "topic" # Kafka topic to be used for Payouts and PayoutAttempt events+consolidated_events_topic = "topic" # Kafka topic to be used for Consolidated events+authentication_analytics_topic = "topic" # Kafka topic to be used for Authentication events# File storage configuration[file_storage]diff --git a/config/development.toml b/config/development.tomlindex 29f693f6bf..58a95994b8 100644--- a/config/development.toml+++ b/config/development.toml@@ -598,6 +598,7 @@ dispute_analytics_topic = "hyperswitch-dispute-events"audit_events_topic = "hyperswitch-audit-events"payout_analytics_topic = "hyperswitch-payout-events"consolidated_events_topic = "hyperswitch-consolidated-events"+authentication_analytics_topic = "hyperswitch-authentication-events"[analytics]source = "sqlx"diff --git a/config/docker_compose.toml b/config/docker_compose.tomlindex 1b0538d1af..ac0c8392d1 100644--- a/config/docker_compose.toml+++ b/config/docker_compose.toml@@ -442,6 +442,7 @@ dispute_analytics_topic = "hyperswitch-dispute-events"audit_events_topic = "hyperswitch-audit-events"payout_analytics_topic = "hyperswitch-payout-events"consolidated_events_topic = "hyperswitch-consolidated-events"+authentication_analytics_topic = "hyperswitch-authentication-events"[analytics]source = "sqlx"diff --git a/crates/analytics/docs/clickhouse/scripts/authentications.sql b/crates/analytics/docs/clickhouse/scripts/authentications.sqlnew file mode 100644index 0000000000..0d540e6494--- /dev/null+++ b/crates/analytics/docs/clickhouse/scripts/authentications.sql@@ -0,0 +1,194 @@+CREATE TABLE authentication_queue (+ `authentication_id` String,+ `merchant_id` String,+ `authentication_connector` LowCardinality(String),+ `connector_authentication_id` Nullable(String),+ `authentication_data` Nullable(String),+ `payment_method_id` Nullable(String),+ `authentication_type` LowCardinality(Nullable(String)),+ `authentication_status` LowCardinality(String),+ `authentication_lifecycle_status` LowCardinality(String),+ `created_at` DateTime64(3),+ `modified_at` DateTime64(3),+ `error_message` Nullable(String),+ `error_code` Nullable(String),+ `connector_metadata` Nullable(String),+ `maximum_supported_version` LowCardinality(Nullable(String)),+ `threeds_server_transaction_id` Nullable(String),+ `cavv` Nullable(String),+ `authentication_flow_type` Nullable(String),+ `message_version` LowCardinality(Nullable(String)),+ `eci` Nullable(String),+ `trans_status` LowCardinality(Nullable(String)),+ `acquirer_bin` Nullable(String),+ `acquirer_merchant_id` Nullable(String),+ `three_ds_method_data` Nullable(String),+ `three_ds_method_url` Nullable(String),+ `acs_url` Nullable(String),+ `challenge_request` Nullable(String),+ `acs_reference_number` Nullable(String),+ `acs_trans_id` Nullable(String),+ `acs_signed_content` Nullable(String),+ `profile_id` String,+ `payment_id` Nullable(String),+ `merchant_connector_id` Nullable(String),+ `ds_trans_id` Nullable(String),+ `directory_server_id` Nullable(String),+ `acquirer_country_code` Nullable(String),+ `sign_flag` Int8+) ENGINE = Kafka SETTINGS kafka_broker_list = 'kafka0:29092',+kafka_topic_list = 'hyperswitch-authentication-events',+kafka_group_name = 'hyper',+kafka_format = 'JSONEachRow',+kafka_handle_error_mode = 'stream';++CREATE TABLE authentications (+ `authentication_id` String,+ `merchant_id` String,+ `authentication_connector` LowCardinality(String),+ `connector_authentication_id` Nullable(String),+ `authentication_data` Nullable(String),+ `payment_method_id` Nullable(String),+ `authentication_type` LowCardinality(Nullable(String)),+ `authentication_status` LowCardinality(String),+ `authentication_lifecycle_status` LowCardinality(String),+ `created_at` DateTime64(3) DEFAULT now64(),+ `inserted_at` DateTime64(3) DEFAULT now64(),+ `modified_at` DateTime64(3) DEFAULT now64(),+ `error_message` Nullable(String),+ `error_code` Nullable(String),+ `connector_metadata` Nullable(String),+ `maximum_supported_version` LowCardinality(Nullable(String)),+ `threeds_server_transaction_id` Nullable(String),+ `cavv` Nullable(String),+ `authentication_flow_type` Nullable(String),+ `message_version` LowCardinality(Nullable(String)),+ `eci` Nullable(String),+ `trans_status` LowCardinality(Nullable(String)),+ `acquirer_bin` Nullable(String),+ `acquirer_merchant_id` Nullable(String),+ `three_ds_method_data` Nullable(String),+ `three_ds_method_url` Nullable(String),+ `acs_url` Nullable(String),+ `challenge_request` Nullable(String),+ `acs_reference_number` Nullable(String),+ `acs_trans_id` Nullable(String),+ `acs_signed_content` Nullable(String),+ `profile_id` String,+ `payment_id` Nullable(String),+ `merchant_connector_id` Nullable(String),+ `ds_trans_id` Nullable(String),+ `directory_server_id` Nullable(String),+ `acquirer_country_code` Nullable(String),+ `sign_flag` Int8,+ INDEX authenticationConnectorIndex authentication_connector TYPE bloom_filter GRANULARITY 1,+ INDEX transStatusIndex trans_status TYPE bloom_filter GRANULARITY 1,+ INDEX authenticationTypeIndex authentication_type TYPE bloom_filter GRANULARITY 1,+ INDEX authenticationStatusIndex authentication_status TYPE bloom_filter GRANULARITY 1+) ENGINE = CollapsingMergeTree(sign_flag) PARTITION BY toStartOfDay(created_at)+ORDER BY+ (created_at, merchant_id, authentication_id) TTL toStartOfDay(created_at) + toIntervalMonth(18) SETTINGS index_granularity = 8192;++CREATE MATERIALIZED VIEW authentication_mv TO authentications (+ `authentication_id` String,+ `merchant_id` String,+ `authentication_connector` LowCardinality(String),+ `connector_authentication_id` Nullable(String),+ `authentication_data` Nullable(String),+ `payment_method_id` Nullable(String),+ `authentication_type` LowCardinality(Nullable(String)),+ `authentication_status` LowCardinality(String),+ `authentication_lifecycle_status` LowCardinality(String),+ `created_at` DateTime64(3) DEFAULT now64(),+ `inserted_at` DateTime64(3) DEFAULT now64(),+ `modified_at` DateTime64(3) DEFAULT now64(),+ `error_message` Nullable(String),+ `error_code` Nullable(String),+ `connector_metadata` Nullable(String),+ `maximum_supported_version` LowCardinality(Nullable(String)),+ `threeds_server_transaction_id` Nullable(String),+ `cavv` Nullable(String),+ `authentication_flow_type` Nullable(String),+ `message_version` LowCardinality(Nullable(String)),+ `eci` Nullable(String),+ `trans_status` LowCardinality(Nullable(String)),+ `acquirer_bin` Nullable(String),+ `acquirer_merchant_id` Nullable(String),+ `three_ds_method_data` Nullable(String),+ `three_ds_method_url` Nullable(String),+ `acs_url` Nullable(String),+ `challenge_request` Nullable(String),+ `acs_reference_number` Nullable(String),+ `acs_trans_id` Nullable(String),+ `acs_signed_content` Nullable(String),+ `profile_id` String,+ `payment_id` Nullable(String),+ `merchant_connector_id` Nullable(String),+ `ds_trans_id` Nullable(String),+ `directory_server_id` Nullable(String),+ `acquirer_country_code` Nullable(String),+ `sign_flag` Int8+) AS+SELECT+ authentication_id,+ merchant_id,+ authentication_connector,+ connector_authentication_id,+ authentication_data,+ payment_method_id,+ authentication_type,+ authentication_status,+ authentication_lifecycle_status,+ created_at,+ now64() as inserted_at,+ modified_at,+ error_message,+ error_code,+ connector_metadata,+ maximum_supported_version,+ threeds_server_transaction_id,+ cavv,+ authentication_flow_type,+ message_version,+ eci,+ trans_status,+ acquirer_bin,+ acquirer_merchant_id,+ three_ds_method_data,+ three_ds_method_url,+ acs_url,+ challenge_request,+ acs_reference_number,+ acs_trans_id,+ acs_signed_content,+ profile_id,+ payment_id,+ merchant_connector_id,+ ds_trans_id,+ directory_server_id,+ acquirer_country_code,+ sign_flag+FROM+ authentication_queue+WHERE+ length(_error) = 0;++CREATE MATERIALIZED VIEW authentication_parse_errors (+ `topic` String,+ `partition` Int64,+ `offset` Int64,+ `raw` String,+ `error` String+) ENGINE = MergeTree+ORDER BY+ (topic, partition, offset) SETTINGS index_granularity = 8192 AS+SELECT+ _topic AS topic,+ _partition AS partition,+ _offset AS offset,+ _raw_message AS raw,+ _error AS error+FROM+ authentication_queue+WHERE+ length(_error) > 0;\ No newline at end of filediff --git a/crates/router/src/db/kafka_store.rs b/crates/router/src/db/kafka_store.rsindex 2964fd78bc..044b17947c 100644--- a/crates/router/src/db/kafka_store.rs+++ b/crates/router/src/db/kafka_store.rs@@ -2751,9 +2751,20 @@ impl AuthenticationInterface for KafkaStore {&self,authentication: storage::AuthenticationNew,) -> CustomResult<storage::Authentication, errors::StorageError> {- self.diesel_store+ let auth = self+ .diesel_store.insert_authentication(authentication)+ .await?;++ if let Err(er) = self+ .kafka_producer+ .log_authentication(&auth, None, self.tenant_id.clone()).await+ {+ logger::error!(message="Failed to log analytics event for authentication {auth:?}", error_message=?er)+ }++ Ok(auth)}async fn find_authentication_by_merchant_id_authentication_id(@@ -2784,12 +2795,23 @@ impl AuthenticationInterface for KafkaStore {previous_state: storage::Authentication,authentication_update: storage::AuthenticationUpdate,) -> CustomResult<storage::Authentication, errors::StorageError> {- self.diesel_store+ let auth = self+ .diesel_store.update_authentication_by_merchant_id_authentication_id(- previous_state,+ previous_state.clone(),authentication_update,)+ .await?;++ if let Err(er) = self+ .kafka_producer+ .log_authentication(&auth, Some(previous_state.clone()), self.tenant_id.clone()).await+ {+ logger::error!(message="Failed to log analytics event for authentication {auth:?}", error_message=?er)+ }++ Ok(auth)}}diff --git a/crates/router/src/events.rs b/crates/router/src/events.rsindex 1af515b8c2..632989c480 100644--- a/crates/router/src/events.rs+++ b/crates/router/src/events.rs@@ -33,6 +33,7 @@ pub enum EventType {#[cfg(feature = "payouts")]Payout,Consolidated,+ Authentication,}#[derive(Debug, Default, Deserialize, Clone)]diff --git a/crates/router/src/services/kafka.rs b/crates/router/src/services/kafka.rsindex 9c38917424..b245eb3fe7 100644--- a/crates/router/src/services/kafka.rs+++ b/crates/router/src/services/kafka.rs@@ -12,6 +12,8 @@ use rdkafka::{#[cfg(feature = "payouts")]pub mod payout;use crate::events::EventType;+mod authentication;+mod authentication_event;mod dispute;mod dispute_event;mod payment_attempt;@@ -20,7 +22,7 @@ mod payment_intent;mod payment_intent_event;mod refund;mod refund_event;-use diesel_models::refund::Refund;+use diesel_models::{authentication::Authentication, refund::Refund};use hyperswitch_domain_models::payments::{payment_attempt::PaymentAttempt, PaymentIntent};use serde::Serialize;use time::{OffsetDateTime, PrimitiveDateTime};@@ -28,6 +30,7 @@ use time::{OffsetDateTime, PrimitiveDateTime};#[cfg(feature = "payouts")]use self::payout::KafkaPayout;use self::{+ authentication::KafkaAuthentication, authentication_event::KafkaAuthenticationEvent,dispute::KafkaDispute, dispute_event::KafkaDisputeEvent, payment_attempt::KafkaPaymentAttempt,payment_attempt_event::KafkaPaymentAttemptEvent, payment_intent::KafkaPaymentIntent,payment_intent_event::KafkaPaymentIntentEvent, refund::KafkaRefund,@@ -147,6 +150,7 @@ pub struct KafkaSettings {#[cfg(feature = "payouts")]payout_analytics_topic: String,consolidated_events_topic: String,+ authentication_analytics_topic: String,}impl KafkaSettings {@@ -225,6 +229,15 @@ impl KafkaSettings {))})?;+ common_utils::fp_utils::when(+ self.authentication_analytics_topic.is_default_or_empty(),+ || {+ Err(ApplicationError::InvalidConfigurationValueError(+ "Kafka Authentication Analytics topic must not be empty".into(),+ ))+ },+ )?;+Ok(())}}@@ -243,6 +256,7 @@ pub struct KafkaProducer {#[cfg(feature = "payouts")]payout_analytics_topic: String,consolidated_events_topic: String,+ authentication_analytics_topic: String,}struct RdKafkaProducer(ThreadedProducer<DefaultProducerContext>);@@ -285,6 +299,7 @@ impl KafkaProducer {#[cfg(feature = "payouts")]payout_analytics_topic: conf.payout_analytics_topic.clone(),consolidated_events_topic: conf.consolidated_events_topic.clone(),+ authentication_analytics_topic: conf.authentication_analytics_topic.clone(),})}@@ -350,6 +365,39 @@ impl KafkaProducer {})}+ pub async fn log_authentication(+ &self,+ authentication: &Authentication,+ old_authentication: Option<Authentication>,+ tenant_id: TenantID,+ ) -> MQResult<()> {+ if let Some(negative_event) = old_authentication {+ self.log_event(&KafkaEvent::old(+ &KafkaAuthentication::from_storage(&negative_event),+ tenant_id.clone(),+ ))+ .attach_printable_lazy(|| {+ format!("Failed to add negative authentication event {negative_event:?}")+ })?;+ };++ self.log_event(&KafkaEvent::new(+ &KafkaAuthentication::from_storage(authentication),+ tenant_id.clone(),+ ))+ .attach_printable_lazy(|| {+ format!("Failed to add positive authentication event {authentication:?}")+ })?;++ self.log_event(&KafkaConsolidatedEvent::new(+ &KafkaAuthenticationEvent::from_storage(authentication),+ tenant_id.clone(),+ ))+ .attach_printable_lazy(|| {+ format!("Failed to add consolidated authentication event {authentication:?}")+ })+ }+pub async fn log_payment_intent(&self,intent: &PaymentIntent,@@ -507,6 +555,7 @@ impl KafkaProducer {#[cfg(feature = "payouts")]EventType::Payout => &self.payout_analytics_topic,EventType::Consolidated => &self.consolidated_events_topic,+ EventType::Authentication => &self.authentication_analytics_topic,}}}diff --git a/crates/router/src/services/kafka/authentication.rs b/crates/router/src/services/kafka/authentication.rsnew file mode 100644index 0000000000..dce648aff6--- /dev/null+++ b/crates/router/src/services/kafka/authentication.rs@@ -0,0 +1,97 @@+use diesel_models::{authentication::Authentication, enums as storage_enums};+use time::OffsetDateTime;++#[derive(serde::Serialize, Debug)]+pub struct KafkaAuthentication<'a> {+ pub authentication_id: &'a String,+ pub merchant_id: &'a String,+ pub authentication_connector: &'a String,+ pub connector_authentication_id: Option<&'a String>,+ pub authentication_data: Option<serde_json::Value>,+ pub payment_method_id: &'a String,+ pub authentication_type: Option<storage_enums::DecoupledAuthenticationType>,+ pub authentication_status: storage_enums::AuthenticationStatus,+ pub authentication_lifecycle_status: storage_enums::AuthenticationLifecycleStatus,+ #[serde(default, with = "time::serde::timestamp::milliseconds")]+ pub created_at: OffsetDateTime,+ #[serde(default, with = "time::serde::timestamp::milliseconds")]+ pub modified_at: OffsetDateTime,+ pub error_message: Option<&'a String>,+ pub error_code: Option<&'a String>,+ pub connector_metadata: Option<serde_json::Value>,+ pub maximum_supported_version: Option<common_utils::types::SemanticVersion>,+ pub threeds_server_transaction_id: Option<&'a String>,+ pub cavv: Option<&'a String>,+ pub authentication_flow_type: Option<&'a String>,+ pub message_version: Option<common_utils::types::SemanticVersion>,+ pub eci: Option<&'a String>,+ pub trans_status: Option<storage_enums::TransactionStatus>,+ pub acquirer_bin: Option<&'a String>,+ pub acquirer_merchant_id: Option<&'a String>,+ pub three_ds_method_data: Option<&'a String>,+ pub three_ds_method_url: Option<&'a String>,+ pub acs_url: Option<&'a String>,+ pub challenge_request: Option<&'a String>,+ pub acs_reference_number: Option<&'a String>,+ pub acs_trans_id: Option<&'a String>,+ pub acs_signed_content: Option<&'a String>,+ pub profile_id: &'a String,+ pub payment_id: Option<&'a String>,+ pub merchant_connector_id: &'a String,+ pub ds_trans_id: Option<&'a String>,+ pub directory_server_id: Option<&'a String>,+ pub acquirer_country_code: Option<&'a String>,+}++impl<'a> KafkaAuthentication<'a> {+ pub fn from_storage(authentication: &'a Authentication) -> Self {+ Self {+ created_at: authentication.created_at.assume_utc(),+ modified_at: authentication.modified_at.assume_utc(),+ authentication_id: &authentication.authentication_id,+ merchant_id: &authentication.merchant_id,+ authentication_status: authentication.authentication_status,+ authentication_connector: &authentication.authentication_connector,+ connector_authentication_id: authentication.connector_authentication_id.as_ref(),+ authentication_data: authentication.authentication_data.clone(),+ payment_method_id: &authentication.payment_method_id,+ authentication_type: authentication.authentication_type,+ authentication_lifecycle_status: authentication.authentication_lifecycle_status,+ error_code: authentication.error_code.as_ref(),+ error_message: authentication.error_message.as_ref(),+ connector_metadata: authentication.connector_metadata.clone(),+ maximum_supported_version: authentication.maximum_supported_version.clone(),+ threeds_server_transaction_id: authentication.threeds_server_transaction_id.as_ref(),+ cavv: authentication.cavv.as_ref(),+ authentication_flow_type: authentication.authentication_flow_type.as_ref(),+ message_version: authentication.message_version.clone(),+ eci: authentication.eci.as_ref(),+ trans_status: authentication.trans_status.clone(),+ acquirer_bin: authentication.acquirer_bin.as_ref(),+ acquirer_merchant_id: authentication.acquirer_merchant_id.as_ref(),+ three_ds_method_data: authentication.three_ds_method_data.as_ref(),+ three_ds_method_url: authentication.three_ds_method_url.as_ref(),+ acs_url: authentication.acs_url.as_ref(),+ challenge_request: authentication.challenge_request.as_ref(),+ acs_reference_number: authentication.acs_reference_number.as_ref(),+ acs_trans_id: authentication.acs_trans_id.as_ref(),+ acs_signed_content: authentication.acs_signed_content.as_ref(),+ profile_id: &authentication.profile_id,+ payment_id: authentication.payment_id.as_ref(),+ merchant_connector_id: &authentication.merchant_connector_id,+ ds_trans_id: authentication.ds_trans_id.as_ref(),+ directory_server_id: authentication.directory_server_id.as_ref(),+ acquirer_country_code: authentication.acquirer_country_code.as_ref(),+ }+ }+}++impl<'a> super::KafkaMessage for KafkaAuthentication<'a> {+ fn key(&self) -> String {+ format!("{}_{}", self.merchant_id, self.authentication_id)+ }++ fn event_type(&self) -> crate::events::EventType {+ crate::events::EventType::Authentication+ }+}diff --git a/crates/router/src/services/kafka/authentication_event.rs b/crates/router/src/services/kafka/authentication_event.rsnew file mode 100644index 0000000000..6dbebe6ca7--- /dev/null+++ b/crates/router/src/services/kafka/authentication_event.rs@@ -0,0 +1,98 @@+use diesel_models::{authentication::Authentication, enums as storage_enums};+use time::OffsetDateTime;++#[serde_with::skip_serializing_none]+#[derive(serde::Serialize, Debug)]+pub struct KafkaAuthenticationEvent<'a> {+ pub authentication_id: &'a String,+ pub merchant_id: &'a String,+ pub authentication_connector: &'a String,+ pub connector_authentication_id: Option<&'a String>,+ pub authentication_data: Option<serde_json::Value>,+ pub payment_method_id: &'a String,+ pub authentication_type: Option<storage_enums::DecoupledAuthenticationType>,+ pub authentication_status: storage_enums::AuthenticationStatus,+ pub authentication_lifecycle_status: storage_enums::AuthenticationLifecycleStatus,+ #[serde(default, with = "time::serde::timestamp::milliseconds")]+ pub created_at: OffsetDateTime,+ #[serde(default, with = "time::serde::timestamp::milliseconds")]+ pub modified_at: OffsetDateTime,+ pub error_message: Option<&'a String>,+ pub error_code: Option<&'a String>,+ pub connector_metadata: Option<serde_json::Value>,+ pub maximum_supported_version: Option<common_utils::types::SemanticVersion>,+ pub threeds_server_transaction_id: Option<&'a String>,+ pub cavv: Option<&'a String>,+ pub authentication_flow_type: Option<&'a String>,+ pub message_version: Option<common_utils::types::SemanticVersion>,+ pub eci: Option<&'a String>,+ pub trans_status: Option<storage_enums::TransactionStatus>,+ pub acquirer_bin: Option<&'a String>,+ pub acquirer_merchant_id: Option<&'a String>,+ pub three_ds_method_data: Option<&'a String>,+ pub three_ds_method_url: Option<&'a String>,+ pub acs_url: Option<&'a String>,+ pub challenge_request: Option<&'a String>,+ pub acs_reference_number: Option<&'a String>,+ pub acs_trans_id: Option<&'a String>,+ pub acs_signed_content: Option<&'a String>,+ pub profile_id: &'a String,+ pub payment_id: Option<&'a String>,+ pub merchant_connector_id: &'a String,+ pub ds_trans_id: Option<&'a String>,+ pub directory_server_id: Option<&'a String>,+ pub acquirer_country_code: Option<&'a String>,+}++impl<'a> KafkaAuthenticationEvent<'a> {+ pub fn from_storage(authentication: &'a Authentication) -> Self {+ Self {+ created_at: authentication.created_at.assume_utc(),+ modified_at: authentication.modified_at.assume_utc(),+ authentication_id: &authentication.authentication_id,+ merchant_id: &authentication.merchant_id,+ authentication_status: authentication.authentication_status,+ authentication_connector: &authentication.authentication_connector,+ connector_authentication_id: authentication.connector_authentication_id.as_ref(),+ authentication_data: authentication.authentication_data.clone(),+ payment_method_id: &authentication.payment_method_id,+ authentication_type: authentication.authentication_type,+ authentication_lifecycle_status: authentication.authentication_lifecycle_status,+ error_code: authentication.error_code.as_ref(),+ error_message: authentication.error_message.as_ref(),+ connector_metadata: authentication.connector_metadata.clone(),+ maximum_supported_version: authentication.maximum_supported_version.clone(),+ threeds_server_transaction_id: authentication.threeds_server_transaction_id.as_ref(),+ cavv: authentication.cavv.as_ref(),+ authentication_flow_type: authentication.authentication_flow_type.as_ref(),+ message_version: authentication.message_version.clone(),+ eci: authentication.eci.as_ref(),+ trans_status: authentication.trans_status.clone(),+ acquirer_bin: authentication.acquirer_bin.as_ref(),+ acquirer_merchant_id: authentication.acquirer_merchant_id.as_ref(),+ three_ds_method_data: authentication.three_ds_method_data.as_ref(),+ three_ds_method_url: authentication.three_ds_method_url.as_ref(),+ acs_url: authentication.acs_url.as_ref(),+ challenge_request: authentication.challenge_request.as_ref(),+ acs_reference_number: authentication.acs_reference_number.as_ref(),+ acs_trans_id: authentication.acs_trans_id.as_ref(),+ acs_signed_content: authentication.acs_signed_content.as_ref(),+ profile_id: &authentication.profile_id,+ payment_id: authentication.payment_id.as_ref(),+ merchant_connector_id: &authentication.merchant_connector_id,+ ds_trans_id: authentication.ds_trans_id.as_ref(),+ directory_server_id: authentication.directory_server_id.as_ref(),+ acquirer_country_code: authentication.acquirer_country_code.as_ref(),+ }+ }+}++impl<'a> super::KafkaMessage for KafkaAuthenticationEvent<'a> {+ fn key(&self) -> String {+ format!("{}_{}", self.merchant_id, self.authentication_id)+ }++ fn event_type(&self) -> crate::events::EventType {+ crate::events::EventType::Authentication+ }+}