From eb0101fa7d617afb226cd024881b53dcd080d129 Mon Sep 17 00:00:00 2001 From: Abhishek Kanojia <89402434+Abhitator216@users.noreply.github.com> Date: Mon, 10 Jun 2024 18:18:27 +0530 Subject: [PATCH] feat(events): Add audit events payment confirm (#4763) Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com> Co-authored-by: Sampras Lopes --- config/development.toml | 2 +- .../core/payments/operations/payment_confirm.rs | 16 +++++++++++++++- crates/router/src/events/audit_events.rs | 16 +++++++++++++--- 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/config/development.toml b/config/development.toml index 95cadf5661..2c6d67e751 100644 --- a/config/development.toml +++ b/config/development.toml @@ -646,4 +646,4 @@ sdk_eligible_payment_methods = "card" enabled = false [multitenancy.tenants] -public = { name = "hyperswitch", base_url = "http://localhost:8080", schema = "public", redis_key_prefix = ""} \ No newline at end of file +public = { name = "hyperswitch", base_url = "http://localhost:8080", schema = "public", redis_key_prefix = ""} diff --git a/crates/router/src/core/payments/operations/payment_confirm.rs b/crates/router/src/core/payments/operations/payment_confirm.rs index ea5f2c0ecb..cff51ed809 100644 --- a/crates/router/src/core/payments/operations/payment_confirm.rs +++ b/crates/router/src/core/payments/operations/payment_confirm.rs @@ -29,6 +29,7 @@ use crate::{ utils as core_utils, }, db::StorageInterface, + events::audit_events::{AuditEvent, AuditEventType}, routes::{app::ReqState, SessionState}, services, types::{ @@ -935,7 +936,7 @@ impl UpdateTracker, api::PaymentsRequest> for Paymen async fn update_trackers<'b>( &'b self, state: &'b SessionState, - _req_state: ReqState, + req_state: ReqState, mut payment_data: PaymentData, customer: Option, storage_scheme: storage_enums::MerchantStorageScheme, @@ -1294,6 +1295,19 @@ impl UpdateTracker, api::PaymentsRequest> for Paymen payment_data.payment_intent = payment_intent; payment_data.payment_attempt = payment_attempt; + let client_src = payment_data.payment_attempt.client_source.clone(); + let client_ver = payment_data.payment_attempt.client_version.clone(); + + let frm_message = payment_data.frm_message.clone(); + req_state + .event_context + .event(AuditEvent::new(AuditEventType::PaymentConfirm { + client_src, + client_ver, + frm_message, + })) + .with(payment_data.to_event()) + .emit(); Ok((Box::new(self), payment_data)) } } diff --git a/crates/router/src/events/audit_events.rs b/crates/router/src/events/audit_events.rs index 0f186e691b..6fc1901865 100644 --- a/crates/router/src/events/audit_events.rs +++ b/crates/router/src/events/audit_events.rs @@ -1,18 +1,27 @@ +use diesel_models::fraud_check::FraudCheck; use events::{Event, EventInfo}; use serde::Serialize; use time::PrimitiveDateTime; - #[derive(Debug, Clone, Serialize)] #[serde(tag = "event_type")] pub enum AuditEventType { - Error { error_message: String }, + Error { + error_message: String, + }, PaymentCreated, ConnectorDecided, ConnectorCalled, RefundCreated, RefundSuccess, RefundFail, - PaymentCancelled { cancellation_reason: Option }, + PaymentConfirm { + client_src: Option, + client_ver: Option, + frm_message: Option, + }, + PaymentCancelled { + cancellation_reason: Option, + }, } #[derive(Debug, Clone, Serialize)] @@ -43,6 +52,7 @@ impl Event for AuditEvent { let event_type = match &self.event_type { AuditEventType::Error { .. } => "error", AuditEventType::PaymentCreated => "payment_created", + AuditEventType::PaymentConfirm { .. } => "payment_confirm", AuditEventType::ConnectorDecided => "connector_decided", AuditEventType::ConnectorCalled => "connector_called", AuditEventType::RefundCreated => "refund_created",