Repository: juspay/hyperswitch
File: crates/hyperswitch_connectors/src/connectors/chargebee/transformers.rs (Rust)

Code before:
                .and_then(|addr| addr.city.clone()),
            billing_address_state: req
                .billing_address
                .address
                .as_ref()
                .and_then(|addr| addr.state.as_ref().map(|state| state.clone().expose())),
            billing_address_zip: req
                .billing_address
                .address
                .as_ref()
                .and_then(|addr| addr.zip.as_ref().map(|zip| zip.clone().expose())),
            billing_address_country: req
                .billing_address
                .address
                .as_ref()
                .and_then(|addr| addr.country.map(|country| country.to_string())),
            auto_collection: req.auto_collection.clone(),
        })
    }
}

#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct ChargebeeSubscriptionCreateResponse {
    pub subscription: ChargebeeSubscriptionDetails,
}

#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct ChargebeeSubscriptionDetails {
    pub id: String,
    pub status: String,
    pub customer_id: String,
    pub currency_code: enums::Currency,
    pub total_dues: Option<MinorUnit>,
    #[serde(default, with = "common_utils::custom_serde::timestamp::option")]
    pub next_billing_at: Option<PrimitiveDateTime>,
    #[serde(default, with = "common_utils::custom_serde::timestamp::option")]
    pub created_at: Option<PrimitiveDateTime>,
}

#[cfg(feature = "v1")]
impl TryFrom<
    ResponseRouterData<
        hyperswitch_domain_models::router_flow_types::subscriptions::SubscriptionCreate,
        ChargebeeSubscriptionCreateResponse,
        hyperswitch_domain_models::router_request_types::subscriptions::SubscriptionCreateRequest,
        hyperswitch_domain_models::router_response_types::subscriptions::SubscriptionCreateResponse,
    >,
> for hyperswitch_domain_models::types::SubscriptionCreateRouterData
{
    type Error = error_stack::Report<errors::ConnectorError>;
    fn try_from(

Review comment (suggestion):
```suggestion
let address = req.billing_address.address.as_ref();

Ok(Self {
    item_price_id: first_item.item_price_id.clone(),
    quantity: first_item.quantity,
    billing_address_line1: address.and_then(|addr| addr.line1.as_ref().map(|line1| line1.clone().expose())),
    billing_address_city: address.and_then(|addr| addr.city.clone()),
    billing_address_state: address.and_then(|addr| addr.state.as_ref().map(|state| state.clone().expose())),
    billing_address_zip: address.and_then(|addr| addr.zip.as_ref().map(|zip| zip.clone().expose())),
    billing_address_country: address.and_then(|addr| addr.country.map(|country| country.to_string())),
    auto_collection: req.auto_collection.clone(),
})
```

Code after:
    for ChargebeeSubscriptionCreateRequest
{
    type Error = error_stack::Report<errors::ConnectorError>;
    fn try_from(
        item: &ChargebeeRouterData<&hyperswitch_domain_models::types::SubscriptionCreateRouterData>,
    ) -> Result<Self, Self::Error> {
        let req = &item.router_data.request;

        let first_item =
            req.subscription_items
                .first()
                .ok_or(errors::ConnectorError::MissingRequiredField {
                    field_name: "subscription_items",
                })?;

        Ok(Self {
            subscription_id: req.subscription_id.clone(),
            item_price_id: first_item.item_price_id.clone(),
            quantity: first_item.quantity,
            billing_address_line1: item.router_data.get_optional_billing_line1(),
            billing_address_city: item.router_data.get_optional_billing_city(),
            billing_address_state: item.router_data.get_optional_billing_state(),
            billing_address_zip: item.router_data.get_optional_billing_zip(),
            billing_address_country: item.router_data.get_optional_billing_country(),
            auto_collection: req.auto_collection.clone().into(),
        })
    }
}

#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct ChargebeeSubscriptionCreateResponse {
    pub subscription: ChargebeeSubscriptionDetails,
}

#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct ChargebeeSubscriptionDetails {
    pub id: SubscriptionId,
    pub status: ChargebeeSubscriptionStatus,
    pub customer_id: CustomerId,
    pub currency_code: enums::Currency,
    pub total_dues: Option<MinorUnit>,
    #[serde(default, with = "common_utils::custom_serde::timestamp::option")]
    pub next_billing_at: Option<PrimitiveDateTime>,
    #[serde(default, with = "common_utils::custom_serde::timestamp::option")]
    pub created_at: Option<PrimitiveDateTime>,
}

#[derive(Debug, Deserialize, Serialize, Clone)]
#[serde(rename_all = "snake_case")]
pub enum ChargebeeSubscriptionStatus {
    Future,