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

Code before:
        &self,
        req: &hyperswitch_domain_models::types::CreateCustomerRouterData,
        connectors: &Connectors,
    ) -> CustomResult<Vec<(String, masking::Maskable<String>)>, errors::ConnectorError> {
        self.build_headers(req, connectors)
    }

    fn get_url(
        &self,
        _req: &hyperswitch_domain_models::types::CreateCustomerRouterData,
        connectors: &Connectors,
    ) -> CustomResult<String, errors::ConnectorError> {
        let url = self
            .base_url(connectors)
            .to_string()
            .replace("$", "hyperswitch-juspay-test"); // TODO: replace with metadata.site
        Ok(format!("{url}v2/customers"))
    }

    fn get_content_type(&self) -> &'static str {
        self.common_get_content_type()
    }

    fn get_request_body(
        &self,
        req: &hyperswitch_domain_models::types::CreateCustomerRouterData,
        _connectors: &Connectors,
    ) -> CustomResult<RequestContent, errors::ConnectorError> {
        let connector_router_data = chargebee::ChargebeeRouterData::from((MinorUnit::new(0), req));
        let connector_req =
            chargebee::ChargebeeCustomerCreateRequest::try_from(&connector_router_data)?;
        Ok(RequestContent::FormUrlEncoded(Box::new(connector_req)))
    }

    fn build_request(
        &self,
        req: &hyperswitch_domain_models::types::CreateCustomerRouterData,
        connectors: &Connectors,
    ) -> CustomResult<Option<Request>, errors::ConnectorError> {
        Ok(Some(
            RequestBuilder::new()
                .method(Method::Post)
                .url(&types::CreateCustomerType::get_url(self, req, connectors)?)
                .attach_default_headers()
                .headers(types::CreateCustomerType::get_headers(
                    self, req, connectors,
                )?)
                .set_body(types::CreateCustomerType::get_request_body(
                    self, req, connectors,
                )?)
                .build(),

Review comment (suggestion):
```suggestion
        req: &CreateCustomerRouterData,
```

Code after:
fn get_chargebee_plans_query_params(
    _req: &RouterData<
        GetSubscriptionPlans,
        GetSubscriptionPlansRequest,
        GetSubscriptionPlansResponse,
    >,
) -> CustomResult<String, errors::ConnectorError> {
    // Try to get limit from request, else default to 10
    let limit = _req.request.limit.unwrap_or(10);
    let param = format!("?limit={}&type[is]={}", limit, constants::PLAN_ITEM_TYPE);
    Ok(param)
}

impl api::subscriptions::Subscriptions for Chargebee {}
impl api::subscriptions::GetSubscriptionPlansFlow for Chargebee {}

impl
    ConnectorIntegration<
        GetSubscriptionPlans,
        GetSubscriptionPlansRequest,
        GetSubscriptionPlansResponse,
    > for Chargebee
{
    fn get_headers(
        &self,
        req: &GetSubscriptionPlansRouterData,
        connectors: &Connectors,
    ) -> CustomResult<Vec<(String, masking::Maskable<String>)>, errors::ConnectorError> {
        self.build_headers(req, connectors)
    }

    fn get_url(
        &self,
        req: &GetSubscriptionPlansRouterData,
        connectors: &Connectors,
    ) -> CustomResult<String, errors::ConnectorError> {
        let query_params = get_chargebee_plans_query_params(req)?;
        let metadata: chargebee::ChargebeeMetadata =
            utils::to_connector_meta_from_secret(req.connector_meta_data.clone())?;

        let site = metadata.site.peek();

        let mut base = self.base_url(connectors).to_string();

        base = base.replace("{{merchant_endpoint_prefix}}", site);
        base = base.replace("$", site);

        if base.contains("{{merchant_endpoint_prefix}}") || base.contains('$') {
            return Err(errors::ConnectorError::InvalidConnectorConfig {
                config: "Chargebee base_url has an unresolved placeholder (expected `$` or `{{merchant_endpoint_prefix}}`).",
            }