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(events): Add audit events payment capture (#4913)

Sandeep Kumar40a996e84c1d
diff --git a/crates/router/src/core/payments/operations/payment_capture.rs b/crates/router/src/core/payments/operations/payment_capture.rs
index 447f7b9290..02c69681a8 100644
--- a/crates/router/src/core/payments/operations/payment_capture.rs
+++ b/crates/router/src/core/payments/operations/payment_capture.rs
@@ -12,6 +12,7 @@ use crate::{
errors::{self, RouterResult, StorageErrorExt},
payments::{self, helpers, operations, types::MultipleCaptureData},
},
+ events::audit_events::{AuditEvent, AuditEventType},
routes::{app::ReqState, SessionState},
services,
types::{
@@ -255,7 +256,7 @@ impl<F: Clone> UpdateTracker<F, payments::PaymentData<F>, api::PaymentsCaptureRe
async fn update_trackers<'b>(
&'b self,
db: &'b SessionState,
- _req_state: ReqState,
+ req_state: ReqState,
mut payment_data: payments::PaymentData<F>,
_customer: Option<domain::Customer>,
storage_scheme: enums::MerchantStorageScheme,
@@ -294,6 +295,16 @@ impl<F: Clone> UpdateTracker<F, payments::PaymentData<F>, api::PaymentsCaptureRe
} else {
payment_data.payment_attempt
};
+ let capture_amount = payment_data.payment_attempt.amount_to_capture;
+ let multiple_capture_count = payment_data.payment_attempt.multiple_capture_count;
+ req_state
+ .event_context
+ .event(AuditEvent::new(AuditEventType::PaymentCapture {
+ capture_amount,
+ multiple_capture_count,
+ }))
+ .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 6fc1901865..367a573a93 100644
--- a/crates/router/src/events/audit_events.rs
+++ b/crates/router/src/events/audit_events.rs
@@ -1,3 +1,4 @@
+use common_utils::types::MinorUnit;
use diesel_models::fraud_check::FraudCheck;
use events::{Event, EventInfo};
use serde::Serialize;
@@ -22,6 +23,10 @@ pub enum AuditEventType {
PaymentCancelled {
cancellation_reason: Option<String>,
},
+ PaymentCapture {
+ capture_amount: Option<MinorUnit>,
+ multiple_capture_count: Option<i16>,
+ },
}
#[derive(Debug, Clone, Serialize)]
@@ -55,6 +60,7 @@ impl Event for AuditEvent {
AuditEventType::PaymentConfirm { .. } => "payment_confirm",
AuditEventType::ConnectorDecided => "connector_decided",
AuditEventType::ConnectorCalled => "connector_called",
+ AuditEventType::PaymentCapture { .. } => "payment_capture",
AuditEventType::RefundCreated => "refund_created",
AuditEventType::RefundSuccess => "refund_success",
AuditEventType::RefundFail => "refund_fail",
diff --git a/crates/router/src/services/api.rs b/crates/router/src/services/api.rs
index 12da9e6765..baa824ced3 100644
--- a/crates/router/src/services/api.rs
+++ b/crates/router/src/services/api.rs
@@ -958,6 +958,9 @@ where
}
})??
};
+ request_state
+ .event_context
+ .record_info(("tenant_id".to_string(), tenant_id.to_string()));
// let tenant_id = "public".to_string();
let mut session_state =
Arc::new(app_state.clone()).get_session_state(tenant_id.as_str(), || {