mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-27 19:46:48 +08:00
feat(router): add three_ds_decision_rule support in routing apis (#8132)
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
7a44626251
commit
9bac41b208
@ -1,10 +1,12 @@
|
||||
use std::fmt::Debug;
|
||||
|
||||
use common_types::three_ds_decision_rule_engine::{ThreeDSDecision, ThreeDSDecisionRule};
|
||||
use common_utils::{
|
||||
errors::{ParsingError, ValidationError},
|
||||
ext_traits::ValueExt,
|
||||
pii,
|
||||
};
|
||||
use euclid::frontend::ast::Program;
|
||||
pub use euclid::{
|
||||
dssa::types::EuclidAnalysable,
|
||||
frontend::{
|
||||
@ -62,6 +64,7 @@ pub struct RoutingConfigRequest {
|
||||
pub algorithm: Option<StaticRoutingAlgorithm>,
|
||||
#[schema(value_type = Option<String>)]
|
||||
pub profile_id: Option<common_utils::id_type::ProfileId>,
|
||||
pub transaction_type: Option<TransactionType>,
|
||||
}
|
||||
|
||||
#[derive(Debug, serde::Serialize, ToSchema)]
|
||||
@ -75,11 +78,18 @@ pub struct ProfileDefaultRoutingConfig {
|
||||
pub struct RoutingRetrieveQuery {
|
||||
pub limit: Option<u16>,
|
||||
pub offset: Option<u8>,
|
||||
pub transaction_type: Option<TransactionType>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
|
||||
pub struct RoutingActivatePayload {
|
||||
pub transaction_type: Option<TransactionType>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
|
||||
pub struct RoutingRetrieveLinkQuery {
|
||||
pub profile_id: Option<common_utils::id_type::ProfileId>,
|
||||
pub transaction_type: Option<TransactionType>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
|
||||
@ -294,6 +304,7 @@ pub enum RoutingAlgorithmKind {
|
||||
VolumeSplit,
|
||||
Advanced,
|
||||
Dynamic,
|
||||
ThreeDsDecisionRule,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
||||
@ -328,7 +339,37 @@ pub enum StaticRoutingAlgorithm {
|
||||
Priority(Vec<RoutableConnectorChoice>),
|
||||
VolumeSplit(Vec<ConnectorVolumeSplit>),
|
||||
#[schema(value_type=ProgramConnectorSelection)]
|
||||
Advanced(ast::Program<ConnectorSelection>),
|
||||
Advanced(Program<ConnectorSelection>),
|
||||
#[schema(value_type=ProgramThreeDsDecisionRule)]
|
||||
ThreeDsDecisionRule(Program<ThreeDSDecisionRule>),
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, ToSchema)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct ProgramThreeDsDecisionRule {
|
||||
pub default_selection: ThreeDSDecisionRule,
|
||||
#[schema(value_type = RuleThreeDsDecisionRule)]
|
||||
pub rules: Vec<ast::Rule<ThreeDSDecisionRule>>,
|
||||
#[schema(value_type = HashMap<String, serde_json::Value>)]
|
||||
pub metadata: std::collections::HashMap<String, serde_json::Value>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize, ToSchema)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct RuleThreeDsDecisionRule {
|
||||
pub name: String,
|
||||
pub connector_selection: ThreeDSDecision,
|
||||
#[schema(value_type = Vec<IfStatement>)]
|
||||
pub statements: Vec<ast::IfStatement>,
|
||||
}
|
||||
|
||||
impl StaticRoutingAlgorithm {
|
||||
pub fn should_validate_connectors_in_routing_config(&self) -> bool {
|
||||
match self {
|
||||
Self::Single(_) | Self::Priority(_) | Self::VolumeSplit(_) | Self::Advanced(_) => true,
|
||||
Self::ThreeDsDecisionRule(_) => false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, ToSchema)]
|
||||
@ -337,7 +378,8 @@ pub enum RoutingAlgorithmSerde {
|
||||
Single(Box<RoutableConnectorChoice>),
|
||||
Priority(Vec<RoutableConnectorChoice>),
|
||||
VolumeSplit(Vec<ConnectorVolumeSplit>),
|
||||
Advanced(ast::Program<ConnectorSelection>),
|
||||
Advanced(Program<ConnectorSelection>),
|
||||
ThreeDsDecisionRule(Program<ThreeDSDecisionRule>),
|
||||
}
|
||||
|
||||
impl TryFrom<RoutingAlgorithmSerde> for StaticRoutingAlgorithm {
|
||||
@ -362,6 +404,7 @@ impl TryFrom<RoutingAlgorithmSerde> for StaticRoutingAlgorithm {
|
||||
RoutingAlgorithmSerde::Priority(i) => Self::Priority(i),
|
||||
RoutingAlgorithmSerde::VolumeSplit(i) => Self::VolumeSplit(i),
|
||||
RoutingAlgorithmSerde::Advanced(i) => Self::Advanced(i),
|
||||
RoutingAlgorithmSerde::ThreeDsDecisionRule(i) => Self::ThreeDsDecisionRule(i),
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -464,6 +507,7 @@ impl StaticRoutingAlgorithm {
|
||||
Self::Priority(_) => RoutingAlgorithmKind::Priority,
|
||||
Self::VolumeSplit(_) => RoutingAlgorithmKind::VolumeSplit,
|
||||
Self::Advanced(_) => RoutingAlgorithmKind::Advanced,
|
||||
Self::ThreeDsDecisionRule(_) => RoutingAlgorithmKind::ThreeDsDecisionRule,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user