Repository: juspay/hyperswitch
File: crates/router/src/services/api.rs (Rust)

Code before:
            .change_context(errors::ConnectorError::ResponseDeserializationFailed)
            .attach_printable("Failed to deserialize UCS webhook transform data")?;

    let webhook_content = webhook_transform_data
        .webhook_content
        .ok_or(errors::ConnectorError::ResponseDeserializationFailed)
        .attach_printable("UCS webhook transform data missing webhook_content")?;

    let payment_get_response = match webhook_content.content {
        Some(unified_connector_service_client::payments::webhook_response_content::Content::PaymentsResponse(payments_response)) => {
            payments_response
        },
        Some(unified_connector_service_client::payments::webhook_response_content::Content::RefundsResponse(_)) => {
            return Err(errors::ConnectorError::ProcessingStepFailed(Some("UCS webhook contains refund response but payment processing was expected".to_string().into())).into());
        },
        Some(unified_connector_service_client::payments::webhook_response_content::Content::DisputesResponse(_)) => {
            return Err(errors::ConnectorError::ProcessingStepFailed(Some("UCS webhook contains dispute response but payment processing was expected".to_string().into())).into());
        },
        None => {
            return Err(errors::ConnectorError::ResponseDeserializationFailed)
                .attach_printable("UCS webhook content missing payments_response");
        }
    };

    let (status, router_data_response, status_code) =
        crate::core::unified_connector_service::handle_unified_connector_service_response_for_payment_get(payment_get_response.clone())
            .change_context(errors::ConnectorError::ProcessingStepFailed(None))
            .attach_printable("Failed to process UCS webhook response using PSync handler")?;

    let mut updated_router_data = router_data;
    updated_router_data.status = status;

    match router_data_response {
        Ok(_payments_response_data) => {}
        Err(error_response) => {
            updated_router_data.response = Err(error_response);
        }
    }

    updated_router_data.raw_connector_response =
        payment_get_response.raw_connector_response.map(Secret::new);
    updated_router_data.connector_http_status_code = Some(status_code);

    Ok(updated_router_data)
}

/// Handle the flow by interacting with connector module
/// `connector_request` is applicable only in case if the `CallConnectorAction` is `Trigger`
/// In other cases, It will be created if required, even if it is not passed
#[instrument(skip_all, fields(connector_name, payment_method))]
pub async fn execute_connector_processing_step<

Review comment (suggestion):
```suggestion
        unified_connector_service::handle_unified_connector_service_response_for_payment_get(payment_get_response.clone())
```

Code after:
            .change_context(errors::ConnectorError::ResponseDeserializationFailed)
            .attach_printable("Failed to deserialize UCS webhook transform data")?;

    let webhook_content = webhook_transform_data
        .webhook_content
        .ok_or(errors::ConnectorError::ResponseDeserializationFailed)
        .attach_printable("UCS webhook transform data missing webhook_content")?;

    let payment_get_response = match webhook_content.content {
        Some(unified_connector_service_client::payments::webhook_response_content::Content::PaymentsResponse(payments_response)) => {
            Ok(payments_response)
        },
        Some(unified_connector_service_client::payments::webhook_response_content::Content::RefundsResponse(_)) => {
            Err(errors::ConnectorError::ProcessingStepFailed(Some("UCS webhook contains refund response but payment processing was expected".to_string().into())).into())
        },
        Some(unified_connector_service_client::payments::webhook_response_content::Content::DisputesResponse(_)) => {
            Err(errors::ConnectorError::ProcessingStepFailed(Some("UCS webhook contains dispute response but payment processing was expected".to_string().into())).into())
        },
        None => {
            Err(errors::ConnectorError::ResponseDeserializationFailed)
                .attach_printable("UCS webhook content missing payments_response")
        }
    }?;

    let (status, router_data_response, status_code) =
        unified_connector_service::handle_unified_connector_service_response_for_payment_get(
            payment_get_response.clone(),
        )
        .change_context(errors::ConnectorError::ProcessingStepFailed(None))
        .attach_printable("Failed to process UCS webhook response using PSync handler")?;

    let mut updated_router_data = router_data;
    updated_router_data.status = status;

    let _ = router_data_response.map_err(|error_response| {
        updated_router_data.response = Err(error_response);
    });
    updated_router_data.raw_connector_response =
        payment_get_response.raw_connector_response.map(Secret::new);
    updated_router_data.connector_http_status_code = Some(status_code);

    Ok(updated_router_data)
}

fn store_raw_connector_response_if_required<T, Req, Resp>(
    return_raw_connector_response: Option<bool>,
    router_data: &mut types::RouterData<T, Req, Resp>,
    body: &types::Response,
) -> CustomResult<(), errors::ConnectorError>
where
    T: Clone + Debug + 'static,