Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(events): Add audit events payment confirm #4763

Merged
merged 11 commits into from
Jun 10, 2024
2 changes: 1 addition & 1 deletion config/development.toml
Abhitator216 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -634,4 +634,4 @@ sdk_eligible_payment_methods = "card"
enabled = false

[multitenancy.tenants]
public = { name = "hyperswitch", base_url = "http://localhost:8080", schema = "public", redis_key_prefix = ""}
public = { name = "hyperswitch", base_url = "http://localhost:8080", schema = "public", redis_key_prefix = ""}
16 changes: 15 additions & 1 deletion crates/router/src/core/payments/operations/payment_confirm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ use crate::{
utils as core_utils,
},
db::StorageInterface,
events::audit_events::{AuditEvent, AuditEventType},
routes::{app::ReqState, SessionState},
services,
types::{
Expand Down Expand Up @@ -935,7 +936,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 @@ -1294,6 +1295,19 @@ impl<F: Clone> UpdateTracker<F, PaymentData<F>, api::PaymentsRequest> for Paymen
payment_data.payment_intent = payment_intent;
payment_data.payment_attempt = payment_attempt;

let client_src = payment_data.payment_attempt.client_source.clone();
let client_ver = payment_data.payment_attempt.client_version.clone();

let frm_message = payment_data.frm_message.clone();
req_state
.event_context
.event(AuditEvent::new(AuditEventType::PaymentConfirm {
client_src,
client_ver,
frm_message,
}))
.with(payment_data.to_event())
.emit();
Ok((Box::new(self), payment_data))
}
}
Expand Down
16 changes: 13 additions & 3 deletions crates/router/src/events/audit_events.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,27 @@
use diesel_models::fraud_check::FraudCheck;
use events::{Event, EventInfo};
use serde::Serialize;
use time::PrimitiveDateTime;

#[derive(Debug, Clone, Serialize)]
#[serde(tag = "event_type")]
pub enum AuditEventType {
Error { error_message: String },
Error {
error_message: String,
},
PaymentCreated,
ConnectorDecided,
ConnectorCalled,
RefundCreated,
RefundSuccess,
RefundFail,
PaymentCancelled { cancellation_reason: Option<String> },
PaymentConfirm {
client_src: Option<String>,
client_ver: Option<String>,
frm_message: Option<FraudCheck>,
},
PaymentCancelled {
cancellation_reason: Option<String>,
},
}

#[derive(Debug, Clone, Serialize)]
Expand Down Expand Up @@ -43,6 +52,7 @@ impl Event for AuditEvent {
let event_type = match &self.event_type {
AuditEventType::Error { .. } => "error",
AuditEventType::PaymentCreated => "payment_created",
AuditEventType::PaymentConfirm { .. } => "payment_confirm",
AuditEventType::ConnectorDecided => "connector_decided",
AuditEventType::ConnectorCalled => "connector_called",
AuditEventType::RefundCreated => "refund_created",
Expand Down
Loading