Repository: juspay/hyperswitch
File: crates/router/src/core/relay.rs (Rust)

Code before:
            status: value.status,
            error,
            connector_resource_id: value.connector_resource_id,
            connector_id: value.connector_id,
            profile_id: value.profile_id,
            relay_type: value.relay_type,
            data: Some(data),
            connector_reference_id: value.connector_reference_id,
        })
    }
}

impl RelayRequestInner<RelayVoid> {
    pub fn from_relay_request(relay_request: relay_api_models::RelayRequest) -> RouterResult<Self> {
        match relay_request.data {
            Some(relay_api_models::RelayData::Void(ref_data)) => Ok(Self {
                connector_resource_id: relay_request.connector_resource_id,
                connector_id: relay_request.connector_id,
                relay_type: PhantomData,
                data: ref_data,
            }),
            Some(relay_api_models::RelayData::Refund(_))
            | Some(relay_api_models::RelayData::IncrementalAuthorization(_))
            | Some(relay_api_models::RelayData::Capture(_))
            | None => Err(errors::ApiErrorResponse::InvalidRequestData {
                message: "Relay data is required for relay type capture".to_string(),
            })?,
        }
    }
}

pub struct RelayVoid;

#[async_trait]
impl RelayInterface for RelayVoid {
    type Request = relay_api_models::RelayVoidRequestData;

    fn get_domain_models(
        relay_request: RelayRequestInner<Self>,
        merchant_id: &id_type::MerchantId,
        profile_id: &id_type::ProfileId,
    ) -> relay::Relay {
        let relay_id = id_type::RelayId::generate();
        let relay_void: relay::RelayVoidData = relay_request.data.into();
        relay::Relay {
            id: relay_id.clone(),
            connector_resource_id: relay_request.connector_resource_id.clone(),
            connector_id: relay_request.connector_id.clone(),
            profile_id: profile_id.clone(),
            merchant_id: merchant_id.clone(),
            relay_type: common_enums::RelayType::Void,

Review comment (suggestion):
```suggestion
            | None => Err(errors::ApiErrorResponse::InvalidRequestData {
                message: "Relay data is required for relay type void".to_string(),
            })?,
```

Code after:
            error,
            connector_resource_id: value.connector_resource_id,
            connector_id: value.connector_id,
            profile_id: value.profile_id,
            relay_type: value.relay_type,
            data: Some(data),
            connector_reference_id: value.connector_reference_id,
        })
    }
}

impl RelayRequestInner<RelayVoid> {
    pub fn from_relay_request(relay_request: relay_api_models::RelayRequest) -> RouterResult<Self> {
        match relay_request.data {
            Some(relay_api_models::RelayData::Void(ref_data)) => Ok(Self {
                connector_resource_id: relay_request.connector_resource_id,
                connector_id: relay_request.connector_id,
                relay_type: PhantomData,
                data: ref_data,
            }),
            Some(relay_api_models::RelayData::Refund(_))
            | Some(relay_api_models::RelayData::IncrementalAuthorization(_))
            | Some(relay_api_models::RelayData::Capture(_))
            | None => Err(errors::ApiErrorResponse::InvalidRequestData {
                message: "Relay data is required for relay type void".to_string(),
            })?,
        }
    }
}

pub struct RelayVoid;

#[async_trait]
impl RelayInterface for RelayVoid {
    type Request = relay_api_models::RelayVoidRequestData;

    fn get_domain_models(
        relay_request: RelayRequestInner<Self>,
        merchant_id: &id_type::MerchantId,
        profile_id: &id_type::ProfileId,
    ) -> relay::Relay {
        let relay_id = id_type::RelayId::generate();
        let relay_void: relay::RelayVoidData = relay_request.data.into();
        relay::Relay {
            id: relay_id.clone(),
            connector_resource_id: relay_request.connector_resource_id.clone(),
            connector_id: relay_request.connector_id.clone(),
            profile_id: profile_id.clone(),
            merchant_id: merchant_id.clone(),
            relay_type: common_enums::RelayType::Void,
            request_data: Some(relay::RelayData::Void(relay_void)),