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

Code before:

#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct ChargebeeCustomerDetails {
    pub id: String,
    pub name: Option<String>,
    pub email: Option<String>,
    pub billing_address: Option<api_models::payments::AddressDetails>,
}

impl
    TryFrom<
        ResponseRouterData<
            hyperswitch_domain_models::router_flow_types::CreateConnectorCustomer,
            ChargebeeCustomerCreateResponse,
            hyperswitch_domain_models::router_request_types::ConnectorCustomerData,
            PaymentsResponseData,
        >,
    > for hyperswitch_domain_models::types::CreateCustomerRouterData
{
    type Error = error_stack::Report<errors::ConnectorError>;

    fn try_from(
        item: ResponseRouterData<
            hyperswitch_domain_models::router_flow_types::CreateConnectorCustomer,
            ChargebeeCustomerCreateResponse,
            hyperswitch_domain_models::router_request_types::ConnectorCustomerData,
            PaymentsResponseData,
        >,
    ) -> Result<Self, Self::Error> {
        let c = &item.response.customer;

        Ok(Self {
            response: Ok(PaymentsResponseData::ConnectorCustomerResponse {
                connector_customer_id: c.id.clone(),
                name: c.name.clone(),
                email: c.email.clone(),
                billing_address: c.billing_address.clone(),
            }),
            ..item.data
        })
    }
}


Review comment (suggestion):
```suggestion
            CreateConnectorCustomer,
            ChargebeeCustomerCreateResponse,
            ConnectorCustomerData,
            PaymentsResponseData,
        >,
    > for CreateCustomerRouterData
{
    type Error = error_stack::Report<errors::ConnectorError>;

    fn try_from(
        item: ResponseRouterData<
            CreateConnectorCustomer,
            ChargebeeCustomerCreateResponse,
            ConnectorCustomerData,
```

Code after:
            .map(|plan| {
                hyperswitch_domain_models::router_response_types::subscriptions::SubscriptionPlans {
                    subscription_provider_plan_id: plan.item.id,
                    name: plan.item.name,
                    description: plan.item.description,
                }
            })
            .collect();
        Ok(Self {
            response: Ok(GetSubscriptionPlansResponse { list: plans }),
            ..item.data
        })
    }
}

#[derive(Debug, Serialize)]
pub struct ChargebeeCustomerCreateRequest {
    #[serde(rename = "id")]
    pub customer_id: CustomerId,
    #[serde(rename = "first_name")]
    pub name: Option<Secret<String>>,
    pub email: Option<Email>,
    pub billing_address: Option<api_models::payments::AddressDetails>,
}

impl TryFrom<&ChargebeeRouterData<&hyperswitch_domain_models::types::ConnectorCustomerRouterData>>
    for ChargebeeCustomerCreateRequest
{
    type Error = error_stack::Report<errors::ConnectorError>;

    fn try_from(
        item: &ChargebeeRouterData<&hyperswitch_domain_models::types::ConnectorCustomerRouterData>,
    ) -> Result<Self, Self::Error> {
        let req = &item.router_data.request;

        Ok(Self {
            customer_id: req
                .customer_id
                .as_ref()
                .ok_or_else(|| errors::ConnectorError::MissingRequiredField {
                    field_name: "customer_id",
                })?
                .clone(),
            name: req.name.clone(),
            email: req.email.clone(),
            billing_address: req.billing_address.clone(),
        })
    }
}

#[derive(Debug, Deserialize, Serialize, Clone)]