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

Code before:
                merchant_key_store,
                &customer.as_ref().unwrap().customer_id,
                &merchant_key_store.merchant_id,
                &bank_debit.locker_id.as_ref().unwrap(),
            )
            .await?;

            let (account_number, routing_number) = match data {
                payment_methods::BankDebitCreateData::ACH {
                    account_number,
                    routing_number,
                } => (account_number, routing_number),
            };

            storage::PaymentMethodDataWithId {
                payment_method: Some(enums::PaymentMethod::BankDebit),
                payment_method_data: Some(
                    hyperswitch_domain_models::payment_method_data::PaymentMethodData::BankDebit(
                        BankDebitData::AchBankDebit {
                            account_number,
                            routing_number,
                            card_holder_name: None,
                            bank_account_holder_name: None,
                            bank_name: None,
                            bank_type: None,
                            bank_holder_type: None,
                        },
                    ),
                ),

                payment_method_id: Some(bank_debit.payment_method_id.clone()),
            }
        }
    };
    Ok(token)
}

#[cfg(feature = "v2")]
#[instrument(skip_all)]
pub(crate) fn get_payment_method_create_request(
    payment_method_data: &api_models::payments::PaymentMethodData,
    payment_method_type: storage_enums::PaymentMethod,
    payment_method_subtype: storage_enums::PaymentMethodType,
    customer_id: id_type::GlobalCustomerId,
    billing_address: Option<&api_models::payments::Address>,
    payment_method_session: Option<&domain::payment_methods::PaymentMethodSession>,
) -> RouterResult<payment_methods::PaymentMethodCreate> {
    match payment_method_data {
        api_models::payments::PaymentMethodData::Card(card) => {
            let card_detail = payment_methods::CardDetail {
                card_number: card.card_number.clone(),

Review comment (suggestion):
We can populate these details using the `payment_method_info` that is input to `retrieve_payment_method_with_token`.

Code after:
                customer
                    .as_ref()
                    .ok_or(errors::ApiErrorResponse::MissingRequiredField {
                        field_name: "customer",
                    })?;

            let locker_id = bank_debit.locker_id.as_ref().ok_or(
                errors::ApiErrorResponse::MissingRequiredField {
                    field_name: "locker_id",
                },
            )?;

            let bank_debit_detail = cards::get_bank_debit_from_hs_locker(
                state,
                merchant_key_store,
                &customer.customer_id,
                &merchant_key_store.merchant_id,
                locker_id,
            )
            .await?;

            let (account_number, routing_number) = match bank_debit_detail {
                payment_methods::BankDebitDetail::Ach {
                    account_number,
                    routing_number,
                } => (account_number, routing_number),
            };

            let payment_method_data = payment_method_info
                .get_required_value("PaymentMethod")
                .change_context(errors::ApiErrorResponse::InternalServerError)
                .attach_printable("PaymentMethod not found")?;

            let (
                card_holder_name,
                bank_account_holder_name,
                bank_name,
                bank_type,
                bank_holder_type,
            ) = if let Some(
                hyperswitch_domain_models::payment_method_data::PaymentMethodsData::BankDebit(
                    bank_debit_data,
                ),
            ) = payment_method_data.get_payment_methods_data()
            {
                use hyperswitch_domain_models::payment_method_data::BankDebitDetailsPaymentMethod;

                let BankDebitDetailsPaymentMethod::AchBankDebit {
                    masked_account_number: _,
                    masked_routing_number: _,
                    card_holder_name,