Repository: juspay/hyperswitch
File: crates/diesel_models/src/payment_attempt.rs (Rust)

Code before:
)]
#[diesel(sql_type = diesel::sql_types::Jsonb)]
pub struct ConnectorMandateReferenceId {
    pub connector_mandate_id: Option<String>,
    pub payment_method_id: Option<String>,
    pub mandate_metadata: Option<pii::SecretSerdeValue>,
    pub connector_mandate_request_reference_id: Option<String>,
}

impl ConnectorMandateReferenceId {
    pub fn get_connector_mandate_request_reference_id(&self) -> Option<String> {
        self.connector_mandate_request_reference_id.clone()
    }

    pub fn get_tokenization_strategy(
        &self,
        setup_future_usage: Option<common_enums::FutureUsage>,
    ) -> Option<common_enums::Tokenization> {
        match setup_future_usage {
            Some(common_enums::FutureUsage::OnSession) | None => None,
            Some(common_enums::FutureUsage::OffSession) => {
                if self.connector_mandate_id.is_some() {
                    Some(common_enums::Tokenization::TokenizeAtPsp)
                } else {
                    Some(common_enums::Tokenization::SkipPsp)
                }
            }
        }
    }
}
common_utils::impl_to_sql_from_sql_json!(NetworkDetails);
#[derive(
    Clone, Default, Debug, serde::Deserialize, Eq, PartialEq, serde::Serialize, diesel::AsExpression,
)]
#[diesel(sql_type = diesel::sql_types::Jsonb)]
pub struct NetworkDetails {
    pub network_advice_code: Option<String>,
}

#[cfg(feature = "v2")]
#[derive(
    Clone, Debug, Eq, PartialEq, Identifiable, Queryable, Serialize, Deserialize, Selectable,
)]
#[diesel(table_name = payment_attempt, primary_key(id), check_for_backend(diesel::pg::Pg))]
pub struct PaymentAttempt {
    pub payment_id: id_type::GlobalPaymentId,
    pub merchant_id: id_type::MerchantId,
    pub status: storage_enums::AttemptStatus,
    pub connector: Option<String>,
    pub error_message: Option<String>,
    pub surcharge_amount: Option<MinorUnit>,

Review comment (suggestion):
Nit:
```suggestion
               self.connector_mandate_id
                .map(|_| common_enums::Tokenization::TokenizeAtPsp)
                .unwrap_or(common_enums::Tokenization::SkipPsp)
```

Code after:
)]
#[diesel(sql_type = diesel::sql_types::Jsonb)]
pub struct ConnectorMandateReferenceId {
    pub connector_mandate_id: Option<String>,
    pub payment_method_id: Option<String>,
    pub mandate_metadata: Option<pii::SecretSerdeValue>,
    pub connector_mandate_request_reference_id: Option<String>,
}

impl ConnectorMandateReferenceId {
    pub fn get_connector_mandate_request_reference_id(&self) -> Option<String> {
        self.connector_mandate_request_reference_id.clone()
    }
}
common_utils::impl_to_sql_from_sql_json!(NetworkDetails);
#[derive(
    Clone, Default, Debug, serde::Deserialize, Eq, PartialEq, serde::Serialize, diesel::AsExpression,
)]
#[diesel(sql_type = diesel::sql_types::Jsonb)]
pub struct NetworkDetails {
    pub network_advice_code: Option<String>,
}

#[cfg(feature = "v2")]
#[derive(
    Clone, Debug, Eq, PartialEq, Identifiable, Queryable, Serialize, Deserialize, Selectable,
)]
#[diesel(table_name = payment_attempt, primary_key(id), check_for_backend(diesel::pg::Pg))]
pub struct PaymentAttempt {
    pub payment_id: id_type::GlobalPaymentId,
    pub merchant_id: id_type::MerchantId,
    pub status: storage_enums::AttemptStatus,
    pub connector: Option<String>,
    pub error_message: Option<String>,
    pub surcharge_amount: Option<MinorUnit>,
    pub payment_method_id: Option<id_type::GlobalPaymentMethodId>,
    #[diesel(deserialize_as = RequiredFromNullable<storage_enums::AuthenticationType>)]
    pub authentication_type: storage_enums::AuthenticationType,
    #[serde(with = "common_utils::custom_serde::iso8601")]
    pub created_at: PrimitiveDateTime,
    #[serde(with = "common_utils::custom_serde::iso8601")]
    pub modified_at: PrimitiveDateTime,
    #[serde(default, with = "common_utils::custom_serde::iso8601::option")]
    pub last_synced: Option<PrimitiveDateTime>,
    pub cancellation_reason: Option<String>,
    pub amount_to_capture: Option<MinorUnit>,
    pub browser_info: Option<common_utils::types::BrowserInformation>,
    pub error_code: Option<String>,
    pub payment_token: Option<String>,
    pub connector_metadata: Option<pii::SecretSerdeValue>,
    pub payment_experience: Option<storage_enums::PaymentExperience>,