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

Code before:

/// This struct stores information to generate the key to identify
/// a unique payment method balance entry in the HashMap stored in Redis
#[cfg(feature = "v2")]
#[derive(Eq, Hash, PartialEq, Clone, Debug)]
pub struct PaymentMethodBalanceKey {
    pub payment_method_type: common_enums::PaymentMethod,
    pub payment_method_subtype: common_enums::PaymentMethodType,
    pub payment_method_key: String,
}

#[cfg(feature = "v2")]
impl PaymentMethodBalanceKey {
    pub fn get_redis_key(&self) -> String {
        format!(
            "{}_{}_{}",
            self.payment_method_type, self.payment_method_subtype, self.payment_method_key
        )
    }
}

/// This struct stores the balance and currency information for a specific
/// payment method to be stored in the HashMap in Redis
#[cfg(feature = "v2")]
#[derive(Clone, Debug, serde::Serialize)]
pub struct PaymentMethodBalanceValue {
    pub balance: common_utils::types::MinorUnit,
    pub currency: common_enums::Currency,
}

#[cfg(feature = "v2")]
pub struct PaymentMethodBalanceData<'a> {
    pub pm_balance_data: HashMap<PaymentMethodBalanceKey, PaymentMethodBalanceValue>,
    pub payment_intent_id: &'a id_type::GlobalPaymentId,
}

#[cfg(feature = "v2")]
impl<'a> PaymentMethodBalanceData<'a> {
    pub fn new(payment_intent_id: &'a id_type::GlobalPaymentId) -> Self {
        Self {
            pm_balance_data: HashMap::new(),
            payment_intent_id,
        }
    }

    pub fn get_pm_balance_redis_key(&self) -> String {
        format!("pm_balance_{}", self.payment_intent_id.get_string_repr())
    }

    pub fn is_empty(&self) -> bool {
        self.pm_balance_data.is_empty()

Review comment (suggestion):
```suggestion
pub struct PaymentMethodBalance {
```

Code after:

/// This struct stores information to generate the key to identify
/// a unique payment method balance entry in the HashMap stored in Redis
#[cfg(feature = "v2")]
#[derive(Eq, Hash, PartialEq, Clone, Debug)]
pub struct PaymentMethodBalanceKey {
    pub payment_method_type: common_enums::PaymentMethod,
    pub payment_method_subtype: common_enums::PaymentMethodType,
    pub payment_method_key: String,
}

#[cfg(feature = "v2")]
impl PaymentMethodBalanceKey {
    pub fn get_redis_key(&self) -> String {
        format!(
            "{}_{}_{}",
            self.payment_method_type, self.payment_method_subtype, self.payment_method_key
        )
    }
}

/// This struct stores the balance and currency information for a specific
/// payment method to be stored in the HashMap in Redis
#[cfg(feature = "v2")]
#[derive(Clone, Debug, serde::Serialize)]
pub struct PaymentMethodBalance {
    pub balance: common_utils::types::MinorUnit,
    pub currency: common_enums::Currency,
}

#[cfg(feature = "v2")]
pub struct PaymentMethodBalanceData<'a> {
    pub pm_balance_data: HashMap<PaymentMethodBalanceKey, PaymentMethodBalance>,
    pub payment_intent_id: &'a id_type::GlobalPaymentId,
}

#[cfg(feature = "v2")]
impl<'a> PaymentMethodBalanceData<'a> {
    pub fn new(payment_intent_id: &'a id_type::GlobalPaymentId) -> Self {
        Self {
            pm_balance_data: HashMap::new(),
            payment_intent_id,
        }
    }

    pub fn get_pm_balance_redis_key(&self) -> String {
        format!("pm_balance_{}", self.payment_intent_id.get_string_repr())
    }

    pub fn is_empty(&self) -> bool {
        self.pm_balance_data.is_empty()