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

Code before:

    fn get_error_response(
        &self,
        res: Response,
        event_builder: Option<&mut ConnectorEvent>,
    ) -> CustomResult<ErrorResponse, errors::ConnectorError> {
        self.build_error_response(res, event_builder)
    }

    fn handle_response(
        &self,
        data: &PaymentsSyncRouterData,
        event_builder: Option<&mut ConnectorEvent>,
        res: Response,
    ) -> CustomResult<PaymentsSyncRouterData, errors::ConnectorError> {
        let response: trustpay::TrustpayPaymentsResponse = res
            .response
            .parse_struct("trustpay PaymentsResponse")
            .change_context(errors::ConnectorError::ResponseDeserializationFailed)?;

        if let trustpay::TrustpayPaymentsResponse::WebhookResponse(ref webhook_response) = response
        {
            let amount = StringMajorUnit::f64_to_string_major_unit(webhook_response.amount.amount);
            let currency = webhook_response.amount.currency;

            let response_integrity_object = connector_utils::get_sync_integrity_object(
                self.amount_converter,
                amount,
                currency.to_string(),
            )?;

            event_builder.map(|i| i.set_response_body(&response));
            router_env::logger::info!(connector_response=?response);

            let new_router_data = RouterData::try_from(ResponseRouterData {
                response,
                data: data.clone(),
                http_code: res.status_code,
            });

            return new_router_data
                .map(|mut router_data| {
                    router_data.request.integrity_object = Some(response_integrity_object);
                    router_data
                })
                .change_context(errors::ConnectorError::ResponseHandlingFailed);
        }

        event_builder.map(|i| i.set_response_body(&response));
        router_env::logger::info!(connector_response=?response);


Review comment (suggestion):
for this we should try serialising into `FloatMajorUnit` and then try converting to required type with amount_convertor

Code after:
        Ok(Some(
            RequestBuilder::new()
                .method(Method::Get)
                .url(&PaymentsSyncType::get_url(self, req, connectors)?)
                .attach_default_headers()
                .headers(PaymentsSyncType::get_headers(self, req, connectors)?)
                .build(),
        ))
    }

    fn get_error_response(
        &self,
        res: Response,
        event_builder: Option<&mut ConnectorEvent>,
    ) -> CustomResult<ErrorResponse, errors::ConnectorError> {
        self.build_error_response(res, event_builder)
    }

    fn handle_response(
        &self,
        data: &PaymentsSyncRouterData,
        event_builder: Option<&mut ConnectorEvent>,
        res: Response,
    ) -> CustomResult<PaymentsSyncRouterData, errors::ConnectorError> {
        let response: trustpay::TrustpayPaymentsResponse = res
            .response
            .parse_struct("trustpay PaymentsResponse")
            .change_context(errors::ConnectorError::ResponseDeserializationFailed)?;

        if let trustpay::TrustpayPaymentsResponse::WebhookResponse(ref webhook_response) = response
        {
            let response_integrity_object = connector_utils::get_sync_integrity_object(
                self.amount_converter_to_float_major_unit,
                webhook_response.amount.amount,
                webhook_response.amount.currency.to_string(),
            )?;

            event_builder.map(|i| i.set_response_body(&response));
            router_env::logger::info!(connector_response=?response);

            let new_router_data = RouterData::try_from(ResponseRouterData {
                response,
                data: data.clone(),
                http_code: res.status_code,
            });

            return new_router_data
                .map(|mut router_data| {
                    router_data.request.integrity_object = Some(response_integrity_object);
                    router_data
                })