Skip to content

Commit

Permalink
feat(events): Add payment reject audit events (#6465)
Browse files Browse the repository at this point in the history
Co-authored-by: Anish Kacham <f2010091@hyderabad.bits-pilani.ac.in>
  • Loading branch information
2 people authored and Sayak Bhattacharya committed Nov 26, 2024
1 parent 7f71cec commit f88c2fd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
13 changes: 12 additions & 1 deletion 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 Down Expand Up @@ -209,7 +210,7 @@ impl<F: Clone> UpdateTracker<F, PaymentData<F>, PaymentsCancelRequest> for Payme
async fn update_trackers<'b>(
&'b self,
state: &'b SessionState,
_req_state: ReqState,
req_state: ReqState,
mut payment_data: PaymentData<F>,
_customer: Option<domain::Customer>,
storage_scheme: enums::MerchantStorageScheme,
Expand Down Expand Up @@ -264,6 +265,16 @@ 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.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))
}
Expand Down
5 changes: 5 additions & 0 deletions crates/router/src/events/audit_events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ pub enum AuditEventType {
},
PaymentApprove,
PaymentCreate,
PaymentReject {
error_code: Option<String>,
error_message: Option<String>,
},
}

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

0 comments on commit f88c2fd

Please sign in to comment.