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

Code before:
        .associated_payment_methods
        .as_ref()
        .and_then(|payment_methods| {
            payment_methods.iter().find(|pm| match &pm.token {
                common_types::payment_methods::AssociatedPaymentMethodTokenType::PaymentMethodSessionToken(token) => token == &request.payment_method_token       
            })
        })
        .ok_or(errors::ApiErrorResponse::GenericNotFoundError {
            message: "No associated payment method found in the session".to_string(),
        })?;

    let payment_token_data = utils::retrieve_payment_token_data(
        &state,
        request.payment_method_token.clone(),
        Some(&associated_pm_token_details.payment_method_type),
    )
    .await
    .attach_printable("Failed to retrieve payment token data")?;

    let payment_method_id = match payment_token_data {
        storage::payment_method::PaymentTokenData::PermanentCard(card) => {
            Some(card.payment_method_id)
        }
        _ => None,
    }
    .get_required_value("payment_method_id from payment token data")
    .attach_printable("Failed to get payment method id from payment token data")?;

    let payment_method_update_request = request.payment_method_update_request.clone();

    Box::pin(update_payment_method_core(
        &state,
        &platform,
        &profile,
        payment_method_update_request,
        &payment_method_id,
    ))
    .await
    .attach_printable("Failed to update saved payment method")?;

    let mut card_cvc_token = None;

    if let Some(api::PaymentMethodUpdateData::Card(ref card_data)) =
        request.payment_method_update_request.payment_method_data
    {
        let token = if let Some(cvc) = card_data.card_cvc.clone() {
            Some(
                vault::insert_cvc_using_payment_token(
                    &state,
                    &request.payment_method_token,
                    cvc,

Review comment (suggestion):
```suggestion
    .get_required_value("payment_method_id from payment method token data")
```

Code after:
    payment_method_session_id: id_type::GlobalPaymentMethodSessionId,
    request: payment_methods::PaymentMethodSessionUpdateSavedPaymentMethod,
) -> RouterResponse<payment_methods::PaymentMethodSessionResponse> {
    let db = state.store.as_ref();

    // Validate if the session still exists
    let payment_method_session = db
        .get_payment_methods_session(
            platform.get_provider().get_key_store(),
            &payment_method_session_id,
        )
        .await
        .to_not_found_response(errors::ApiErrorResponse::GenericNotFoundError {
            message: "payment methods session does not exist or has expired".to_string(),
        })
        .attach_printable("Failed to retrieve payment methods session from db")?;

    // Get the associated_pm_token_details for the payment_method_token from the request
    let associated_pm_token_details = payment_method_session
        .associated_payment_methods
        .as_ref()
        .and_then(|payment_methods| {
            payment_methods.iter().find(|pm| match &pm.payment_method_token {
                common_types::payment_methods::AssociatedPaymentMethodTokenType::PaymentMethodSessionToken(token) => token == &request.payment_method_token
            })
        })
        .ok_or(errors::ApiErrorResponse::GenericNotFoundError {
            message: "No associated payment method found in the session".to_string(),
        })?;

    let payment_method_token_data =
        utils::retrieve_payment_token_data(&state, request.payment_method_token.clone())
            .await
            .attach_printable("Failed to retrieve payment method token data")?;

    let payment_method_id = match payment_method_token_data {
        storage::payment_method::PaymentTokenData::PermanentCard(card) => {
            Some(card.payment_method_id)
        }
        _ => None,
    }
    .get_required_value("payment_method_id from payment method token data")
    .attach_printable("Failed to get payment method id from payment method token data")?;

    let payment_method_update_request = request.payment_method_update_request.clone();

    Box::pin(update_payment_method_core(
        &state,
        &platform,
        &profile,
        payment_method_update_request,