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

Code before:
) -> bool {
    match (payment_method_type, payment_method_token) {
        (
            Some(storage::enums::PaymentMethodType::ApplePay),
            Some(PaymentMethodToken::ApplePayDecrypt(..)),
        ) => !matches!(
            apple_pay_pre_decrypt_flow_filter,
            Some(ApplePayPreDecryptFlow::NetworkTokenization)
        ),
        _ => true,
    }
}

fn is_google_pay_pre_decrypt_type_connector_tokenization(
    payment_method_type: Option<storage::enums::PaymentMethodType>,
    payment_method_token: Option<&PaymentMethodToken>,
    google_pay_pre_decrypt_flow_filter: Option<GooglePayPreDecryptFlow>,
) -> bool {
    match (payment_method_type, payment_method_token) {
        (
            Some(storage::enums::PaymentMethodType::GooglePay),
            Some(PaymentMethodToken::GooglePayDecrypt(..)),
        ) => !matches!(
            google_pay_pre_decrypt_flow_filter,
            Some(GooglePayPreDecryptFlow::NetworkTokenization)
        ),
        _ => true,
    }
}

fn decide_apple_pay_flow(
    state: &SessionState,
    payment_method_type: Option<enums::PaymentMethodType>,
    merchant_connector_account: Option<&helpers::MerchantConnectorAccountType>,
) -> Option<domain::ApplePayFlow> {
    payment_method_type.and_then(|pmt| match pmt {
        enums::PaymentMethodType::ApplePay => {
            check_apple_pay_metadata(state, merchant_connector_account)
        }
        _ => None,
    })
}

fn check_apple_pay_metadata(
    state: &SessionState,
    merchant_connector_account: Option<&helpers::MerchantConnectorAccountType>,
) -> Option<domain::ApplePayFlow> {
    merchant_connector_account.and_then(|mca| {
        let metadata = mca.get_metadata();
        metadata.and_then(|apple_pay_metadata| {
            let parsed_metadata = apple_pay_metadata

Review comment (suggestion):
instead of not operation over network tokenization, can we just do a match over connector tokenization. if tomorrow a new variant comes it, that is not needed to be handled in this function

Code after:
{
    let profile_id = payment_data
        .get_payment_intent()
        .profile_id
        .as_ref()
        .get_required_value("profile_id")
        .change_context(errors::ApiErrorResponse::InternalServerError)
        .attach_printable("profile_id is not set in payment_intent")?
        .clone();

    #[cfg(feature = "v2")]
    let profile_id = payment_data.get_payment_intent().profile_id.clone();

    let merchant_connector_account = helpers::get_merchant_connector_account(
        state,
        merchant_context.get_merchant_account().get_id(),
        payment_data.get_creds_identifier(),
        merchant_context.get_merchant_key_store(),
        &profile_id,
        connector_name,
        merchant_connector_id,
    )
    .await?;

    Ok(merchant_connector_account)
}

fn is_payment_method_tokenization_enabled_for_connector(
    state: &SessionState,
    connector_name: &str,
    payment_method: storage::enums::PaymentMethod,
    payment_method_type: Option<storage::enums::PaymentMethodType>,
    payment_method_token: Option<&PaymentMethodToken>,
    mandate_flow_enabled: Option<storage_enums::FutureUsage>,
) -> RouterResult<bool> {
    let connector_tokenization_filter = state.conf.tokenization.0.get(connector_name);

    Ok(connector_tokenization_filter
        .map(|connector_filter| {
            connector_filter
                .payment_method
                .clone()
                .contains(&payment_method)
                && is_payment_method_type_allowed_for_connector(
                    payment_method_type,
                    connector_filter.payment_method_type.clone(),
                )
                && is_apple_pay_pre_decrypt_type_connector_tokenization(
                    payment_method_type,
                    payment_method_token,
                    connector_filter.apple_pay_pre_decrypt_flow.clone(),