Repository: juspay/hyperswitch
File: crates/api_models/src/subscription.rs (Rust)

Code before:
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
pub struct ClientSecret(String);

impl ClientSecret {
    pub fn new(secret: String) -> Self {
        Self(secret)
    }

    pub fn as_str(&self) -> &str {
        &self.0
    }

    pub fn as_string(&self) -> &String {
        &self.0
    }
}

#[derive(serde::Deserialize, serde::Serialize, Debug)]
pub struct GetPlansQuery {
    pub client_secret: Option<ClientSecret>,
    pub limit: Option<u32>,
    pub offset: Option<u32>,
}

#[derive(serde::Deserialize, serde::Serialize, Debug)]
pub struct GetSubscriptionQuery {
    pub client_secret: Option<ClientSecret>,
}

impl ApiEventMetric for SubscriptionResponse {}
impl ApiEventMetric for CreateSubscriptionRequest {}
impl ApiEventMetric for GetPlansQuery {}
impl ApiEventMetric for GetPlansResponse {}
impl ApiEventMetric for GetSubscriptionQuery {}

#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, ToSchema)]
pub struct ConfirmSubscriptionPaymentDetails {
    pub shipping: Option<Address>,
    pub payment_method: api_enums::PaymentMethod,
    pub payment_method_type: Option<api_enums::PaymentMethodType>,
    pub payment_method_data: PaymentMethodDataRequest,
    pub customer_acceptance: Option<CustomerAcceptance>,
}

#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, ToSchema)]
pub struct CreateSubscriptionPaymentDetails {
    pub return_url: common_utils::types::Url,
    pub setup_future_usage: Option<api_enums::FutureUsage>,
    pub capture_method: Option<api_enums::CaptureMethod>,
    pub authentication_type: Option<api_enums::AuthenticationType>,
}

Review comment (suggestion):
Get-subscription shouldn't be a client call, basically if a merchant wants to update their state with a response of hyperswitch then they shouldn't depend on the client to send data, instead they should depend on server to server communication which is safer and scalable with features  

Code after:
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
pub struct ClientSecret(String);

impl ClientSecret {
    pub fn new(secret: String) -> Self {
        Self(secret)
    }

    pub fn as_str(&self) -> &str {
        &self.0
    }

    pub fn as_string(&self) -> &String {
        &self.0
    }
}

#[derive(serde::Deserialize, serde::Serialize, Debug)]
pub struct GetPlansQuery {
    pub client_secret: Option<ClientSecret>,
    pub limit: Option<u32>,
    pub offset: Option<u32>,
}

impl ApiEventMetric for SubscriptionResponse {}
impl ApiEventMetric for CreateSubscriptionRequest {}
impl ApiEventMetric for GetPlansQuery {}
impl ApiEventMetric for GetPlansResponse {}

#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, ToSchema)]
pub struct ConfirmSubscriptionPaymentDetails {
    pub shipping: Option<Address>,
    pub payment_method: api_enums::PaymentMethod,
    pub payment_method_type: Option<api_enums::PaymentMethodType>,
    pub payment_method_data: PaymentMethodDataRequest,
    pub customer_acceptance: Option<CustomerAcceptance>,
}

#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, ToSchema)]
pub struct CreateSubscriptionPaymentDetails {
    pub return_url: common_utils::types::Url,
    pub setup_future_usage: Option<api_enums::FutureUsage>,
    pub capture_method: Option<api_enums::CaptureMethod>,
    pub authentication_type: Option<api_enums::AuthenticationType>,
}

#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, ToSchema)]
pub struct PaymentDetails {
    pub payment_method: Option<api_enums::PaymentMethod>,
    pub payment_method_type: Option<api_enums::PaymentMethodType>,
    pub payment_method_data: Option<PaymentMethodDataRequest>,