Skip to content

Commit

Permalink
feat(payments): Add audit events for PaymentUpdate update (#6426)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rutam21 authored Nov 8, 2024
1 parent 3d9f443 commit 1be2654
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
11 changes: 9 additions & 2 deletions crates/router/src/core/payments/operations/payment_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use crate::{
payments::{self, helpers, operations, CustomerDetails, PaymentAddress, PaymentData},
utils as core_utils,
},
events::audit_events::{AuditEvent, AuditEventType},
routes::{app::ReqState, SessionState},
services,
types::{
Expand Down Expand Up @@ -694,7 +695,7 @@ impl<F: Clone> UpdateTracker<F, PaymentData<F>, api::PaymentsRequest> for Paymen
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: storage_enums::MerchantStorageScheme,
Expand All @@ -714,7 +715,7 @@ impl<F: Clone> UpdateTracker<F, PaymentData<F>, api::PaymentsRequest> for Paymen
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: storage_enums::MerchantStorageScheme,
Expand Down Expand Up @@ -925,6 +926,12 @@ impl<F: Clone> UpdateTracker<F, PaymentData<F>, api::PaymentsRequest> for Paymen
)
.await
.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?;
let amount = payment_data.amount;
req_state
.event_context
.event(AuditEvent::new(AuditEventType::PaymentUpdate { amount }))
.with(payment_data.to_event())
.emit();

Ok((
payments::is_confirm(self, payment_data.confirm),
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
@@ -1,3 +1,4 @@
use api_models::payments::Amount;
use common_utils::types::MinorUnit;
use diesel_models::fraud_check::FraudCheck;
use events::{Event, EventInfo};
Expand Down Expand Up @@ -27,6 +28,9 @@ pub enum AuditEventType {
capture_amount: Option<MinorUnit>,
multiple_capture_count: Option<i16>,
},
PaymentUpdate {
amount: Amount,
},
PaymentApprove,
PaymentCreate,
}
Expand Down Expand Up @@ -67,6 +71,7 @@ impl Event for AuditEvent {
AuditEventType::RefundSuccess => "refund_success",
AuditEventType::RefundFail => "refund_fail",
AuditEventType::PaymentCancelled { .. } => "payment_cancelled",
AuditEventType::PaymentUpdate { .. } => "payment_update",
AuditEventType::PaymentApprove { .. } => "payment_approve",
AuditEventType::PaymentCreate { .. } => "payment_create",
};
Expand Down

0 comments on commit 1be2654

Please sign in to comment.