mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-29 17:19:15 +08:00
refactor(euclid): transform enum types to include sub-variants of payment method types (#8909)
This commit is contained in:
@ -21,7 +21,10 @@ use diesel_models::{enums, routing_algorithm};
|
|||||||
use error_stack::ResultExt;
|
use error_stack::ResultExt;
|
||||||
use euclid::{
|
use euclid::{
|
||||||
backend::BackendInput,
|
backend::BackendInput,
|
||||||
frontend::ast::{self},
|
frontend::{
|
||||||
|
ast::{self},
|
||||||
|
dir::{self, transformers::IntoDirValue},
|
||||||
|
},
|
||||||
};
|
};
|
||||||
#[cfg(all(feature = "v1", feature = "dynamic_routing"))]
|
#[cfg(all(feature = "v1", feature = "dynamic_routing"))]
|
||||||
use external_services::grpc_client::dynamic_routing as ir_client;
|
use external_services::grpc_client::dynamic_routing as ir_client;
|
||||||
@ -839,6 +842,17 @@ pub fn convert_backend_input_to_routing_eval(
|
|||||||
"payment_method".to_string(),
|
"payment_method".to_string(),
|
||||||
Some(ValueType::EnumVariant(pm.to_string())),
|
Some(ValueType::EnumVariant(pm.to_string())),
|
||||||
);
|
);
|
||||||
|
if let Some(pmt) = input.payment_method.payment_method_type {
|
||||||
|
match (pmt, pm).into_dir_value() {
|
||||||
|
Ok(dv) => insert_dirvalue_param(&mut params, dv),
|
||||||
|
Err(e) => logger::debug!(
|
||||||
|
?e,
|
||||||
|
?pmt,
|
||||||
|
?pm,
|
||||||
|
"decision_engine_euclid: into_dir_value failed; skipping subset param"
|
||||||
|
),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if let Some(pmt) = input.payment_method.payment_method_type {
|
if let Some(pmt) = input.payment_method.payment_method_type {
|
||||||
params.insert(
|
params.insert(
|
||||||
@ -893,6 +907,110 @@ pub fn convert_backend_input_to_routing_eval(
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// All the independent variants of payment method types, configured via dashboard
|
||||||
|
fn insert_dirvalue_param(params: &mut HashMap<String, Option<ValueType>>, dv: dir::DirValue) {
|
||||||
|
match dv {
|
||||||
|
dir::DirValue::RewardType(v) => {
|
||||||
|
params.insert(
|
||||||
|
"reward".to_string(),
|
||||||
|
Some(ValueType::EnumVariant(v.to_string())),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
dir::DirValue::CardType(v) => {
|
||||||
|
params.insert(
|
||||||
|
"card".to_string(),
|
||||||
|
Some(ValueType::EnumVariant(v.to_string())),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
dir::DirValue::PayLaterType(v) => {
|
||||||
|
params.insert(
|
||||||
|
"pay_later".to_string(),
|
||||||
|
Some(ValueType::EnumVariant(v.to_string())),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
dir::DirValue::WalletType(v) => {
|
||||||
|
params.insert(
|
||||||
|
"wallet".to_string(),
|
||||||
|
Some(ValueType::EnumVariant(v.to_string())),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
dir::DirValue::VoucherType(v) => {
|
||||||
|
params.insert(
|
||||||
|
"voucher".to_string(),
|
||||||
|
Some(ValueType::EnumVariant(v.to_string())),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
dir::DirValue::BankRedirectType(v) => {
|
||||||
|
params.insert(
|
||||||
|
"bank_redirect".to_string(),
|
||||||
|
Some(ValueType::EnumVariant(v.to_string())),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
dir::DirValue::BankDebitType(v) => {
|
||||||
|
params.insert(
|
||||||
|
"bank_debit".to_string(),
|
||||||
|
Some(ValueType::EnumVariant(v.to_string())),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
dir::DirValue::BankTransferType(v) => {
|
||||||
|
params.insert(
|
||||||
|
"bank_transfer".to_string(),
|
||||||
|
Some(ValueType::EnumVariant(v.to_string())),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
dir::DirValue::RealTimePaymentType(v) => {
|
||||||
|
params.insert(
|
||||||
|
"real_time_payment".to_string(),
|
||||||
|
Some(ValueType::EnumVariant(v.to_string())),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
dir::DirValue::UpiType(v) => {
|
||||||
|
params.insert(
|
||||||
|
"upi".to_string(),
|
||||||
|
Some(ValueType::EnumVariant(v.to_string())),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
dir::DirValue::GiftCardType(v) => {
|
||||||
|
params.insert(
|
||||||
|
"gift_card".to_string(),
|
||||||
|
Some(ValueType::EnumVariant(v.to_string())),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
dir::DirValue::CardRedirectType(v) => {
|
||||||
|
params.insert(
|
||||||
|
"card_redirect".to_string(),
|
||||||
|
Some(ValueType::EnumVariant(v.to_string())),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
dir::DirValue::OpenBankingType(v) => {
|
||||||
|
params.insert(
|
||||||
|
"open_banking".to_string(),
|
||||||
|
Some(ValueType::EnumVariant(v.to_string())),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
dir::DirValue::MobilePaymentType(v) => {
|
||||||
|
params.insert(
|
||||||
|
"mobile_payment".to_string(),
|
||||||
|
Some(ValueType::EnumVariant(v.to_string())),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
dir::DirValue::CryptoType(v) => {
|
||||||
|
params.insert(
|
||||||
|
"crypto".to_string(),
|
||||||
|
Some(ValueType::EnumVariant(v.to_string())),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
other => {
|
||||||
|
// all other values can be ignored for now as they don't converge with
|
||||||
|
// payment method type
|
||||||
|
logger::warn!(
|
||||||
|
?other,
|
||||||
|
"decision_engine_euclid: unmapped dir::DirValue; add a mapping here"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, serde::Deserialize)]
|
#[derive(Debug, Clone, serde::Deserialize)]
|
||||||
struct DeErrorResponse {
|
struct DeErrorResponse {
|
||||||
code: String,
|
code: String,
|
||||||
|
|||||||
Reference in New Issue
Block a user