From 43cf2b546b17d24780ab590d425fa433eb0da097 Mon Sep 17 00:00:00 2001 From: Anish Kacham Date: Wed, 6 Nov 2024 18:09:00 +0000 Subject: [PATCH] feat(events): include error_code and error_message in payment reject audit event --- .../src/core/payments/operations/payment_reject.rs | 12 ++++++++---- crates/router/src/events/audit_events.rs | 7 +++++-- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/crates/router/src/core/payments/operations/payment_reject.rs b/crates/router/src/core/payments/operations/payment_reject.rs index 30e86e0a829e..7321200a30ad 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::{ @@ -20,7 +21,6 @@ use crate::{ storage::{self, enums}, }, utils::OptionExt, - events::audit_events::{AuditEvent, AuditEventType}, }; #[derive(Debug, Clone, Copy, router_derive::PaymentOperation)] @@ -265,13 +265,17 @@ impl UpdateTracker, PaymentsCancelRequest> for Payme ) .await .to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?; - + let error_code = payment_data.payment_attempt.error_code; + let error_message = payment_data.payment_attempt.error_message; req_state .event_context - .event(AuditEvent::new(AuditEventType::PaymentReject)) + .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 8f22e4a435b6..e2308f09a556 100644 --- a/crates/router/src/events/audit_events.rs +++ b/crates/router/src/events/audit_events.rs @@ -27,7 +27,10 @@ pub enum AuditEventType { capture_amount: Option, multiple_capture_count: Option, }, - PaymentReject, + PaymentReject { + error_code: Option, + error_message: Option, + }, } #[derive(Debug, Clone, Serialize)] @@ -66,7 +69,7 @@ impl Event for AuditEvent { AuditEventType::RefundSuccess => "refund_success", AuditEventType::RefundFail => "refund_fail", AuditEventType::PaymentCancelled { .. } => "payment_cancelled", - AuditEventType::PaymentReject => "payment_rejected", + AuditEventType::PaymentReject { .. } => "payment_rejected", }; format!( "{event_type}-{}",