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

Code before:
    ) -> 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(),
        ))
    }

    fn handle_response(
        &self,
        data: &hyperswitch_domain_models::types::CreateCustomerRouterData,
        event_builder: Option<&mut ConnectorEvent>,
        res: Response,
    ) -> CustomResult<
        hyperswitch_domain_models::types::CreateCustomerRouterData,
        errors::ConnectorError,

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

Code after:
}

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}}`).",
            }
            .into());
        }

        if !base.ends_with('/') {
            base.push('/');
        }

        let url = format!("{base}v2/items{query_params}");
        Ok(url)
    }