mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-30 01:27:31 +08:00
refactor(graph): refactor the Knowledge Graph to include configs check, while eligibility analysis (#4687)
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
This commit is contained in:
@ -1,3 +1,4 @@
|
||||
pub mod error;
|
||||
pub mod mca;
|
||||
pub mod transformers;
|
||||
pub mod types;
|
||||
|
||||
@ -4,15 +4,138 @@ use api_models::{
|
||||
admin as admin_api, enums as api_enums, payment_methods::RequestPaymentMethodTypes,
|
||||
};
|
||||
use euclid::{
|
||||
dirval,
|
||||
frontend::{ast, dir},
|
||||
types::{NumValue, NumValueRefinement},
|
||||
};
|
||||
use hyperswitch_constraint_graph as cgraph;
|
||||
use strum::IntoEnumIterator;
|
||||
|
||||
use crate::{error::KgraphError, transformers::IntoDirValue};
|
||||
use crate::{error::KgraphError, transformers::IntoDirValue, types as kgraph_types};
|
||||
|
||||
pub const DOMAIN_IDENTIFIER: &str = "payment_methods_enabled_for_merchantconnectoraccount";
|
||||
|
||||
fn get_dir_value_payment_method(
|
||||
from: api_enums::PaymentMethodType,
|
||||
) -> Result<dir::DirValue, KgraphError> {
|
||||
match from {
|
||||
api_enums::PaymentMethodType::Credit => Ok(dirval!(CardType = Credit)),
|
||||
api_enums::PaymentMethodType::Debit => Ok(dirval!(CardType = Debit)),
|
||||
api_enums::PaymentMethodType::Giropay => Ok(dirval!(BankRedirectType = Giropay)),
|
||||
api_enums::PaymentMethodType::Ideal => Ok(dirval!(BankRedirectType = Ideal)),
|
||||
api_enums::PaymentMethodType::Sofort => Ok(dirval!(BankRedirectType = Sofort)),
|
||||
api_enums::PaymentMethodType::Eps => Ok(dirval!(BankRedirectType = Eps)),
|
||||
api_enums::PaymentMethodType::Klarna => Ok(dirval!(PayLaterType = Klarna)),
|
||||
api_enums::PaymentMethodType::Affirm => Ok(dirval!(PayLaterType = Affirm)),
|
||||
api_enums::PaymentMethodType::AfterpayClearpay => {
|
||||
Ok(dirval!(PayLaterType = AfterpayClearpay))
|
||||
}
|
||||
api_enums::PaymentMethodType::GooglePay => Ok(dirval!(WalletType = GooglePay)),
|
||||
api_enums::PaymentMethodType::ApplePay => Ok(dirval!(WalletType = ApplePay)),
|
||||
api_enums::PaymentMethodType::Paypal => Ok(dirval!(WalletType = Paypal)),
|
||||
api_enums::PaymentMethodType::CryptoCurrency => Ok(dirval!(CryptoType = CryptoCurrency)),
|
||||
api_enums::PaymentMethodType::Ach => Ok(dirval!(BankDebitType = Ach)),
|
||||
|
||||
api_enums::PaymentMethodType::Bacs => Ok(dirval!(BankDebitType = Bacs)),
|
||||
|
||||
api_enums::PaymentMethodType::Becs => Ok(dirval!(BankDebitType = Becs)),
|
||||
api_enums::PaymentMethodType::Sepa => Ok(dirval!(BankDebitType = Sepa)),
|
||||
|
||||
api_enums::PaymentMethodType::AliPay => Ok(dirval!(WalletType = AliPay)),
|
||||
api_enums::PaymentMethodType::AliPayHk => Ok(dirval!(WalletType = AliPayHk)),
|
||||
api_enums::PaymentMethodType::BancontactCard => {
|
||||
Ok(dirval!(BankRedirectType = BancontactCard))
|
||||
}
|
||||
api_enums::PaymentMethodType::Blik => Ok(dirval!(BankRedirectType = Blik)),
|
||||
api_enums::PaymentMethodType::MbWay => Ok(dirval!(WalletType = MbWay)),
|
||||
api_enums::PaymentMethodType::MobilePay => Ok(dirval!(WalletType = MobilePay)),
|
||||
api_enums::PaymentMethodType::Cashapp => Ok(dirval!(WalletType = Cashapp)),
|
||||
api_enums::PaymentMethodType::Multibanco => Ok(dirval!(BankTransferType = Multibanco)),
|
||||
api_enums::PaymentMethodType::Pix => Ok(dirval!(BankTransferType = Pix)),
|
||||
api_enums::PaymentMethodType::Pse => Ok(dirval!(BankTransferType = Pse)),
|
||||
api_enums::PaymentMethodType::Interac => Ok(dirval!(BankRedirectType = Interac)),
|
||||
api_enums::PaymentMethodType::OnlineBankingCzechRepublic => {
|
||||
Ok(dirval!(BankRedirectType = OnlineBankingCzechRepublic))
|
||||
}
|
||||
api_enums::PaymentMethodType::OnlineBankingFinland => {
|
||||
Ok(dirval!(BankRedirectType = OnlineBankingFinland))
|
||||
}
|
||||
api_enums::PaymentMethodType::OnlineBankingPoland => {
|
||||
Ok(dirval!(BankRedirectType = OnlineBankingPoland))
|
||||
}
|
||||
api_enums::PaymentMethodType::OnlineBankingSlovakia => {
|
||||
Ok(dirval!(BankRedirectType = OnlineBankingSlovakia))
|
||||
}
|
||||
api_enums::PaymentMethodType::Swish => Ok(dirval!(WalletType = Swish)),
|
||||
api_enums::PaymentMethodType::Trustly => Ok(dirval!(BankRedirectType = Trustly)),
|
||||
api_enums::PaymentMethodType::Bizum => Ok(dirval!(BankRedirectType = Bizum)),
|
||||
|
||||
api_enums::PaymentMethodType::PayBright => Ok(dirval!(PayLaterType = PayBright)),
|
||||
api_enums::PaymentMethodType::Walley => Ok(dirval!(PayLaterType = Walley)),
|
||||
api_enums::PaymentMethodType::Przelewy24 => Ok(dirval!(BankRedirectType = Przelewy24)),
|
||||
api_enums::PaymentMethodType::WeChatPay => Ok(dirval!(WalletType = WeChatPay)),
|
||||
|
||||
api_enums::PaymentMethodType::ClassicReward => Ok(dirval!(RewardType = ClassicReward)),
|
||||
api_enums::PaymentMethodType::Evoucher => Ok(dirval!(RewardType = Evoucher)),
|
||||
api_enums::PaymentMethodType::UpiCollect => Ok(dirval!(UpiType = UpiCollect)),
|
||||
api_enums::PaymentMethodType::SamsungPay => Ok(dirval!(WalletType = SamsungPay)),
|
||||
api_enums::PaymentMethodType::GoPay => Ok(dirval!(WalletType = GoPay)),
|
||||
api_enums::PaymentMethodType::KakaoPay => Ok(dirval!(WalletType = KakaoPay)),
|
||||
api_enums::PaymentMethodType::Twint => Ok(dirval!(WalletType = Twint)),
|
||||
api_enums::PaymentMethodType::Gcash => Ok(dirval!(WalletType = Gcash)),
|
||||
api_enums::PaymentMethodType::Vipps => Ok(dirval!(WalletType = Vipps)),
|
||||
api_enums::PaymentMethodType::Momo => Ok(dirval!(WalletType = Momo)),
|
||||
api_enums::PaymentMethodType::Alma => Ok(dirval!(PayLaterType = Alma)),
|
||||
api_enums::PaymentMethodType::Dana => Ok(dirval!(WalletType = Dana)),
|
||||
api_enums::PaymentMethodType::OnlineBankingFpx => {
|
||||
Ok(dirval!(BankRedirectType = OnlineBankingFpx))
|
||||
}
|
||||
api_enums::PaymentMethodType::OnlineBankingThailand => {
|
||||
Ok(dirval!(BankRedirectType = OnlineBankingThailand))
|
||||
}
|
||||
api_enums::PaymentMethodType::TouchNGo => Ok(dirval!(WalletType = TouchNGo)),
|
||||
api_enums::PaymentMethodType::Atome => Ok(dirval!(PayLaterType = Atome)),
|
||||
api_enums::PaymentMethodType::Boleto => Ok(dirval!(VoucherType = Boleto)),
|
||||
api_enums::PaymentMethodType::Efecty => Ok(dirval!(VoucherType = Efecty)),
|
||||
api_enums::PaymentMethodType::PagoEfectivo => Ok(dirval!(VoucherType = PagoEfectivo)),
|
||||
api_enums::PaymentMethodType::RedCompra => Ok(dirval!(VoucherType = RedCompra)),
|
||||
api_enums::PaymentMethodType::RedPagos => Ok(dirval!(VoucherType = RedPagos)),
|
||||
api_enums::PaymentMethodType::Alfamart => Ok(dirval!(VoucherType = Alfamart)),
|
||||
api_enums::PaymentMethodType::BcaBankTransfer => {
|
||||
Ok(dirval!(BankTransferType = BcaBankTransfer))
|
||||
}
|
||||
api_enums::PaymentMethodType::BniVa => Ok(dirval!(BankTransferType = BniVa)),
|
||||
api_enums::PaymentMethodType::BriVa => Ok(dirval!(BankTransferType = BriVa)),
|
||||
api_enums::PaymentMethodType::CimbVa => Ok(dirval!(BankTransferType = CimbVa)),
|
||||
api_enums::PaymentMethodType::DanamonVa => Ok(dirval!(BankTransferType = DanamonVa)),
|
||||
api_enums::PaymentMethodType::Indomaret => Ok(dirval!(VoucherType = Indomaret)),
|
||||
api_enums::PaymentMethodType::MandiriVa => Ok(dirval!(BankTransferType = MandiriVa)),
|
||||
api_enums::PaymentMethodType::LocalBankTransfer => {
|
||||
Ok(dirval!(BankTransferType = LocalBankTransfer))
|
||||
}
|
||||
api_enums::PaymentMethodType::PermataBankTransfer => {
|
||||
Ok(dirval!(BankTransferType = PermataBankTransfer))
|
||||
}
|
||||
api_enums::PaymentMethodType::PaySafeCard => Ok(dirval!(GiftCardType = PaySafeCard)),
|
||||
api_enums::PaymentMethodType::SevenEleven => Ok(dirval!(VoucherType = SevenEleven)),
|
||||
api_enums::PaymentMethodType::Lawson => Ok(dirval!(VoucherType = Lawson)),
|
||||
api_enums::PaymentMethodType::MiniStop => Ok(dirval!(VoucherType = MiniStop)),
|
||||
api_enums::PaymentMethodType::FamilyMart => Ok(dirval!(VoucherType = FamilyMart)),
|
||||
api_enums::PaymentMethodType::Seicomart => Ok(dirval!(VoucherType = Seicomart)),
|
||||
api_enums::PaymentMethodType::PayEasy => Ok(dirval!(VoucherType = PayEasy)),
|
||||
api_enums::PaymentMethodType::Givex => Ok(dirval!(GiftCardType = Givex)),
|
||||
api_enums::PaymentMethodType::Benefit => Ok(dirval!(CardRedirectType = Benefit)),
|
||||
api_enums::PaymentMethodType::Knet => Ok(dirval!(CardRedirectType = Knet)),
|
||||
api_enums::PaymentMethodType::OpenBankingUk => {
|
||||
Ok(dirval!(BankRedirectType = OpenBankingUk))
|
||||
}
|
||||
api_enums::PaymentMethodType::MomoAtm => Ok(dirval!(CardRedirectType = MomoAtm)),
|
||||
api_enums::PaymentMethodType::Oxxo => Ok(dirval!(VoucherType = Oxxo)),
|
||||
api_enums::PaymentMethodType::CardRedirect => Ok(dirval!(CardRedirectType = CardRedirect)),
|
||||
api_enums::PaymentMethodType::Venmo => Ok(dirval!(WalletType = Venmo)),
|
||||
}
|
||||
}
|
||||
|
||||
fn compile_request_pm_types(
|
||||
builder: &mut cgraph::ConstraintGraphBuilder<'_, dir::DirValue>,
|
||||
pm_types: RequestPaymentMethodTypes,
|
||||
@ -258,16 +381,220 @@ fn compile_payment_method_enabled(
|
||||
Ok(agg_id)
|
||||
}
|
||||
|
||||
macro_rules! collect_global_variants {
|
||||
($parent_enum:ident) => {
|
||||
&mut dir::enums::$parent_enum::iter()
|
||||
.map(dir::DirValue::$parent_enum)
|
||||
.collect::<Vec<_>>()
|
||||
};
|
||||
}
|
||||
fn global_vec_pmt(
|
||||
enabled_pmt: Vec<dir::DirValue>,
|
||||
builder: &mut cgraph::ConstraintGraphBuilder<'_, dir::DirValue>,
|
||||
) -> Vec<cgraph::NodeId> {
|
||||
let mut global_vector: Vec<dir::DirValue> = Vec::new();
|
||||
|
||||
global_vector.append(collect_global_variants!(PayLaterType));
|
||||
global_vector.append(collect_global_variants!(WalletType));
|
||||
global_vector.append(collect_global_variants!(BankRedirectType));
|
||||
global_vector.append(collect_global_variants!(BankDebitType));
|
||||
global_vector.append(collect_global_variants!(CryptoType));
|
||||
global_vector.append(collect_global_variants!(RewardType));
|
||||
global_vector.append(collect_global_variants!(UpiType));
|
||||
global_vector.append(collect_global_variants!(VoucherType));
|
||||
global_vector.append(collect_global_variants!(GiftCardType));
|
||||
global_vector.append(collect_global_variants!(BankTransferType));
|
||||
global_vector.append(collect_global_variants!(CardRedirectType));
|
||||
global_vector.push(dir::DirValue::PaymentMethod(
|
||||
dir::enums::PaymentMethod::Card,
|
||||
));
|
||||
let global_vector = global_vector
|
||||
.into_iter()
|
||||
.filter(|global_value| !enabled_pmt.contains(global_value))
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
global_vector
|
||||
.into_iter()
|
||||
.map(|dir_v| {
|
||||
builder.make_value_node(
|
||||
cgraph::NodeValue::Value(dir_v),
|
||||
Some("Payment Method Type"),
|
||||
None::<()>,
|
||||
)
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
}
|
||||
|
||||
fn compile_graph_for_countries_and_currencies(
|
||||
builder: &mut cgraph::ConstraintGraphBuilder<'_, dir::DirValue>,
|
||||
config: &kgraph_types::CurrencyCountryFlowFilter,
|
||||
payment_method_type_node: cgraph::NodeId,
|
||||
) -> Result<cgraph::NodeId, KgraphError> {
|
||||
let mut agg_nodes: Vec<(cgraph::NodeId, cgraph::Relation, cgraph::Strength)> = Vec::new();
|
||||
agg_nodes.push((
|
||||
payment_method_type_node,
|
||||
cgraph::Relation::Positive,
|
||||
cgraph::Strength::Normal,
|
||||
));
|
||||
if let Some(country) = config.country.clone() {
|
||||
let node_country = country
|
||||
.into_iter()
|
||||
.map(|country| dir::DirValue::BillingCountry(api_enums::Country::from_alpha2(country)))
|
||||
.collect();
|
||||
let country_agg = builder
|
||||
.make_in_aggregator(node_country, Some("Configs for Country"), None::<()>)
|
||||
.map_err(KgraphError::GraphConstructionError)?;
|
||||
agg_nodes.push((
|
||||
country_agg,
|
||||
cgraph::Relation::Positive,
|
||||
cgraph::Strength::Weak,
|
||||
))
|
||||
}
|
||||
|
||||
if let Some(currency) = config.currency.clone() {
|
||||
let node_currency = currency
|
||||
.into_iter()
|
||||
.map(IntoDirValue::into_dir_value)
|
||||
.collect::<Result<Vec<_>, _>>()?;
|
||||
let currency_agg = builder
|
||||
.make_in_aggregator(node_currency, Some("Configs for Currency"), None::<()>)
|
||||
.map_err(KgraphError::GraphConstructionError)?;
|
||||
agg_nodes.push((
|
||||
currency_agg,
|
||||
cgraph::Relation::Positive,
|
||||
cgraph::Strength::Normal,
|
||||
))
|
||||
}
|
||||
if let Some(capture_method) = config
|
||||
.not_available_flows
|
||||
.and_then(|naf| naf.capture_method)
|
||||
{
|
||||
let make_capture_node = builder.make_value_node(
|
||||
cgraph::NodeValue::Value(dir::DirValue::CaptureMethod(capture_method)),
|
||||
Some("Configs for CaptureMethod"),
|
||||
None::<()>,
|
||||
);
|
||||
agg_nodes.push((
|
||||
make_capture_node,
|
||||
cgraph::Relation::Negative,
|
||||
cgraph::Strength::Normal,
|
||||
))
|
||||
}
|
||||
|
||||
builder
|
||||
.make_all_aggregator(
|
||||
&agg_nodes,
|
||||
Some("Country & Currency Configs With Payment Method Type"),
|
||||
None::<()>,
|
||||
None,
|
||||
)
|
||||
.map_err(KgraphError::GraphConstructionError)
|
||||
}
|
||||
|
||||
fn compile_config_graph(
|
||||
builder: &mut cgraph::ConstraintGraphBuilder<'_, dir::DirValue>,
|
||||
config: &kgraph_types::CountryCurrencyFilter,
|
||||
connector: &api_enums::RoutableConnectors,
|
||||
) -> Result<cgraph::NodeId, KgraphError> {
|
||||
let mut agg_node_id: Vec<(cgraph::NodeId, cgraph::Relation, cgraph::Strength)> = Vec::new();
|
||||
let mut pmt_enabled: Vec<dir::DirValue> = Vec::new();
|
||||
if let Some(pmt) = config
|
||||
.connector_configs
|
||||
.get(connector)
|
||||
.or(config.default_configs.as_ref())
|
||||
.map(|inner| inner.0.clone())
|
||||
{
|
||||
for pm_filter_key in pmt {
|
||||
match pm_filter_key {
|
||||
(kgraph_types::PaymentMethodFilterKey::PaymentMethodType(pm), filter) => {
|
||||
let dir_val_pm = get_dir_value_payment_method(pm)?;
|
||||
|
||||
let pm_node = if pm == api_enums::PaymentMethodType::Credit
|
||||
|| pm == api_enums::PaymentMethodType::Debit
|
||||
{
|
||||
pmt_enabled
|
||||
.push(dir::DirValue::PaymentMethod(api_enums::PaymentMethod::Card));
|
||||
builder.make_value_node(
|
||||
cgraph::NodeValue::Value(dir::DirValue::PaymentMethod(
|
||||
dir::enums::PaymentMethod::Card,
|
||||
)),
|
||||
Some("PaymentMethod"),
|
||||
None::<()>,
|
||||
)
|
||||
} else {
|
||||
pmt_enabled.push(dir_val_pm.clone());
|
||||
builder.make_value_node(
|
||||
cgraph::NodeValue::Value(dir_val_pm),
|
||||
Some("PaymentMethodType"),
|
||||
None::<()>,
|
||||
)
|
||||
};
|
||||
|
||||
let node_config =
|
||||
compile_graph_for_countries_and_currencies(builder, &filter, pm_node)?;
|
||||
|
||||
agg_node_id.push((
|
||||
node_config,
|
||||
cgraph::Relation::Positive,
|
||||
cgraph::Strength::Normal,
|
||||
));
|
||||
}
|
||||
(kgraph_types::PaymentMethodFilterKey::CardNetwork(cn), filter) => {
|
||||
let dir_val_cn = cn.clone().into_dir_value()?;
|
||||
pmt_enabled.push(dir_val_cn);
|
||||
let cn_node = builder.make_value_node(
|
||||
cn.clone().into_dir_value().map(Into::into)?,
|
||||
Some("CardNetwork"),
|
||||
None::<()>,
|
||||
);
|
||||
let node_config =
|
||||
compile_graph_for_countries_and_currencies(builder, &filter, cn_node)?;
|
||||
|
||||
agg_node_id.push((
|
||||
node_config,
|
||||
cgraph::Relation::Positive,
|
||||
cgraph::Strength::Normal,
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
let global_vector_pmt: Vec<cgraph::NodeId> = global_vec_pmt(pmt_enabled, builder);
|
||||
let any_agg_pmt: Vec<(cgraph::NodeId, cgraph::Relation, cgraph::Strength)> = global_vector_pmt
|
||||
.into_iter()
|
||||
.map(|node| (node, cgraph::Relation::Positive, cgraph::Strength::Normal))
|
||||
.collect::<Vec<_>>();
|
||||
let any_agg_node = builder
|
||||
.make_any_aggregator(
|
||||
&any_agg_pmt,
|
||||
Some("Any Aggregator For Payment Method Types"),
|
||||
None::<()>,
|
||||
None,
|
||||
)
|
||||
.map_err(KgraphError::GraphConstructionError)?;
|
||||
|
||||
agg_node_id.push((
|
||||
any_agg_node,
|
||||
cgraph::Relation::Positive,
|
||||
cgraph::Strength::Normal,
|
||||
));
|
||||
|
||||
builder
|
||||
.make_any_aggregator(&agg_node_id, Some("Configs"), None::<()>, None)
|
||||
.map_err(KgraphError::GraphConstructionError)
|
||||
}
|
||||
|
||||
fn compile_merchant_connector_graph(
|
||||
builder: &mut cgraph::ConstraintGraphBuilder<'_, dir::DirValue>,
|
||||
mca: admin_api::MerchantConnectorResponse,
|
||||
config: &kgraph_types::CountryCurrencyFilter,
|
||||
) -> Result<(), KgraphError> {
|
||||
let connector = common_enums::RoutableConnectors::from_str(&mca.connector_name)
|
||||
.map_err(|_| KgraphError::InvalidConnectorName(mca.connector_name.clone()))?;
|
||||
|
||||
let mut agg_nodes: Vec<(cgraph::NodeId, cgraph::Relation, cgraph::Strength)> = Vec::new();
|
||||
|
||||
if let Some(pms_enabled) = mca.payment_methods_enabled {
|
||||
if let Some(pms_enabled) = mca.payment_methods_enabled.clone() {
|
||||
for pm_enabled in pms_enabled {
|
||||
let maybe_pm_enabled_id = compile_payment_method_enabled(builder, pm_enabled)?;
|
||||
if let Some(pm_enabled_id) = maybe_pm_enabled_id {
|
||||
@ -285,10 +612,33 @@ fn compile_merchant_connector_graph(
|
||||
.make_any_aggregator(&agg_nodes, Some(aggregator_info), None::<()>, None)
|
||||
.map_err(KgraphError::GraphConstructionError)?;
|
||||
|
||||
let config_info = "Config for respective PaymentMethodType for the connector";
|
||||
|
||||
let config_enabled_agg_id = compile_config_graph(builder, config, &connector)?;
|
||||
|
||||
let domain_level_node_id = builder
|
||||
.make_all_aggregator(
|
||||
&[
|
||||
(
|
||||
config_enabled_agg_id,
|
||||
cgraph::Relation::Positive,
|
||||
cgraph::Strength::Normal,
|
||||
),
|
||||
(
|
||||
pms_enabled_agg_id,
|
||||
cgraph::Relation::Positive,
|
||||
cgraph::Strength::Normal,
|
||||
),
|
||||
],
|
||||
Some(config_info),
|
||||
None::<()>,
|
||||
None,
|
||||
)
|
||||
.map_err(KgraphError::GraphConstructionError)?;
|
||||
let connector_dir_val = dir::DirValue::Connector(Box::new(ast::ConnectorChoice {
|
||||
connector,
|
||||
#[cfg(not(feature = "connector_choice_mca_id"))]
|
||||
sub_label: mca.business_sub_label,
|
||||
sub_label: mca.business_sub_label.clone(),
|
||||
}));
|
||||
|
||||
let connector_info = "Connector";
|
||||
@ -297,7 +647,7 @@ fn compile_merchant_connector_graph(
|
||||
|
||||
builder
|
||||
.make_edge(
|
||||
pms_enabled_agg_id,
|
||||
domain_level_node_id,
|
||||
connector_node_id,
|
||||
cgraph::Strength::Normal,
|
||||
cgraph::Relation::Positive,
|
||||
@ -310,6 +660,7 @@ fn compile_merchant_connector_graph(
|
||||
|
||||
pub fn make_mca_graph<'a>(
|
||||
accts: Vec<admin_api::MerchantConnectorResponse>,
|
||||
config: &kgraph_types::CountryCurrencyFilter,
|
||||
) -> Result<cgraph::ConstraintGraph<'a, dir::DirValue>, KgraphError> {
|
||||
let mut builder = cgraph::ConstraintGraphBuilder::new();
|
||||
let _domain = builder.make_domain(
|
||||
@ -317,7 +668,7 @@ pub fn make_mca_graph<'a>(
|
||||
"Payment methods enabled for MerchantConnectorAccount",
|
||||
);
|
||||
for acct in accts {
|
||||
compile_merchant_connector_graph(&mut builder, acct)?;
|
||||
compile_merchant_connector_graph(&mut builder, acct, config)?;
|
||||
}
|
||||
|
||||
Ok(builder.build())
|
||||
@ -327,6 +678,8 @@ pub fn make_mca_graph<'a>(
|
||||
mod tests {
|
||||
#![allow(clippy::expect_used)]
|
||||
|
||||
use std::collections::{HashMap, HashSet};
|
||||
|
||||
use api_models::enums as api_enums;
|
||||
use euclid::{
|
||||
dirval,
|
||||
@ -335,6 +688,7 @@ mod tests {
|
||||
use hyperswitch_constraint_graph::{ConstraintGraph, CycleCheck, Memoization};
|
||||
|
||||
use super::*;
|
||||
use crate::types as kgraph_types;
|
||||
|
||||
fn build_test_data<'a>() -> ConstraintGraph<'a, dir::DirValue> {
|
||||
use api_models::{admin::*, payment_methods::*};
|
||||
@ -398,7 +752,36 @@ mod tests {
|
||||
status: api_enums::ConnectorStatus::Inactive,
|
||||
};
|
||||
|
||||
make_mca_graph(vec![stripe_account]).expect("Failed graph construction")
|
||||
let currency_country_flow_filter = kgraph_types::CurrencyCountryFlowFilter {
|
||||
currency: Some(HashSet::from([api_enums::Currency::INR])),
|
||||
country: Some(HashSet::from([api_enums::CountryAlpha2::IN])),
|
||||
not_available_flows: Some(kgraph_types::NotAvailableFlows {
|
||||
capture_method: Some(api_enums::CaptureMethod::Manual),
|
||||
}),
|
||||
};
|
||||
|
||||
let config_map = kgraph_types::CountryCurrencyFilter {
|
||||
connector_configs: HashMap::from([(
|
||||
api_enums::RoutableConnectors::Stripe,
|
||||
kgraph_types::PaymentMethodFilters(HashMap::from([
|
||||
(
|
||||
kgraph_types::PaymentMethodFilterKey::PaymentMethodType(
|
||||
api_enums::PaymentMethodType::Credit,
|
||||
),
|
||||
currency_country_flow_filter.clone(),
|
||||
),
|
||||
(
|
||||
kgraph_types::PaymentMethodFilterKey::PaymentMethodType(
|
||||
api_enums::PaymentMethodType::Debit,
|
||||
),
|
||||
currency_country_flow_filter,
|
||||
),
|
||||
])),
|
||||
)]),
|
||||
default_configs: None,
|
||||
};
|
||||
|
||||
make_mca_graph(vec![stripe_account], &config_map).expect("Failed graph construction")
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -412,8 +795,8 @@ mod tests {
|
||||
dirval!(PaymentMethod = Card),
|
||||
dirval!(CardType = Credit),
|
||||
dirval!(CardNetwork = Visa),
|
||||
dirval!(PaymentCurrency = USD),
|
||||
dirval!(PaymentAmount = 100),
|
||||
dirval!(PaymentCurrency = INR),
|
||||
dirval!(PaymentAmount = 101),
|
||||
]),
|
||||
&mut Memoization::new(),
|
||||
&mut CycleCheck::new(),
|
||||
@ -711,8 +1094,11 @@ mod tests {
|
||||
|
||||
let data: Vec<admin_api::MerchantConnectorResponse> =
|
||||
serde_json::from_value(value).expect("data");
|
||||
|
||||
let graph = make_mca_graph(data).expect("graph");
|
||||
let config = kgraph_types::CountryCurrencyFilter {
|
||||
connector_configs: HashMap::new(),
|
||||
default_configs: None,
|
||||
};
|
||||
let graph = make_mca_graph(data, &config).expect("graph");
|
||||
let context = AnalysisContext::from_dir_values([
|
||||
dirval!(Connector = Stripe),
|
||||
dirval!(PaymentAmount = 212),
|
||||
|
||||
35
crates/kgraph_utils/src/types.rs
Normal file
35
crates/kgraph_utils/src/types.rs
Normal file
@ -0,0 +1,35 @@
|
||||
use std::collections::{HashMap, HashSet};
|
||||
|
||||
use api_models::enums as api_enums;
|
||||
use serde::Deserialize;
|
||||
#[derive(Debug, Deserialize, Clone, Default)]
|
||||
|
||||
pub struct CountryCurrencyFilter {
|
||||
pub connector_configs: HashMap<api_enums::RoutableConnectors, PaymentMethodFilters>,
|
||||
pub default_configs: Option<PaymentMethodFilters>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Clone, Default)]
|
||||
#[serde(transparent)]
|
||||
pub struct PaymentMethodFilters(pub HashMap<PaymentMethodFilterKey, CurrencyCountryFlowFilter>);
|
||||
|
||||
#[derive(Debug, Deserialize, Clone, PartialEq, Eq, Hash)]
|
||||
#[serde(untagged)]
|
||||
pub enum PaymentMethodFilterKey {
|
||||
PaymentMethodType(api_enums::PaymentMethodType),
|
||||
CardNetwork(api_enums::CardNetwork),
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Clone, Default)]
|
||||
#[serde(default)]
|
||||
pub struct CurrencyCountryFlowFilter {
|
||||
pub currency: Option<HashSet<api_enums::Currency>>,
|
||||
pub country: Option<HashSet<api_enums::CountryAlpha2>>,
|
||||
pub not_available_flows: Option<NotAvailableFlows>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Copy, Clone, Default)]
|
||||
#[serde(default)]
|
||||
pub struct NotAvailableFlows {
|
||||
pub capture_method: Option<api_enums::CaptureMethod>,
|
||||
}
|
||||
Reference in New Issue
Block a user