From 1aa4ad60e2326cbdc5c81479cf3420c3f3e1d8ee Mon Sep 17 00:00:00 2001 From: Prajjwal Kumar Date: Tue, 10 Dec 2024 16:38:34 +0530 Subject: [PATCH] refactor(constraint_graph): add setup_future_usage for mandate check in payments (#6744) --- .../router/src/core/payment_methods/cards.rs | 15 +++++++++++- .../router/src/core/payment_methods/utils.rs | 24 +++++++++++-------- 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/crates/router/src/core/payment_methods/cards.rs b/crates/router/src/core/payment_methods/cards.rs index 259f77c81a30..135759611082 100644 --- a/crates/router/src/core/payment_methods/cards.rs +++ b/crates/router/src/core/payment_methods/cards.rs @@ -4558,6 +4558,12 @@ pub async fn filter_payment_methods( if payment_attempt .and_then(|attempt| attempt.mandate_details.as_ref()) .is_some() + || payment_intent + .and_then(|intent| intent.setup_future_usage) + .map(|future_usage| { + future_usage == common_enums::FutureUsage::OffSession + }) + .unwrap_or(false) { context_values.push(dir::DirValue::PaymentType( euclid::enums::PaymentType::NewMandate, @@ -4576,7 +4582,14 @@ pub async fn filter_payment_methods( payment_attempt .map(|attempt| { - attempt.mandate_data.is_none() && attempt.mandate_details.is_none() + attempt.mandate_data.is_none() + && attempt.mandate_details.is_none() + && payment_intent + .and_then(|intent| intent.setup_future_usage) + .map(|future_usage| { + future_usage == common_enums::FutureUsage::OnSession + }) + .unwrap_or(false) }) .and_then(|res| { res.then(|| { diff --git a/crates/router/src/core/payment_methods/utils.rs b/crates/router/src/core/payment_methods/utils.rs index 816807fe0149..d7e83cb5bf22 100644 --- a/crates/router/src/core/payment_methods/utils.rs +++ b/crates/router/src/core/payment_methods/utils.rs @@ -429,16 +429,20 @@ fn construct_supported_connectors_for_update_mandate_node( } } - Ok(Some( - builder - .make_any_aggregator( - &agg_nodes, - Some("any node for card and non card pm"), - None::<()>, - Some(domain_id), - ) - .map_err(KgraphError::GraphConstructionError)?, - )) + if !agg_nodes.is_empty() { + Ok(Some( + builder + .make_any_aggregator( + &agg_nodes, + Some("any node for card and non card pm"), + None::<()>, + Some(domain_id), + ) + .map_err(KgraphError::GraphConstructionError)?, + )) + } else { + Ok(None) + } } fn construct_supported_connectors_for_mandate_node(