Skip to content

Commit

Permalink
fix(core): add validation to check if routable connector supports net…
Browse files Browse the repository at this point in the history
…work tokenization in CIT repeat flow (#6749)

Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
  • Loading branch information
prasunna09 and hyperswitch-bot[bot] authored Dec 10, 2024
1 parent f96a87d commit 9f0d8ef
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
2 changes: 2 additions & 0 deletions crates/router/src/core/payment_methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,7 @@ pub async fn retrieve_payment_method_with_token(
mandate_id,
payment_method_info,
business_profile,
payment_attempt.connector.clone(),
)
.await
.map(|card| Some((card, enums::PaymentMethod::Card)))?
Expand Down Expand Up @@ -622,6 +623,7 @@ pub async fn retrieve_payment_method_with_token(
mandate_id,
payment_method_info,
business_profile,
payment_attempt.connector.clone(),
)
.await
.map(|card| Some((card, enums::PaymentMethod::Card)))?
Expand Down
28 changes: 27 additions & 1 deletion crates/router/src/core/payments/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1916,6 +1916,7 @@ pub async fn retrieve_card_with_permanent_token(
mandate_id: Option<api_models::payments::MandateIds>,
payment_method_info: Option<domain::PaymentMethod>,
business_profile: &domain::Profile,
connector: Option<String>,
) -> RouterResult<domain::PaymentMethodData> {
let customer_id = payment_intent
.customer_id
Expand Down Expand Up @@ -1986,7 +1987,28 @@ pub async fn retrieve_card_with_permanent_token(
.attach_printable("Payment method data is not present"),
(Some(ref pm_data), None) => {
// Regular (non-mandate) Payment flow
if let Some(token_ref) = pm_data.network_token_requestor_reference_id.clone() {
let network_tokenization_supported_connectors = &state
.conf
.network_tokenization_supported_connectors
.connector_list;
let connector_variant = connector
.as_ref()
.map(|conn| {
api_enums::Connector::from_str(conn.as_str())
.change_context(errors::ApiErrorResponse::InvalidDataValue {
field_name: "connector",
})
.attach_printable_lazy(|| {
format!("unable to parse connector name {connector:?}")
})
})
.transpose()?;
if let (Some(_conn), Some(token_ref)) = (
connector_variant
.filter(|conn| network_tokenization_supported_connectors.contains(conn)),
pm_data.network_token_requestor_reference_id.clone(),
) {
logger::info!("Fetching network token data from tokenization service");
match network_tokenization::get_token_from_tokenization_service(
state, token_ref, pm_data,
)
Expand Down Expand Up @@ -2016,6 +2038,8 @@ pub async fn retrieve_card_with_permanent_token(
}
}
} else {
logger::info!("Either the connector is not in the NT supported list or token requestor reference ID is absent");
logger::info!("Falling back to fetch card details from locker");
fetch_card_details_from_locker(
state,
customer_id,
Expand Down Expand Up @@ -5773,6 +5797,7 @@ pub async fn get_payment_method_details_from_payment_token(
None,
None,
business_profile,
payment_attempt.connector.clone(),
)
.await
.map(|card| Some((card, enums::PaymentMethod::Card))),
Expand All @@ -5791,6 +5816,7 @@ pub async fn get_payment_method_details_from_payment_token(
None,
None,
business_profile,
payment_attempt.connector.clone(),
)
.await
.map(|card| Some((card, enums::PaymentMethod::Card))),
Expand Down

0 comments on commit 9f0d8ef

Please sign in to comment.