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

Code before:
use common_utils::{events::ApiEventMetric, pii};
use masking::Secret;
use utoipa::ToSchema;

use crate::{
    customers::{CustomerRequest, CustomerResponse},
    payments::CustomerDetailsResponse,
};

/// Request payload for creating a subscription.
///
/// This struct captures details required to create a subscription,
/// including plan, profile, merchant connector, and optional customer info.
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, ToSchema)]
pub struct CreateSubscriptionRequest {
    /// Unique identifier for the subscription (optional, generated if missing).
    pub subscription_id: Option<common_utils::id_type::SubscriptionId>,

    /// Associated profile ID for this subscription.
    pub profile_id: common_utils::id_type::ProfileId,

    /// Identifier for the subscription plan.
    pub plan_id: Option<String>,

    /// Optional coupon code applied to the subscription.
    pub coupon_code: Option<String>,

    /// Optional merchant connector account ID for routing payments.
    pub merchant_connector_account_id: Option<common_utils::id_type::MerchantConnectorAccountId>,

    /// Whether to immediately confirm the subscription on creation.
    pub confirm: Option<bool>,

    /// Optional customer ID associated with this subscription.
    pub customer_id: Option<common_utils::id_type::CustomerId>,

    /// Optional full customer request data.
    pub customer: Option<CustomerRequest>,
}

impl CreateSubscriptionRequest {
    /// Retrieves the `customer_id` either from the top-level field

Review comment (suggestion):
We should not get the database reference id from merchants, id should be generated for us, introduce a merchant_reference_id where they can pass their ids but that is not the id we will be processing with our api's.

The id which we generate should be global unique without any composite id logic 

Code after:
use common_utils::events::ApiEventMetric;
use masking::Secret;
use utoipa::ToSchema;

// use crate::{
//     customers::{CustomerRequest, CustomerResponse},
//     payments::CustomerDetailsResponse,
// };

/// Request payload for creating a subscription.
///
/// This struct captures details required to create a subscription,
/// including plan, profile, merchant connector, and optional customer info.
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, ToSchema)]
pub struct CreateSubscriptionRequest {
    /// Merchant specific Unique identifier.
    pub merchant_reference_id: Option<String>,

    /// Identifier for the subscription plan.
    pub plan_id: Option<String>,

    /// Optional coupon code applied to the subscription.
    pub coupon_code: Option<String>,

    /// customer ID associated with this subscription.
    pub customer_id: common_utils::id_type::CustomerId,
}

/// Response payload returned after successfully creating a subscription.
///
/// Includes details such as subscription ID, status, plan, merchant, and customer info.
#[derive(Debug, Clone, serde::Serialize, ToSchema)]
pub struct CreateSubscriptionResponse {
    /// Unique identifier for the subscription.
    pub id: common_utils::id_type::SubscriptionId,

    /// Merchant specific Unique identifier.
    pub merchant_reference_id: Option<String>,

    /// Current status of the subscription.
    pub status: SubscriptionStatus,