Skip to content

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

fix(payment_methods): match vault delete entity_id to the add-flow scheme (#13423)

Shankar Singh C578b7cb066b3
diff --git a/crates/hyperswitch_domain_models/src/errors/api_error_response.rs b/crates/hyperswitch_domain_models/src/errors/api_error_response.rs
index 5bf493ed7b..cbaf297e9e 100644
--- a/crates/hyperswitch_domain_models/src/errors/api_error_response.rs
+++ b/crates/hyperswitch_domain_models/src/errors/api_error_response.rs
@@ -203,6 +203,8 @@ pub enum ApiErrorResponse {
MandateActive,
#[error(error_type = ErrorType::InvalidRequestError, code = "IR_11", message = "Customer has already been redacted")]
CustomerRedacted,
+ #[error(error_type = ErrorType::InvalidRequestError, code = "IR_11", message = "Payment method has already been redacted")]
+ PaymentMethodRedacted,
#[error(error_type = ErrorType::InvalidRequestError, code = "IR_12", message = "Reached maximum refund attempts")]
MaximumRefundCount,
#[error(error_type = ErrorType::InvalidRequestError, code = "IR_13", message = "The refund amount exceeds the amount captured")]
@@ -595,6 +597,9 @@ impl ErrorSwitch<api_models::errors::types::ApiErrorResponse> for ApiErrorRespon
Self::CustomerRedacted => {
AER::BadRequest(ApiError::new("IR", 11, "Customer has already been redacted", None))
}
+ Self::PaymentMethodRedacted => {
+ AER::BadRequest(ApiError::new("IR", 11, "Payment method has already been redacted", None))
+ }
Self::MaximumRefundCount => AER::BadRequest(ApiError::new("IR", 12, "Reached maximum refund attempts", None)),
Self::RefundAmountExceedsPaymentAmount => {
AER::BadRequest(ApiError::new("IR", 13, "The refund amount exceeds the amount captured", None))
diff --git a/crates/router/src/compatibility/stripe/errors.rs b/crates/router/src/compatibility/stripe/errors.rs
index 5f794b2697..4ece22d204 100644
--- a/crates/router/src/compatibility/stripe/errors.rs
+++ b/crates/router/src/compatibility/stripe/errors.rs
@@ -78,6 +78,9 @@ pub enum StripeErrorCode {
#[error(error_type = StripeErrorType::InvalidRequestError, code = "customer_redacted", message = "Customer has redacted")]
CustomerRedacted,
+ #[error(error_type = StripeErrorType::InvalidRequestError, code = "payment_method_redacted", message = "Payment method has already been redacted")]
+ PaymentMethodRedacted,
+
#[error(error_type = StripeErrorType::InvalidRequestError, code = "customer_already_exists", message = "Customer with the given customer_id already exists")]
DuplicateCustomer,
@@ -541,6 +544,7 @@ impl From<errors::ApiErrorResponse> for StripeErrorCode {
}
errors::ApiErrorResponse::MandateActive => Self::MandateActive, //not a stripe code
errors::ApiErrorResponse::CustomerRedacted => Self::CustomerRedacted, //not a stripe code
+ errors::ApiErrorResponse::PaymentMethodRedacted => Self::PaymentMethodRedacted, //not a stripe code
errors::ApiErrorResponse::ConfigNotFound => Self::ConfigNotFound, // not a stripe code
errors::ApiErrorResponse::DuplicateConfig => Self::DuplicateConfig, // not a stripe code
errors::ApiErrorResponse::DuplicateRefundRequest => Self::DuplicateRefundRequest,
@@ -798,6 +802,7 @@ impl actix_web::ResponseError for StripeErrorCode {
| Self::InternalServerError
| Self::MandateActive
| Self::CustomerRedacted
+ | Self::PaymentMethodRedacted
| Self::WebhookProcessingError
| Self::InvalidTenant
| Self::ExternalVaultFailed
diff --git a/crates/router/src/core/payment_methods.rs b/crates/router/src/core/payment_methods.rs
index d72725e9bd..c335e38d8e 100644
--- a/crates/router/src/core/payment_methods.rs
+++ b/crates/router/src/core/payment_methods.rs
@@ -1907,17 +1907,35 @@ impl LockerOperations for GenericLocker {
async fn delete_payment_method_from_locker(
&self,
state: &SessionState,
- _platform: &domain::Platform,
+ platform: &domain::Platform,
vault_id: domain::VaultId,
customer_id: &id_type::GlobalCustomerId,
) -> CustomResult<pm_types::VaultDeleteResponse, errors::VaultError> {
- let payload = pm_types::VaultDeleteRequest {
- entity_id: customer_id.to_owned(),
- vault_id,
- }
- .encode_to_vec()
- .change_context(errors::VaultError::RequestEncodingFailed)
- .attach_printable("Failed to encode VaultDeleteRequest")?;
+ let should_trigger_fingerprint_migration =
+ payment_method_utils::get_should_trigger_fingerprint_migration(
+ state,
+ None,
+ platform.get_provider().get_provider_merchant_id(),
+ )
+ .await;
+
+ let payload = if should_trigger_fingerprint_migration {
+ pm_types::VaultDeleteRequestNew {
+ entity_id: platform.get_provider().get_account().get_id().clone(),
+ vault_id,
+ }
+ .encode_to_vec()
+ .change_context(errors::VaultError::RequestEncodingFailed)
+ .attach_printable("Failed to encode VaultDeleteRequestNew")?
+ } else {
+ pm_types::VaultDeleteRequest {
+ entity_id: customer_id.to_owned(),
+ vault_id,
+ }
+ .encode_to_vec()
+ .change_context(errors::VaultError::RequestEncodingFailed)
+ .attach_printable("Failed to encode VaultDeleteRequest")?
+ };
let resp = vault::call_to_vault::<pm_types::VaultDelete>(state, payload, None, None)
.await
@@ -6126,6 +6144,11 @@ pub async fn delete_payment_method_core(
|| Err(errors::ApiErrorResponse::PaymentMethodNotFound),
)?;
+ when(
+ payment_method.status == enums::PaymentMethodStatus::Redacted,
+ || Err(errors::ApiErrorResponse::PaymentMethodRedacted),
+ )?;
+
let _customer = db
.find_customer_by_global_id_merchant_id(
customer_id,
diff --git a/crates/router/src/types/payment_methods.rs b/crates/router/src/types/payment_methods.rs
index 0f1eacf171..0f47692d78 100644
--- a/crates/router/src/types/payment_methods.rs
+++ b/crates/router/src/types/payment_methods.rs
@@ -233,6 +233,12 @@ pub struct VaultDeleteRequest {
pub vault_id: domain::VaultId,
}
+#[derive(Debug, serde::Deserialize, serde::Serialize)]
+pub struct VaultDeleteRequestNew {
+ pub entity_id: id_type::MerchantId,
+ pub vault_id: domain::VaultId,
+}
+
#[cfg(feature = "v2")]
#[derive(Debug, serde::Deserialize, serde::Serialize)]
pub struct VaultDeleteResponse {