Repository: juspay/hyperswitch
File: crates/payment_methods/src/client/retrieve.rs (Rust)

Code before:
        Ok(Self)
    }
}
impl TryFrom<RawPaymentMethodData> for PaymentMethodData {
    type Error = MicroserviceClientError;

    fn try_from(value: RawPaymentMethodData) -> Result<Self, Self::Error> {
        match value {
            RawPaymentMethodData::Card(card_data) => Ok(Self::CardDetailsForNetworkTransactionId(
                CardDetailsForNetworkTransactionId {
                    card_number: card_data.card_number,
                    card_exp_month: card_data.card_exp_month,
                    card_exp_year: card_data.card_exp_year,
                    card_issuer: card_data.card_issuer,
                    card_network: card_data.card_network,
                    card_type: card_data.card_type.map(|val| val.to_string()),
                    card_issuing_country: card_data.card_issuing_country,
                    card_issuing_country_code: None,
                    card_holder_name: card_data.card_holder_name,
                    bank_code: None,
                    nick_name: card_data.nick_name,
                },
            )),
        }
    }
}

impl TryFrom<ModularPMRetrieveResponse> for RetrievePaymentMethodResponse {
    type Error = MicroserviceClientError;

    fn try_from(v2_resp: ModularPMRetrieveResponse) -> Result<Self, Self::Error> {
        // Extract payment_method_id from GlobalPaymentMethodId
        let payment_method_id = v2_resp.id.clone();

        // Convert GlobalCustomerId to CustomerId
        let customer_id = v2_resp.customer_id;

        let raw_payment_method_data = match v2_resp.raw_payment_method_data {
            Some(raw_data) => Some(PaymentMethodData::try_from(raw_data)?),
            None => None,
        };

        Ok(Self {
            payment_method_id,
            merchant_id: v2_resp.merchant_id,
            customer_id,
            payment_method_type: v2_resp.payment_method_type,
            payment_method_subtype: v2_resp.payment_method_subtype,
            recurring_enabled: v2_resp.recurring_enabled,
            created: v2_resp.created,
            last_used_at: v2_resp.last_used_at,

Review comment (suggestion):
This conversation should be based on is cvc is none or some, right ?
If cvc is returned then construct `Self::Card` else `Self::CardDetailsForNetworkTransactionId`

Code after:

impl TryFrom<ModularPMRetrieveResponse> for RetrievePaymentMethodResponse {
    type Error = MicroserviceClientError;

    fn try_from(v2_resp: ModularPMRetrieveResponse) -> Result<Self, Self::Error> {
        // Extract payment_method_id from GlobalPaymentMethodId
        let payment_method_id = v2_resp.id.clone();

        // Convert GlobalCustomerId to CustomerId
        let customer_id = v2_resp.customer_id;

        Ok(Self {
            payment_method_id,
            merchant_id: v2_resp.merchant_id,
            customer_id,
            payment_method_type: v2_resp.payment_method_type,
            payment_method_subtype: v2_resp.payment_method_subtype,
            recurring_enabled: v2_resp.recurring_enabled,
            created: v2_resp.created,
            last_used_at: v2_resp.last_used_at,
            payment_method_data: v2_resp.payment_method_data,
            connector_tokens: v2_resp.connector_tokens,
            network_token: v2_resp.network_token,
            raw_payment_method_data: v2_resp.raw_payment_method_data,
        })
    }
}

impl RetrievePaymentMethod {
    fn validate_request(
        &self,
        request: &RetrievePaymentMethodV1Request,
    ) -> Result<(), MicroserviceClientError> {
        if request
            .payment_method_id
            .payment_method_id
            .trim()
            .is_empty()
        {
            return Err(MicroserviceClientError {
                operation: std::any::type_name::<Self>().to_string(),
                kind: MicroserviceClientErrorKind::InvalidRequest(
                    "Payment method ID cannot be empty".to_string(),
                ),
            });
        }
        Ok(())
    }

    fn build_path_params(
        &self,