Skip to content

Commit

Permalink
refactor(constraint_graph): add setup_future_usage for mandate check …
Browse files Browse the repository at this point in the history
…in payments (#6744)
  • Loading branch information
prajjwalkumar17 authored Dec 10, 2024
1 parent 47a3d2b commit 1aa4ad6
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 11 deletions.
15 changes: 14 additions & 1 deletion crates/router/src/core/payment_methods/cards.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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(|| {
Expand Down
24 changes: 14 additions & 10 deletions crates/router/src/core/payment_methods/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 1aa4ad6

Please sign in to comment.