diff --git a/crates/router/src/core/payments/operations/payment_reject.rs b/crates/router/src/core/payments/operations/payment_reject.rs index 55b935012758..23531d2342dc 100644 --- a/crates/router/src/core/payments/operations/payment_reject.rs +++ b/crates/router/src/core/payments/operations/payment_reject.rs @@ -12,6 +12,7 @@ use crate::{ errors::{self, RouterResult, StorageErrorExt}, payments::{helpers, operations, PaymentAddress, PaymentData}, }, + events::audit_events::{AuditEvent, AuditEventType}, routes::{app::ReqState, SessionState}, services, types::{ @@ -209,7 +210,7 @@ impl UpdateTracker, PaymentsCancelRequest> for Payme async fn update_trackers<'b>( &'b self, state: &'b SessionState, - _req_state: ReqState, + req_state: ReqState, mut payment_data: PaymentData, _customer: Option, storage_scheme: enums::MerchantStorageScheme, @@ -264,6 +265,16 @@ impl UpdateTracker, PaymentsCancelRequest> for Payme ) .await .to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?; + let error_code = payment_data.payment_attempt.error_code.clone(); + let error_message = payment_data.payment_attempt.error_message.clone(); + req_state + .event_context + .event(AuditEvent::new(AuditEventType::PaymentReject { + error_code, + error_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 a6b0884d21de..5f2ed10bc5f2 100644 --- a/crates/router/src/events/audit_events.rs +++ b/crates/router/src/events/audit_events.rs @@ -33,6 +33,10 @@ pub enum AuditEventType { }, PaymentApprove, PaymentCreate, + PaymentReject { + error_code: Option, + error_message: Option, + }, } #[derive(Debug, Clone, Serialize)] @@ -74,6 +78,7 @@ impl Event for AuditEvent { AuditEventType::PaymentUpdate { .. } => "payment_update", AuditEventType::PaymentApprove { .. } => "payment_approve", AuditEventType::PaymentCreate { .. } => "payment_create", + AuditEventType::PaymentReject { .. } => "payment_rejected", }; format!( "{event_type}-{}",