Repository: juspay/hyperswitch
File: crates/router/src/core/payments/retry.rs (Rust)

Code before:

                    let should_retry_with_pan = is_network_token
                        && clear_pan_possible
                        && business_profile.is_clear_pan_retries_enabled;

                    let (connector, routing_decision) = if should_retry_with_pan {
                        // If should_retry_with_pan is true, it indicates that we are retrying with PAN using the same connector.
                        (original_connector_data.clone(), None)
                    } else {
                        let connector_routing_data =
                            super::get_connector_data(&mut connector_routing_data)?;
                        let routing_decision = connector_routing_data.network.map(|card_network| {
                            routing_helpers::RoutingDecisionData::get_debit_routing_decision_data(
                                card_network,
                                None,
                            )
                        });

                        (connector_routing_data.connector_data, routing_decision)
                    };

                    match (
                        payment_data.get_payment_intent().setup_future_usage,
                        payment_data.get_payment_intent().off_session,
                    ) {
                        (Some(storage_enums::FutureUsage::OffSession), _) | (_, Some(true)) => {
                            let current_connector_routing_data =
                                super::get_connector_data(&mut connector_routing_data)?;
                            let payment_method_info = payment_data
                                .get_payment_method_info()
                                .get_required_value("payment_method_info")?
                                .clone();
                            let mandate_reference_id = payments::get_mandate_reference_id(
                                current_connector_routing_data.action_type.clone(),
                                current_connector_routing_data,
                                payment_data,
                                &payment_method_info,
                            )?;
                            payment_data.set_mandate_id(api_models::payments::MandateIds {
                                mandate_id: None,
                                mandate_reference_id, //mandate_ref_id
                            });
                        }
                        _ => (),
                    }

                    router_data = do_retry(
                        &state.clone(),
                        req_state.clone(),
                        &connector,
                        operation,

Review comment (suggestion):
if setup future usage is off-session - then it is considered as CIT, then we dont want to go through this snippet.

transaction is considered as Merchant Initiated transaction  only when off-session is set to true which mean customer is not present.

Code after:
                    let should_retry_with_pan = is_network_token
                        && clear_pan_possible
                        && business_profile.is_clear_pan_retries_enabled;

                    // Currently we are taking off_session as a source of truth to identify MIT payments.
                    let is_mit_payment = payment_data
                        .get_payment_intent()
                        .off_session
                        .unwrap_or(false);

                    let (connector, routing_decision) = if is_mit_payment {
                        let connector_routing_data =
                            super::get_connector_data(&mut connector_routing_data)?;
                        let payment_method_info = payment_data
                            .get_payment_method_info()
                            .get_required_value("payment_method_info")?
                            .clone();
                        let mandate_reference_id = payments::get_mandate_reference_id(
                            connector_routing_data.action_type.clone(),
                            connector_routing_data.clone(),
                            payment_data,
                            &payment_method_info,
                        )?;
                        payment_data.set_mandate_id(api_models::payments::MandateIds {
                            mandate_id: None,
                            mandate_reference_id, //mandate_ref_id
                        });
                        (connector_routing_data.connector_data, None)
                    } else if should_retry_with_pan {
                        // If should_retry_with_pan is true, it indicates that we are retrying with PAN using the same connector.
                        (original_connector_data.clone(), None)
                    } else {
                        let connector_routing_data =
                            super::get_connector_data(&mut connector_routing_data)?;
                        let routing_decision = connector_routing_data.network.map(|card_network| {
                            routing_helpers::RoutingDecisionData::get_debit_routing_decision_data(
                                card_network,
                                None,
                            )
                        });

                        (connector_routing_data.connector_data, routing_decision)
                    };

                    router_data = do_retry(
                        &state.clone(),
                        req_state.clone(),
                        &connector,
                        operation,
                        customer,
                        merchant_context,