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

Code before:
        }
    }
}

impl<const T: u8> TryFrom<&DummyConnectorRouterData<&PaymentsAuthorizeRouterData>>
    for DummyConnectorPaymentsRequest<T>
{
    type Error = error_stack::Report<ConnectorError>;
    fn try_from(
        item: &DummyConnectorRouterData<&PaymentsAuthorizeRouterData>,
    ) -> Result<Self, Self::Error> {
        let payment_method_data: Result<DummyPaymentMethodData, Self::Error> =
            match item.router_data.request.payment_method_data {
                PaymentMethodData::Card(ref req_card) => {
                    let card_holder_name = item.router_data.get_optional_billing_full_name();
                    Ok(DummyPaymentMethodData::Card(DummyConnectorCard::try_from(
                        (req_card.clone(), card_holder_name),
                    )?))
                }
                PaymentMethodData::Upi(ref req_upi_data) => match req_upi_data {
                    UpiData::UpiCollect(data) => Ok(DummyPaymentMethodData::Upi(
                        DummyConnectorUpi::try_from(data.clone())?,
                    )),
                    UpiData::UpiIntent(_) => {
                        Err(ConnectorError::NotImplemented("UPI Intent".to_string()).into())
                    }
                    UpiData::UpiQr(_) => {
                        Err(ConnectorError::NotImplemented("UPI QR".to_string()).into())
                    }
                },
                PaymentMethodData::Wallet(ref wallet_data) => Ok(DummyPaymentMethodData::Wallet(
                    wallet_data.clone().try_into()?,
                )),
                PaymentMethodData::PayLater(ref pay_later_data) => Ok(
                    DummyPaymentMethodData::PayLater(pay_later_data.clone().try_into()?),
                ),
                _ => Err(ConnectorError::NotImplemented("Payment methods".to_string()).into()),
            };
        Ok(Self {
            amount: item.router_data.request.minor_amount,
            currency: item.router_data.request.currency,
            payment_method_data: payment_method_data?,
            return_url: item.router_data.request.router_return_url.clone(),
            connector: Into::<DummyConnectors>::into(T),
        })
    }
}

// Auth Struct
pub struct DummyConnectorAuthType {
    pub(super) api_key: Secret<String>,

Review comment (refactor):
You can simplify this by combining both using |
```suggestion
                   UpiData::UpiIntent(_) | UpiData::UpiQr(_) => {
    Err(ConnectorError::NotImplemented("UPI flow".to_string()).into())
}

```

Code after:
        }
    }
}

impl<const T: u8> TryFrom<&DummyConnectorRouterData<&PaymentsAuthorizeRouterData>>
    for DummyConnectorPaymentsRequest<T>
{
    type Error = error_stack::Report<ConnectorError>;
    fn try_from(
        item: &DummyConnectorRouterData<&PaymentsAuthorizeRouterData>,
    ) -> Result<Self, Self::Error> {
        let payment_method_data: Result<DummyPaymentMethodData, Self::Error> =
            match item.router_data.request.payment_method_data {
                PaymentMethodData::Card(ref req_card) => {
                    let card_holder_name = item.router_data.get_optional_billing_full_name();
                    Ok(DummyPaymentMethodData::Card(DummyConnectorCard::try_from(
                        (req_card.clone(), card_holder_name),
                    )?))
                }
                PaymentMethodData::Upi(ref req_upi_data) => match req_upi_data {
                    UpiData::UpiCollect(data) => Ok(DummyPaymentMethodData::Upi(
                        DummyConnectorUpi::try_from(data.clone())?,
                    )),
                    UpiData::UpiIntent(_) | UpiData::UpiQr(_) => {
                        Err(ConnectorError::NotImplemented("UPI flow".to_string()).into())
                    }
                },
                PaymentMethodData::Wallet(ref wallet_data) => Ok(DummyPaymentMethodData::Wallet(
                    wallet_data.clone().try_into()?,
                )),
                PaymentMethodData::PayLater(ref pay_later_data) => Ok(
                    DummyPaymentMethodData::PayLater(pay_later_data.clone().try_into()?),
                ),
                _ => Err(ConnectorError::NotImplemented("Payment methods".to_string()).into()),
            };
        Ok(Self {
            amount: item.router_data.request.minor_amount,
            currency: item.router_data.request.currency,
            payment_method_data: payment_method_data?,
            return_url: item.router_data.request.router_return_url.clone(),
            connector: Into::<DummyConnectors>::into(T),
        })
    }
}

// Auth Struct
pub struct DummyConnectorAuthType {
    pub(super) api_key: Secret<String>,
}

impl TryFrom<&ConnectorAuthType> for DummyConnectorAuthType {