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

Code before:
                    db.update_payment_method(
                        &((&state).into()),
                        merchant_context.get_merchant_key_store(),
                        payment_method,
                        pm_update,
                        merchant_context.get_merchant_account().storage_scheme,
                    )
                    .await
                    .change_context(errors::ApiErrorResponse::InternalServerError)
                    .attach_printable("Failed to update payment method in db")?;

                    return Err(e.attach_printable("Failed to add card to locker"));
                }
            }
        }
    }
}

#[cfg(feature = "v1")]
#[instrument(skip_all)]
pub async fn update_customer_payment_method(
    state: routes::SessionState,
    merchant_context: domain::MerchantContext,
    req: api::PaymentMethodUpdate,
    payment_method_id: &str,
    pm_fetch: Option<common_enums::enums::PaymentMethodFetch>,
) -> errors::RouterResponse<api::PaymentMethodResponse> {
    // Currently update is supported only for cards
    if let Some(card_update) = req.card.clone() {
        let db = state.store.as_ref();

        let pm = db
            .find_payment_method(
                &((&state).into()),
                merchant_context.get_merchant_key_store(),
                payment_method_id,
                merchant_context.get_merchant_account().storage_scheme,
            )
            .await
            .to_not_found_response(errors::ApiErrorResponse::PaymentMethodNotFound)?;

        if let Some(fetch) = pm_fetch {
            if matches!(fetch, common_enums::enums::PaymentMethodFetch::Fetch)
                && pm.locker_id.is_some()
            {
                return Err(report!(errors::ApiErrorResponse::NotSupported {
                    message:
                        "Cannot proceed to update Payment Method when locker_id is already present"
                            .into(),
                }));
            }

Review comment (suggestion):
```suggestion
    pm_data: Option<domain::PaymentMethod>,
```

Code after:
                    let pm_update = storage::PaymentMethodUpdate::StatusUpdate {
                        status: Some(enums::PaymentMethodStatus::Inactive),
                    };

                    db.update_payment_method(
                        &((&state).into()),
                        merchant_context.get_merchant_key_store(),
                        payment_method,
                        pm_update,
                        merchant_context.get_merchant_account().storage_scheme,
                    )
                    .await
                    .change_context(errors::ApiErrorResponse::InternalServerError)
                    .attach_printable("Failed to update payment method in db")?;

                    return Err(e.attach_printable("Failed to add card to locker"));
                }
            }
        }
    }
}

#[cfg(feature = "v1")]
#[instrument(skip_all)]
pub async fn update_customer_payment_method(
    state: routes::SessionState,
    merchant_context: domain::MerchantContext,
    req: api::PaymentMethodUpdate,
    payment_method_id: &str,

    pm_data: Option<domain::PaymentMethod>,
) -> errors::RouterResponse<api::CustomerPaymentMethodUpdateResponse> {
    let db = state.store.as_ref();

    let pm = if let Some(pm) = pm_data {
        pm
    } else {
        db.find_payment_method(
            &((&state).into()),
            merchant_context.get_merchant_key_store(),
            payment_method_id,
            merchant_context.get_merchant_account().storage_scheme,
        )
        .await
        .to_not_found_response(errors::ApiErrorResponse::PaymentMethodNotFound)?
    };

    if let Some(cs) = &req.client_secret {
        let is_client_secret_expired = authenticate_pm_client_secret_and_check_expiry(cs, &pm)?;

        if is_client_secret_expired {