mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-27 19:46:48 +08:00
feat(core): Implement 3ds decision manger for V2 (#7022)
This commit is contained in:
@ -1,82 +1,10 @@
|
||||
use common_utils::events;
|
||||
use euclid::{
|
||||
dssa::types::EuclidAnalysable,
|
||||
enums,
|
||||
frontend::{
|
||||
ast::Program,
|
||||
dir::{DirKeyKind, DirValue, EuclidDirFilter},
|
||||
},
|
||||
types::Metadata,
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(
|
||||
Clone,
|
||||
Debug,
|
||||
Hash,
|
||||
PartialEq,
|
||||
Eq,
|
||||
strum::Display,
|
||||
strum::VariantNames,
|
||||
strum::EnumIter,
|
||||
strum::EnumString,
|
||||
Serialize,
|
||||
Deserialize,
|
||||
)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
#[strum(serialize_all = "snake_case")]
|
||||
pub enum AuthenticationType {
|
||||
ThreeDs,
|
||||
NoThreeDs,
|
||||
}
|
||||
impl AuthenticationType {
|
||||
pub fn to_dir_value(&self) -> DirValue {
|
||||
match self {
|
||||
Self::ThreeDs => DirValue::AuthenticationType(enums::AuthenticationType::ThreeDs),
|
||||
Self::NoThreeDs => DirValue::AuthenticationType(enums::AuthenticationType::NoThreeDs),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl EuclidAnalysable for AuthenticationType {
|
||||
fn get_dir_value_for_analysis(&self, rule_name: String) -> Vec<(DirValue, Metadata)> {
|
||||
let auth = self.to_string();
|
||||
|
||||
vec![(
|
||||
self.to_dir_value(),
|
||||
std::collections::HashMap::from_iter([(
|
||||
"AUTHENTICATION_TYPE".to_string(),
|
||||
serde_json::json!({
|
||||
"rule_name":rule_name,
|
||||
"Authentication_type": auth,
|
||||
}),
|
||||
)]),
|
||||
)]
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Clone, Serialize, Deserialize)]
|
||||
pub struct ConditionalConfigs {
|
||||
pub override_3ds: Option<AuthenticationType>,
|
||||
}
|
||||
impl EuclidDirFilter for ConditionalConfigs {
|
||||
const ALLOWED: &'static [DirKeyKind] = &[
|
||||
DirKeyKind::PaymentMethod,
|
||||
DirKeyKind::CardType,
|
||||
DirKeyKind::CardNetwork,
|
||||
DirKeyKind::MetaData,
|
||||
DirKeyKind::PaymentAmount,
|
||||
DirKeyKind::PaymentCurrency,
|
||||
DirKeyKind::CaptureMethod,
|
||||
DirKeyKind::BillingCountry,
|
||||
DirKeyKind::BusinessCountry,
|
||||
];
|
||||
}
|
||||
use euclid::frontend::ast::Program;
|
||||
|
||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
||||
pub struct DecisionManagerRecord {
|
||||
pub name: String,
|
||||
pub program: Program<ConditionalConfigs>,
|
||||
pub program: Program<common_types::payments::ConditionalConfigs>,
|
||||
pub created_at: i64,
|
||||
pub modified_at: i64,
|
||||
}
|
||||
@ -89,12 +17,14 @@ impl events::ApiEventMetric for DecisionManagerRecord {
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct ConditionalConfigReq {
|
||||
pub name: Option<String>,
|
||||
pub algorithm: Option<Program<ConditionalConfigs>>,
|
||||
pub algorithm: Option<Program<common_types::payments::ConditionalConfigs>>,
|
||||
}
|
||||
|
||||
#[cfg(feature = "v1")]
|
||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
||||
pub struct DecisionManagerRequest {
|
||||
pub name: Option<String>,
|
||||
pub program: Option<Program<ConditionalConfigs>>,
|
||||
pub program: Option<Program<common_types::payments::ConditionalConfigs>>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
||||
@ -111,3 +41,17 @@ impl events::ApiEventMetric for DecisionManager {
|
||||
}
|
||||
|
||||
pub type DecisionManagerResponse = DecisionManagerRecord;
|
||||
|
||||
#[cfg(feature = "v2")]
|
||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
||||
pub struct DecisionManagerRequest {
|
||||
pub name: String,
|
||||
pub program: Program<common_types::payments::ConditionalConfigs>,
|
||||
}
|
||||
|
||||
#[cfg(feature = "v2")]
|
||||
impl events::ApiEventMetric for DecisionManagerRequest {
|
||||
fn get_api_event_type(&self) -> Option<events::ApiEventsType> {
|
||||
Some(events::ApiEventsType::Routing)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user