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

Code before:
            };
        };

        if pm.payment_method != Some(common_enums::PaymentMethod::Wallet) {
            return Err((errors::ApiErrorResponse::InvalidRequestdata {
                message: "The Payment Method is not wallet",
            })
            .into());
        }

        let updated_pmd = PaymentMethodsData::WalletDetails(wallet_update);
        let key_manager_state = (&state).into();
        let pm_data_encrypted = create_encrypted_data(
            &key_manager_state,
            merchant_context.get_merchant_key_store(),
            updated_pmd,
        )
        .await
        .change_context(errors::ApiErrorResponse::InternalServerError)
        .attach_printable("Unable to encrypt payment method data")?;

        let pm_update = storage::PaymentMethodUpdate::PaymentMethodDataUpdate {
            payment_method_data: Some(pm_data_encrypted.into()),
        };

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

        Ok(services::ApplicationResponse::Json(
            api::PaymentMethodResponse {
                merchant_id: pm.merchant_id.to_owned(),
                customer_id: Some(pm.customer_id.clone()),
                payment_method_id: pm.payment_method_id.clone(),
                payment_method: pm.get_payment_method_type(),
                payment_method_type: pm.get_payment_method_subtype(),
                #[cfg(feature = "payouts")]
                bank_transfer: None,
                card: None,
                metadata: pm.metadata,
                created: Some(pm.created_at),
                recurring_enabled: Some(false),
                installment_payment_enabled: Some(false),
                payment_experience: Some(vec![api_models::enums::PaymentExperience::RedirectToUrl]),

Review comment (suggestion):
```suggestion
        let pm = db.update_payment_method(
```

Code after:
                installment_payment_enabled: Some(false),
                payment_experience: Some(vec![api_models::enums::PaymentExperience::RedirectToUrl]),
                last_used_at: Some(common_utils::date_time::now()),
                client_secret: pm.client_secret.clone(),
            }
        };

        Ok(services::ApplicationResponse::Json(response))
    } else if let Some(wallet_update) = req.wallet.clone() {
        if pm.payment_method != Some(common_enums::PaymentMethod::Wallet) {
            return Err((errors::ApiErrorResponse::InvalidRequestData {
                message: "The Payment Method is not wallet".to_string(),
            })
            .into());
        }

        let updated_pmd = PaymentMethodsData::WalletDetails(wallet_update);
        let key_manager_state = (&state).into();
        let pm_data_encrypted = create_encrypted_data(
            &key_manager_state,
            merchant_context.get_merchant_key_store(),
            updated_pmd,
        )
        .await
        .change_context(errors::ApiErrorResponse::InternalServerError)
        .attach_printable("Unable to encrypt payment method data")?;

        let pm_update = storage::PaymentMethodUpdate::PaymentMethodDataUpdate {
            payment_method_data: Some(pm_data_encrypted.into()),
        };

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

        Ok(services::ApplicationResponse::Json(
            api::CustomerPaymentMethodUpdateResponse {
                merchant_id: pm.merchant_id.to_owned(),
                customer_id: Some(pm.customer_id.clone()),
                payment_method_id: pm.payment_method_id.clone(),
                payment_method: pm.get_payment_method_type(),
                payment_method_type: pm.get_payment_method_subtype(),
                #[cfg(feature = "payouts")]