feat(analytics): FRM Analytics (#4880)

Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
Co-authored-by: Abhitator216 <abhishek.kanojia@juspay.in>
Co-authored-by: Abhishek Kanojia <89402434+Abhitator216@users.noreply.github.com>
Co-authored-by: ivor-juspay <138492857+ivor-juspay@users.noreply.github.com>
Co-authored-by: Sampras Lopes <sampras.lopes@juspay.in>
This commit is contained in:
Sandeep Kumar
2024-07-04 12:22:27 +05:30
committed by GitHub
parent 7a1651d26b
commit cc88c0707f
36 changed files with 1629 additions and 78 deletions

View File

@ -36,9 +36,8 @@ pub mod user;
pub mod user_authentication_method;
pub mod user_key_store;
pub mod user_role;
use diesel_models::{
fraud_check::{FraudCheck, FraudCheckNew, FraudCheckUpdate},
fraud_check::{FraudCheck, FraudCheckUpdate},
organization::{Organization, OrganizationNew, OrganizationUpdate},
};
use error_stack::ResultExt;
@ -53,16 +52,23 @@ use hyperswitch_domain_models::payouts::{
use hyperswitch_domain_models::{PayoutAttemptInterface, PayoutsInterface};
use masking::PeekInterface;
use redis_interface::errors::RedisError;
use router_env::logger;
use storage_impl::{errors::StorageError, redis::kv_store::RedisConnInterface, MockDb};
pub use self::kafka_store::KafkaStore;
use self::{fraud_check::FraudCheckInterface, organization::OrganizationInterface};
pub use crate::{
core::errors::{self, ProcessTrackerError},
errors::CustomResult,
services::{
kafka::{KafkaError, KafkaProducer, MQResult},
Store,
},
types::{
domain,
storage::{self},
AccessToken,
},
};
#[derive(PartialEq, Eq)]
@ -259,36 +265,74 @@ impl RequestIdStore for KafkaStore {
impl FraudCheckInterface for KafkaStore {
async fn insert_fraud_check_response(
&self,
new: FraudCheckNew,
new: storage::FraudCheckNew,
) -> CustomResult<FraudCheck, StorageError> {
self.diesel_store.insert_fraud_check_response(new).await
let frm = self.diesel_store.insert_fraud_check_response(new).await?;
if let Err(er) = self
.kafka_producer
.log_fraud_check(&frm, None, self.tenant_id.clone())
.await
{
logger::error!(message = "Failed to log analytics event for fraud check", error_message = ?er);
}
Ok(frm)
}
async fn update_fraud_check_response_with_attempt_id(
&self,
fraud_check: FraudCheck,
fraud_check_update: FraudCheckUpdate,
this: FraudCheck,
fraud_check: FraudCheckUpdate,
) -> CustomResult<FraudCheck, StorageError> {
self.diesel_store
.update_fraud_check_response_with_attempt_id(fraud_check, fraud_check_update)
let frm = self
.diesel_store
.update_fraud_check_response_with_attempt_id(this, fraud_check)
.await?;
if let Err(er) = self
.kafka_producer
.log_fraud_check(&frm, None, self.tenant_id.clone())
.await
{
logger::error!(message="Failed to log analytics event for fraud check {frm:?}", error_message=?er)
}
Ok(frm)
}
async fn find_fraud_check_by_payment_id(
&self,
payment_id: String,
merchant_id: String,
) -> CustomResult<FraudCheck, StorageError> {
self.diesel_store
let frm = self
.diesel_store
.find_fraud_check_by_payment_id(payment_id, merchant_id)
.await?;
if let Err(er) = self
.kafka_producer
.log_fraud_check(&frm, None, self.tenant_id.clone())
.await
{
logger::error!(message="Failed to log analytics event for fraud check {frm:?}", error_message=?er)
}
Ok(frm)
}
async fn find_fraud_check_by_payment_id_if_present(
&self,
payment_id: String,
merchant_id: String,
) -> CustomResult<Option<FraudCheck>, StorageError> {
self.diesel_store
let frm = self
.diesel_store
.find_fraud_check_by_payment_id_if_present(payment_id, merchant_id)
.await
.await?;
if let Some(fraud_check) = frm.clone() {
if let Err(er) = self
.kafka_producer
.log_fraud_check(&fraud_check, None, self.tenant_id.clone())
.await
{
logger::error!(message="Failed to log analytics event for frm {frm:?}", error_message=?er);
}
}
Ok(frm)
}
}