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

Code before:
pub struct PaymentAttemptListData<F>
where
    F: Clone,
{
    pub flow: PhantomData<F>,
    pub payment_attempt_list: Vec<PaymentAttempt>,
}

// TODO: Check if this can be merged with existing payment data
#[cfg(feature = "v2")]
#[derive(Clone, Debug)]
pub struct PaymentConfirmData<F>
where
    F: Clone,
{
    pub flow: PhantomData<F>,
    pub payment_intent: PaymentIntent,
    pub payment_attempt: PaymentAttempt,
    pub payment_method_data: Option<payment_method_data::PaymentMethodData>,
    pub payment_address: payment_address::PaymentAddress,
    pub mandate_data: Option<api_models::payments::MandateIds>,
    pub payment_method: Option<payment_methods::PaymentMethod>,
    pub merchant_connector_details: Option<common_types::domain::MerchantConnectorAuthDetails>,
    pub external_vault_pmd: Option<payment_method_data::ExternalVaultPaymentMethodData>,
}

#[cfg(feature = "v2")]
impl<F: Clone> PaymentConfirmData<F> {
    pub fn get_connector_customer_id(
        &self,
        customer: Option<&customer::Customer>,
        merchant_connector_account: &MerchantConnectorAccountTypeDetails,
    ) -> Option<String> {
        match merchant_connector_account {
            MerchantConnectorAccountTypeDetails::MerchantConnectorAccount(_) => customer
                .and_then(|customer| customer.get_connector_customer_id(merchant_connector_account))
                .map(|id| id.to_string())
                .or_else(|| {
                    self.payment_intent
                        .get_connector_customer_id_from_feature_metadata()
                }),
            MerchantConnectorAccountTypeDetails::MerchantConnectorDetails(_) => None,
        }
    }

    pub fn update_payment_method_data(
        &mut self,
        payment_method_data: payment_method_data::PaymentMethodData,
    ) {
        self.payment_method_data = Some(payment_method_data);
    }

Review comment (suggestion):
You can make the change of modifying the type here and RouterData as well in a separate PR, please create an issue for it

Code after:
pub struct PaymentAttemptListData<F>
where
    F: Clone,
{
    pub flow: PhantomData<F>,
    pub payment_attempt_list: Vec<PaymentAttempt>,
}

// TODO: Check if this can be merged with existing payment data
#[cfg(feature = "v2")]
#[derive(Clone, Debug)]
pub struct PaymentConfirmData<F>
where
    F: Clone,
{
    pub flow: PhantomData<F>,
    pub payment_intent: PaymentIntent,
    pub payment_attempt: PaymentAttempt,
    pub payment_method_data: Option<payment_method_data::PaymentMethodData>,
    pub payment_address: payment_address::PaymentAddress,
    pub mandate_data: Option<api_models::payments::MandateIds>,
    pub payment_method: Option<payment_methods::PaymentMethod>,
    pub merchant_connector_details: Option<common_types::domain::MerchantConnectorAuthDetails>,
    pub external_vault_pmd: Option<payment_method_data::ExternalVaultPaymentMethodData>,
    /// The webhook url of the merchant, to which the connector will send the webhook.
    pub webhook_url: Option<String>,
}

#[cfg(feature = "v2")]
impl<F: Clone> PaymentConfirmData<F> {
    pub fn get_connector_customer_id(
        &self,
        customer: Option<&customer::Customer>,
        merchant_connector_account: &MerchantConnectorAccountTypeDetails,
    ) -> Option<String> {
        match merchant_connector_account {
            MerchantConnectorAccountTypeDetails::MerchantConnectorAccount(_) => customer
                .and_then(|customer| customer.get_connector_customer_id(merchant_connector_account))
                .map(|id| id.to_string())
                .or_else(|| {
                    self.payment_intent
                        .get_connector_customer_id_from_feature_metadata()
                }),
            MerchantConnectorAccountTypeDetails::MerchantConnectorDetails(_) => None,
        }
    }

    pub fn update_payment_method_data(
        &mut self,
        payment_method_data: payment_method_data::PaymentMethodData,
    ) {