mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-27 19:46:48 +08:00
feat(routing): Add api-refs for new decision engine endpoints (#8709)
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
This commit is contained in:
@ -16,17 +16,18 @@ use crate::{
|
||||
payment_methods,
|
||||
};
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct OpenRouterDecideGatewayRequest {
|
||||
pub payment_info: PaymentInfo,
|
||||
#[schema(value_type = String)]
|
||||
pub merchant_id: id_type::ProfileId,
|
||||
pub eligible_gateway_list: Option<Vec<String>>,
|
||||
pub ranking_algorithm: Option<RankingAlgorithm>,
|
||||
pub elimination_enabled: Option<bool>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
|
||||
pub struct DecideGatewayResponse {
|
||||
pub decided_gateway: Option<String>,
|
||||
pub gateway_priority_map: Option<serde_json::Value>,
|
||||
@ -43,7 +44,7 @@ pub struct DecideGatewayResponse {
|
||||
pub gateway_mga_id_map: Option<serde_json::Value>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct PriorityLogicOutput {
|
||||
pub is_enforcement: Option<bool>,
|
||||
@ -54,14 +55,14 @@ pub struct PriorityLogicOutput {
|
||||
pub fallback_logic: Option<PriorityLogicData>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
|
||||
pub struct PriorityLogicData {
|
||||
pub name: Option<String>,
|
||||
pub status: Option<String>,
|
||||
pub failure_reason: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, ToSchema)]
|
||||
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
|
||||
pub enum RankingAlgorithm {
|
||||
SrBasedRouting,
|
||||
@ -69,9 +70,10 @@ pub enum RankingAlgorithm {
|
||||
NtwBasedRouting,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct PaymentInfo {
|
||||
#[schema(value_type = String)]
|
||||
pub payment_id: id_type::PaymentId,
|
||||
pub amount: MinorUnit,
|
||||
pub currency: Currency,
|
||||
@ -189,21 +191,23 @@ pub struct UnifiedError {
|
||||
pub developer_message: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, ToSchema)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct UpdateScorePayload {
|
||||
#[schema(value_type = String)]
|
||||
pub merchant_id: id_type::ProfileId,
|
||||
pub gateway: String,
|
||||
pub status: TxnStatus,
|
||||
#[schema(value_type = String)]
|
||||
pub payment_id: id_type::PaymentId,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
#[derive(Debug, Serialize, Deserialize, Clone, ToSchema)]
|
||||
pub struct UpdateScoreResponse {
|
||||
pub message: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, ToSchema)]
|
||||
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
|
||||
pub enum TxnStatus {
|
||||
Started,
|
||||
|
||||
@ -1444,3 +1444,122 @@ pub enum RoutingResultSource {
|
||||
/// Inbuilt Hyperswitch Routing Engine
|
||||
HyperswitchRouting,
|
||||
}
|
||||
//TODO: temporary change will be refactored afterwards
|
||||
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize, PartialEq, ToSchema)]
|
||||
pub struct RoutingEvaluateRequest {
|
||||
pub created_by: String,
|
||||
#[schema(value_type = Object)]
|
||||
///Parameters that can be used in the routing evaluate request.
|
||||
///eg: {"parameters": {
|
||||
/// "payment_method": {"type": "enum_variant", "value": "card"},
|
||||
/// "payment_method_type": {"type": "enum_variant", "value": "credit"},
|
||||
/// "amount": {"type": "number", "value": 10},
|
||||
/// "currency": {"type": "str_value", "value": "INR"},
|
||||
/// "authentication_type": {"type": "enum_variant", "value": "three_ds"},
|
||||
/// "card_bin": {"type": "str_value", "value": "424242"},
|
||||
/// "capture_method": {"type": "enum_variant", "value": "scheduled"},
|
||||
/// "business_country": {"type": "str_value", "value": "IN"},
|
||||
/// "billing_country": {"type": "str_value", "value": "IN"},
|
||||
/// "business_label": {"type": "str_value", "value": "business_label"},
|
||||
/// "setup_future_usage": {"type": "enum_variant", "value": "off_session"},
|
||||
/// "card_network": {"type": "enum_variant", "value": "visa"},
|
||||
/// "payment_type": {"type": "enum_variant", "value": "recurring_mandate"},
|
||||
/// "mandate_type": {"type": "enum_variant", "value": "single_use"},
|
||||
/// "mandate_acceptance_type": {"type": "enum_variant", "value": "online"},
|
||||
/// "metadata":{"type": "metadata_variant", "value": {"key": "key1", "value": "value1"}}
|
||||
/// }}
|
||||
pub parameters: std::collections::HashMap<String, Option<ValueType>>,
|
||||
pub fallback_output: Vec<DeRoutableConnectorChoice>,
|
||||
}
|
||||
impl common_utils::events::ApiEventMetric for RoutingEvaluateRequest {}
|
||||
|
||||
#[derive(Debug, serde::Serialize, serde::Deserialize, Clone, ToSchema)]
|
||||
pub struct RoutingEvaluateResponse {
|
||||
pub status: String,
|
||||
pub output: serde_json::Value,
|
||||
#[serde(deserialize_with = "deserialize_connector_choices")]
|
||||
pub evaluated_output: Vec<RoutableConnectorChoice>,
|
||||
#[serde(deserialize_with = "deserialize_connector_choices")]
|
||||
pub eligible_connectors: Vec<RoutableConnectorChoice>,
|
||||
}
|
||||
impl common_utils::events::ApiEventMetric for RoutingEvaluateResponse {}
|
||||
|
||||
fn deserialize_connector_choices<'de, D>(
|
||||
deserializer: D,
|
||||
) -> Result<Vec<RoutableConnectorChoice>, D::Error>
|
||||
where
|
||||
D: serde::Deserializer<'de>,
|
||||
{
|
||||
let infos = Vec::<DeRoutableConnectorChoice>::deserialize(deserializer)?;
|
||||
Ok(infos
|
||||
.into_iter()
|
||||
.map(RoutableConnectorChoice::from)
|
||||
.collect())
|
||||
}
|
||||
|
||||
impl From<DeRoutableConnectorChoice> for RoutableConnectorChoice {
|
||||
fn from(choice: DeRoutableConnectorChoice) -> Self {
|
||||
Self {
|
||||
choice_kind: RoutableChoiceKind::FullStruct,
|
||||
connector: choice.gateway_name,
|
||||
merchant_connector_id: choice.gateway_id,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Routable Connector chosen for a payment
|
||||
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, ToSchema)]
|
||||
pub struct DeRoutableConnectorChoice {
|
||||
pub gateway_name: RoutableConnectors,
|
||||
#[schema(value_type = String)]
|
||||
pub gateway_id: Option<common_utils::id_type::MerchantConnectorAccountId>,
|
||||
}
|
||||
/// Represents a value in the DSL
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize, ToSchema)]
|
||||
#[serde(tag = "type", content = "value", rename_all = "snake_case")]
|
||||
pub enum ValueType {
|
||||
/// Represents a number literal
|
||||
Number(u64),
|
||||
/// Represents an enum variant
|
||||
EnumVariant(String),
|
||||
/// Represents a Metadata variant
|
||||
MetadataVariant(MetadataValue),
|
||||
/// Represents a arbitrary String value
|
||||
StrValue(String),
|
||||
/// Represents a global reference, which is a reference to a global variable
|
||||
GlobalRef(String),
|
||||
/// Represents an array of numbers. This is basically used for
|
||||
/// "one of the given numbers" operations
|
||||
/// eg: payment.method.amount = (1, 2, 3)
|
||||
NumberArray(Vec<u64>),
|
||||
/// Similar to NumberArray but for enum variants
|
||||
/// eg: payment.method.cardtype = (debit, credit)
|
||||
EnumVariantArray(Vec<String>),
|
||||
/// Like a number array but can include comparisons. Useful for
|
||||
/// conditions like "500 < amount < 1000"
|
||||
/// eg: payment.amount = (> 500, < 1000)
|
||||
NumberComparisonArray(Vec<NumberComparison>),
|
||||
}
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize, ToSchema)]
|
||||
pub struct MetadataValue {
|
||||
pub key: String,
|
||||
pub value: String,
|
||||
}
|
||||
/// Represents a number comparison for "NumberComparisonArrayValue"
|
||||
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize, ToSchema)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub struct NumberComparison {
|
||||
pub comparison_type: ComparisonType,
|
||||
pub number: u64,
|
||||
}
|
||||
/// Conditional comparison type
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize, ToSchema)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum ComparisonType {
|
||||
Equal,
|
||||
NotEqual,
|
||||
LessThan,
|
||||
LessThanEqual,
|
||||
GreaterThan,
|
||||
GreaterThanEqual,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user