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

Code before:
        let apple_pay_wallet_data = payment_data
            .get_payment_method_data()
            .and_then(|payment_method_data| payment_method_data.get_wallet_data())
            .and_then(|wallet_data| wallet_data.get_apple_pay_wallet_data());

        let pre_decrypted_token = if let Some(data) = apple_pay_wallet_data {
            match &data.payment_data {
                common_payments_types::ApplePayPaymentData::Encrypted(_) => None,
                common_payments_types::ApplePayPaymentData::Decrypted(
                    apple_pay_predecrypt_data,
                ) => {
                    helpers::validate_card_expiry(
                        &apple_pay_predecrypt_data.application_expiration_month,
                        &apple_pay_predecrypt_data.application_expiration_year,
                    )?;
                    Some(PaymentMethodToken::ApplePayDecrypt(Box::new(
                        apple_pay_predecrypt_data.clone(),
                    )))
                }
            }
        } else {
            None
        };

        let support_predecrypted_token =
            is_predecrypted_flow_supported_googlepay(merchant_connector_account.get_metadata());
        match (pre_decrypted_token, support_predecrypted_token) {
            (Some(PaymentMethodToken::ApplePayDecrypt(_token)), false) => {
                Err(errors::ApiErrorResponse::PreconditionFailed {
                    message: "Predecrypted token is not enabled for ApplePay".to_string(),
                }
                .into())
            }
            (Some(PaymentMethodToken::ApplePayDecrypt(token)), true) => {
                Ok(Some(PaymentMethodToken::ApplePayDecrypt(token)))
            }
            (_, _) => Ok(None),
        }
    }

    fn decide_wallet_flow(
        &self,
        state: &SessionState,
        payment_data: &D,
        merchant_connector_account: &helpers::MerchantConnectorAccountType,
    ) -> CustomResult<Option<DecideWalletFlow>, errors::ApiErrorResponse> {
        let apple_pay_metadata = check_apple_pay_metadata(state, Some(merchant_connector_account));

        add_apple_pay_flow_metrics(
            &apple_pay_metadata,
            payment_data.get_payment_attempt().connector.clone(),

Review comment (suggestion):
This can be moved inside `common_payments_types::ApplePayPaymentData::Decrypted` match arm

Code after:
    F: Send + Clone,
    D: OperationSessionGetters<F> + Send + Sync + Clone,
{
    fn check_predecrypted_token(
        &self,
        payment_data: &D,
        merchant_connector_account: &helpers::MerchantConnectorAccountType,
    ) -> CustomResult<Option<PaymentMethodToken>, errors::ApiErrorResponse> {
        let google_pay_wallet_data = payment_data
            .get_payment_method_data()
            .and_then(|payment_method_data| payment_method_data.get_wallet_data())
            .and_then(|wallet_data| wallet_data.get_google_pay_wallet_data());

        if let Some(data) = google_pay_wallet_data {
            match &data.tokenization_data {
                common_payments_types::GpayTokenizationData::Encrypted(_) => Ok(None),
                common_payments_types::GpayTokenizationData::Decrypted(
                    google_pay_predecrypt_data,
                ) => {
                    if is_googlepay_predecrypted_flow_supported(
                        merchant_connector_account.get_metadata(),
                    ) {
                        helpers::validate_card_expiry(
                            &google_pay_predecrypt_data.card_exp_month,
                            &google_pay_predecrypt_data.card_exp_year,
                        )?;
                        Ok(Some(PaymentMethodToken::GooglePayDecrypt(Box::new(
                            google_pay_predecrypt_data.clone(),
                        ))))
                    } else {
                        Err(errors::ApiErrorResponse::PreconditionFailed {
                            message: "Predecrypted token flow is not enabled for GooglePay."
                                .to_string(),
                        }
                        .into())
                    }
                }
            }
        } else {
            Ok(None)
        }
    }
    fn decide_wallet_flow(
        &self,
        state: &SessionState,
        _payment_data: &D,
        merchant_connector_account: &helpers::MerchantConnectorAccountType,
    ) -> CustomResult<Option<DecideWalletFlow>, errors::ApiErrorResponse> {
        Ok(
            get_google_pay_connector_wallet_details(state, merchant_connector_account)
                .map(DecideWalletFlow::GooglePayDecrypt),