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

Code before:
        let request = &raw_payment.item.router_data.request;

        match raw_payment.raw_payout_method_data {
            payouts::PayoutMethodData::Wallet(_)
            | payouts::PayoutMethodData::BankRedirect(_)
            | payouts::PayoutMethodData::Passthrough(_) => Err(ConnectorError::NotImplemented(
                utils::get_unimplemented_payment_method_error_message("Adyenplatform"),
            ))?,
            payouts::PayoutMethodData::Card(c) => {
                let card_holder: AdyenAccountHolder =
                    (raw_payment.item.router_data, &c).try_into()?;

                let card_identification =
                    AdyenCardIdentification::Card(AdyenRawCardIdentification {
                        expiry_year: c.get_expiry_year_4_digit(),
                        card_number: c.card_number,
                        expiry_month: c.expiry_month,
                        issue_number: None,
                        start_month: None,
                        start_year: None,
                    });

                let counterparty = AdyenPayoutMethodDetails::Card(AdyenCardDetails {
                    card_holder,
                    card_identification,
                });

                Ok((counterparty, None))
            }
            payouts::PayoutMethodData::Bank(bd) => {
                let account_holder: AdyenAccountHolder =
                    (raw_payment.item.router_data, &bd).try_into()?;
                let bank_details = match bd {
                    payouts::Bank::Sepa(b) => AdyenBankAccountIdentification {
                        bank_type: "iban".to_string(),
                        account_details: AdyenBankAccountIdentificationDetails::Sepa(SepaDetails {
                            iban: b.iban,
                        }),
                    },
                    payouts::Bank::Ach(..) => Err(ConnectorError::NotSupported {
                        message: "Bank transfer via ACH is not supported".to_string(),
                        connector: "Adyenplatform",
                    })?,
                    payouts::Bank::Bacs(..) => Err(ConnectorError::NotSupported {
                        message: "Bank transfer via Bacs is not supported".to_string(),
                        connector: "Adyenplatform",
                    })?,
                    payouts::Bank::Pix(..) => Err(ConnectorError::NotSupported {
                        message: "Bank transfer via Pix is not supported".to_string(),
                        connector: "Adyenplatform",
                    })?,

Review comment (suggestion):
nit:

```suggestion
let should_fallback = billing_first_name
    .as_ref()
    .map_or(true, |s| s.peek().trim().is_empty())
    || billing_last_name
        .as_ref()
        .map_or(true, |s| s.peek().trim().is_empty())
```

Code after:
}

impl<F> TryFrom<&PayoutsRouterData<F>> for Name {
    type Error = Error;
    fn try_from(router_data: &PayoutsRouterData<F>) -> Result<Self, Self::Error> {
        let card_holder_name = router_data
            .request
            .get_optional_additional_payout_method_data()
            .and_then(|additional_data| additional_data.get_optional_card_holder_name());

        let billing_first_name = router_data
            .get_optional_billing_first_name()
            .map(|first_name| Secret::new(first_name.peek().trim().to_string()));
        let billing_last_name = router_data
            .get_optional_billing_last_name()
            .map(|last_name| Secret::new(last_name.peek().trim().to_string()));

        let mut should_fallback = billing_first_name.is_none() || billing_last_name.is_none();
        //check for empty first name
        billing_first_name.clone().inspect(|first_name| {
            should_fallback = first_name.peek().is_empty() || should_fallback;
        });
        // check for empty last name
        billing_last_name.clone().inspect(|last_name| {
            should_fallback = last_name.peek().is_empty() || should_fallback;
        });

        // get first_name from the billing
        // if not present in billing, get from card_holder_name
        let first_name = if should_fallback {
            card_holder_name.clone().and_then(|full_name| {
                let mut name_collection = full_name.peek().split_whitespace();
                name_collection
                    .next()
                    .map(|first_name| Secret::new(first_name.to_string()))
            })
        } else {
            billing_first_name
        };

        // get last_name from the billing
        // if not present in billing, get from card_holder_name
        let last_name = if should_fallback {
            card_holder_name.map(|full_name| {
                let mut name_collection = full_name.peek().split_whitespace();
                let _first_name = name_collection.next();

                Secret::new(name_collection.collect::<Vec<_>>().join(" "))
            })
        } else {
            billing_last_name