Skip to content

Commit

Permalink
feat(events): include error_code and error_message in payment reject …
Browse files Browse the repository at this point in the history
…audit event
  • Loading branch information
Anish Kacham committed Nov 6, 2024
1 parent 9c2ae81 commit 43cf2b5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
12 changes: 8 additions & 4 deletions crates/router/src/core/payments/operations/payment_reject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand All @@ -20,7 +21,6 @@ use crate::{
storage::{self, enums},
},
utils::OptionExt,
events::audit_events::{AuditEvent, AuditEventType},
};

#[derive(Debug, Clone, Copy, router_derive::PaymentOperation)]
Expand Down Expand Up @@ -265,13 +265,17 @@ impl<F: Clone> UpdateTracker<F, PaymentData<F>, 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))
}
}
Expand Down
7 changes: 5 additions & 2 deletions crates/router/src/events/audit_events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ pub enum AuditEventType {
capture_amount: Option<MinorUnit>,
multiple_capture_count: Option<i16>,
},
PaymentReject,
PaymentReject {
error_code: Option<String>,
error_message: Option<String>,
},
}

#[derive(Debug, Clone, Serialize)]
Expand Down Expand Up @@ -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}-{}",
Expand Down

0 comments on commit 43cf2b5

Please sign in to comment.