Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation
Rust adyenbeginner-friendlyfeaturedfinancefintechhacktoberfesthigh-performanceopen-sourceorchestrationpaymentpayment-gatewaypayment-integrationpayment-processingpaymentspayments-platformrestful-apirustsdkstripeworks-with-react
fix(customers): resolve unimplemented payment method deletion in v2 (#11192)
Gaurav Rawat8e5d98de350f
diff --git a/crates/router/src/core/customers.rs b/crates/router/src/core/customers.rsindex 3f3b74b8d3..1399f64c8e 100644--- a/crates/router/src/core/customers.rs+++ b/crates/router/src/core/customers.rs@@ -1,4 +1,6 @@use api_models::customers::CustomerDocumentDetails;+#[cfg(feature = "v2")]+use api_models::payment_methods::PaymentMethodId;use common_types::primitive_wrappers::CustomerListLimit;use common_utils::{crypto::Encryptable,@@ -20,6 +22,8 @@ use router_env::{instrument, tracing};#[cfg(feature = "v2")]use crate::core::payment_methods::cards::create_encrypted_data;+#[cfg(feature = "v2")]+use crate::core::payment_methods::delete_payment_method_by_record;#[cfg(feature = "v1")]use crate::utils::CustomerAddress;use crate::{@@ -700,13 +704,20 @@ pub async fn list_customers_with_count(#[instrument(skip_all)]pub async fn delete_customer(state: SessionState,- provider: domain::Provider,+ platform: domain::Platform,id: id_type::GlobalCustomerId,+ profile: domain::Profile,) -> errors::CustomerResponse<customers::CustomerDeleteResponse> {let db = &*state.store;let key_manager_state = &(&state).into();- id.redact_customer_details_and_generate_response(db, &provider, key_manager_state, &state)- .await+ id.redact_customer_details_and_generate_response(+ db,+ &platform,+ key_manager_state,+ &state,+ profile,+ )+ .await}#[cfg(feature = "v2")]@@ -715,10 +726,12 @@ impl CustomerDeleteBridge for id_type::GlobalCustomerId {async fn redact_customer_details_and_generate_response<'a>(&'a self,db: &'a dyn StorageInterface,- provider: &'a domain::Provider,+ platform: &'a domain::Platform,key_manager_state: &'a KeyManagerState,state: &'a SessionState,+ profile: domain::Profile,) -> errors::CustomerResponse<customers::CustomerDeleteResponse> {+ let provider = platform.get_provider();let customer_orig = db.find_customer_by_global_id(self,@@ -742,27 +755,11 @@ impl CustomerDeleteBridge for id_type::GlobalCustomerId {.find_payment_method_list_by_global_customer_id(provider.get_key_store(), self, None).await{- // check this in reviewOk(customer_payment_methods) => {for pm in customer_payment_methods.into_iter() {- if pm.get_payment_method_type() == Some(enums::PaymentMethod::Card) {- cards::delete_card_by_locker_id(- state,- self,- provider.get_account().get_id(),- )+ delete_payment_method_by_record(db, state, platform, &profile, pm).await.switch()?;- }- // No solution as of now, need to discuss this further with payment_method_v2-- // db.delete_payment_method(- // key_manager_state,- // key_store,- // pm,- // )- // .await- // .switch()?;}}Err(error) => {@@ -839,7 +836,7 @@ impl CustomerDeleteBridge for id_type::GlobalCustomerId {Ok(services::ApplicationResponse::Json(response))}}-+#[cfg(feature = "v1")]#[async_trait::async_trait]trait CustomerDeleteBridge {async fn redact_customer_details_and_generate_response<'a>(@@ -850,6 +847,18 @@ trait CustomerDeleteBridge {state: &'a SessionState,) -> errors::CustomerResponse<customers::CustomerDeleteResponse>;}+#[cfg(feature = "v2")]+#[async_trait::async_trait]+trait CustomerDeleteBridge {+ async fn redact_customer_details_and_generate_response<'a>(+ &'a self,+ db: &'a dyn StorageInterface,+ platform: &'a domain::Platform,+ key_manager_state: &'a KeyManagerState,+ state: &'a SessionState,+ profile: domain::Profile,+ ) -> errors::CustomerResponse<customers::CustomerDeleteResponse>;+}#[cfg(feature = "v1")]#[instrument(skip_all)]diff --git a/crates/router/src/core/payment_methods.rs b/crates/router/src/core/payment_methods.rsindex e4f3b5010d..d5396f4f07 100644--- a/crates/router/src/core/payment_methods.rs+++ b/crates/router/src/core/payment_methods.rs@@ -4239,7 +4239,10 @@ pub async fn delete_payment_method(let pm_id = id_type::GlobalPaymentMethodId::generate_from_string(pm_id.payment_method_id).change_context(errors::ApiErrorResponse::InternalServerError).attach_printable("Unable to generate GlobalPaymentMethodId")?;- let response = delete_payment_method_core(&state, pm_id, &platform, &profile).await?;+ let response = Box::pin(delete_payment_method_core(+ &state, pm_id, &platform, &profile,+ ))+ .await?;Ok(services::ApplicationResponse::Json(response))}@@ -4283,6 +4286,22 @@ pub async fn delete_payment_method_core(.to_not_found_response(errors::ApiErrorResponse::InternalServerError).attach_printable("Customer not found for the payment method")?;+ delete_payment_method_by_record(db, state, platform, profile, payment_method).await?;++ let response = api::PaymentMethodDeleteResponse { id: pm_id };++ Ok(response)+}++#[cfg(feature = "v2")]+#[instrument(skip_all)]+pub async fn delete_payment_method_by_record(+ db: &dyn StorageInterface,+ state: &SessionState,+ platform: &domain::Platform,+ profile: &domain::Profile,+ payment_method: domain::PaymentMethod,+) -> RouterResult<()> {// Soft deletelet pm_update = storage::PaymentMethodUpdate::StatusAndFingerprintUpdate {status: Some(enums::PaymentMethodStatus::Inactive),@@ -4305,9 +4324,7 @@ pub async fn delete_payment_method_core(.change_context(errors::ApiErrorResponse::InternalServerError).attach_printable("Failed to delete payment method from vault")?;- let response = api::PaymentMethodDeleteResponse { id: pm_id };-- Ok(response)+ Ok(())}#[cfg(feature = "v2")]@@ -4756,9 +4773,14 @@ pub async fn payment_methods_session_delete_payment_method("Failed to retrieve payment method id from payment method token data",)?;- delete_payment_method_core(&state, payment_method_id, &platform, &profile)- .await- .attach_printable("Failed to delete saved payment method")?;+ Box::pin(delete_payment_method_core(+ &state,+ payment_method_id,+ &platform,+ &profile,+ ))+ .await+ .attach_printable("Failed to delete saved payment method")?;Ok(services::ApplicationResponse::Json(payment_methods::PaymentMethodDeleteSessionResponse {diff --git a/crates/router/src/routes/customers.rs b/crates/router/src/routes/customers.rsindex a56945f253..b278c9f6f9 100644--- a/crates/router/src/routes/customers.rs+++ b/crates/router/src/routes/customers.rs@@ -388,7 +388,7 @@ pub async fn customers_delete(&req,id,|state, auth: auth::AuthenticationData, id, _| {- delete_customer(state, auth.platform.get_provider().clone(), id)+ delete_customer(state, auth.platform, id, auth.profile)},auth::auth_type(&auth::V2ApiKeyAuth {