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

Code before:
        last_modified_by: None,
    };

    db.update_payment_method(key_store, pm, pm_update, storage_scheme)
        .await
        .change_context(errors::VaultError::UpdateInPaymentMethodDataTableFailed)?;
    Ok(())
}

#[cfg(feature = "v1")]
#[allow(clippy::too_many_arguments)]
pub async fn update_payment_method_connector_mandate_details_and_network_token_data(
    key_store: &domain::MerchantKeyStore,
    db: &dyn db::StorageInterface,
    pm: domain::PaymentMethod,
    connector_mandate_details: Option<CommonMandateReference>,
    network_token_requestor_reference_id: Option<String>,
    network_token_locker_id: Option<String>,
    pm_network_token_data_encrypted: Option<Encryptable<Secret<serde_json::Value>>>,
    storage_scheme: MerchantStorageScheme,
) -> errors::CustomResult<(), errors::VaultError> {
    let connector_mandate_details_value = connector_mandate_details
        .map(|common_mandate| {
            common_mandate.get_mandate_details_value().map_err(|err| {
                router_env::logger::error!("Failed to get get_mandate_details_value : {:?}", err);
                errors::VaultError::UpdateInPaymentMethodDataTableFailed
            })
        })
        .transpose()?;
    let pm_update = payment_method::PaymentMethodUpdate::AdditionalDataUpdate {
        locker_id: None,
        payment_method_data: None,
        status: None,
        payment_method: None,
        payment_method_type: None,
        payment_method_issuer: None,
        network_token_requestor_reference_id,
        network_token_locker_id,
        network_token_payment_method_data: pm_network_token_data_encrypted.map(Into::into),
        last_modified_by: None,
        metadata: None,
        last_used_at: None,
        connector_mandate_details: connector_mandate_details_value,
    };

    db.update_payment_method(key_store, pm, pm_update, storage_scheme)
        .await
        .change_context(errors::VaultError::UpdateInPaymentMethodDataTableFailed)?;
    Ok(())
}
#[instrument(skip_all)]

Review comment (bug):
```suggestion
                errors::VaultError::UpdateInPaymentMethodTableFailed
```


Code after:
    key_store: &domain::MerchantKeyStore,
    db: &dyn db::StorageInterface,
    pm: domain::PaymentMethod,
    network_token_requestor_reference_id: Option<String>,
    network_token_locker_id: Option<String>,
    pm_network_token_data_encrypted: Option<Encryptable<Secret<serde_json::Value>>>,
    storage_scheme: MerchantStorageScheme,
) -> errors::CustomResult<(), errors::VaultError> {
    let pm_update = payment_method::PaymentMethodUpdate::NetworkTokenDataUpdate {
        network_token_requestor_reference_id,
        network_token_locker_id,
        network_token_payment_method_data: pm_network_token_data_encrypted.map(Into::into),
        last_modified_by: None,
    };

    db.update_payment_method(key_store, pm, pm_update, storage_scheme)
        .await
        .change_context(errors::VaultError::UpdateInPaymentMethodTableFailed)?;
    Ok(())
}

pub async fn update_payment_method_and_last_used(
    key_store: &domain::MerchantKeyStore,
    db: &dyn db::StorageInterface,
    pm: domain::PaymentMethod,
    payment_method_update: Option<Encryption>,
    storage_scheme: MerchantStorageScheme,
    card_scheme: Option<String>,
) -> errors::CustomResult<(), errors::VaultError> {
    let pm_update = payment_method::PaymentMethodUpdate::UpdatePaymentMethodDataAndLastUsed {
        payment_method_data: payment_method_update,
        scheme: card_scheme,
        last_used_at: common_utils::date_time::now(),
        last_modified_by: None,
    };
    db.update_payment_method(key_store, pm, pm_update, storage_scheme)
        .await
        .change_context(errors::VaultError::UpdateInPaymentMethodTableFailed)?;
    Ok(())
}

#[cfg(feature = "v2")]
pub async fn update_payment_method_connector_mandate_details(
    state: &routes::SessionState,
    key_store: &domain::MerchantKeyStore,
    db: &dyn db::StorageInterface,
    pm: domain::PaymentMethod,
    connector_mandate_details: Option<CommonMandateReference>,
    storage_scheme: MerchantStorageScheme,
) -> errors::CustomResult<(), errors::VaultError> {
    let pm_update = payment_method::PaymentMethodUpdate::ConnectorMandateDetailsUpdate {