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(merchant_connector_account): add validation for the `disabled` flag (#1141)

Nishant Joshi600dc338673c
diff --git a/crates/router/src/compatibility/stripe/errors.rs b/crates/router/src/compatibility/stripe/errors.rs
index 91d95e8a8f..760bd84bfd 100644
--- a/crates/router/src/compatibility/stripe/errors.rs
+++ b/crates/router/src/compatibility/stripe/errors.rs
@@ -91,6 +91,9 @@ pub enum StripeErrorCode {
#[error(error_type = StripeErrorType::InvalidRequestError, code = "resource_missing", message = "Merchant connector account with id '{id}' does not exist in our records")]
MerchantConnectorAccountNotFound { id: String },
+ #[error(error_type = StripeErrorType::InvalidRequestError, code = "invalid_request", message = "The merchant connector account is disabled")]
+ MerchantConnectorAccountDisabled,
+
#[error(error_type = StripeErrorType::InvalidRequestError, code = "resource_missing", message = "No such mandate")]
MandateNotFound,
@@ -491,6 +494,9 @@ impl From<errors::ApiErrorResponse> for StripeErrorCode {
errors::ApiErrorResponse::MissingDisputeId => Self::MissingDisputeId,
errors::ApiErrorResponse::FileNotFound => Self::FileNotFound,
errors::ApiErrorResponse::FileNotAvailable => Self::FileNotAvailable,
+ errors::ApiErrorResponse::MerchantConnectorAccountDisabled => {
+ Self::MerchantConnectorAccountDisabled
+ }
errors::ApiErrorResponse::NotSupported { .. } => Self::InternalServerError,
}
}
@@ -519,6 +525,7 @@ impl actix_web::ResponseError for StripeErrorCode {
| Self::PaymentMethodNotFound
| Self::MerchantAccountNotFound
| Self::MerchantConnectorAccountNotFound { .. }
+ | Self::MerchantConnectorAccountDisabled
| Self::MandateNotFound
| Self::ApiKeyNotFound
| Self::DuplicateMerchantAccount
diff --git a/crates/router/src/core/errors/api_error_response.rs b/crates/router/src/core/errors/api_error_response.rs
index 3af3580baa..9529f0def1 100644
--- a/crates/router/src/core/errors/api_error_response.rs
+++ b/crates/router/src/core/errors/api_error_response.rs
@@ -154,6 +154,8 @@ pub enum ApiErrorResponse {
MandateValidationFailed { reason: String },
#[error(error_type= ErrorType::ValidationError, code = "HE_03", message = "The payment has not succeeded yet. Please pass a successful payment to initiate refund")]
PaymentNotSucceeded,
+ #[error(error_type = ErrorType::ValidationError, code = "HE_03", message = "The specified merchant connector account is disabled")]
+ MerchantConnectorAccountDisabled,
#[error(error_type= ErrorType::ObjectNotFound, code = "HE_04", message = "Successful payment not found for the given payment id")]
SuccessfulPaymentNotFound,
#[error(error_type = ErrorType::ObjectNotFound, code = "HE_04", message = "The connector provided in the request is incorrect or not available")]
@@ -260,6 +262,7 @@ impl actix_web::ResponseError for ApiErrorResponse {
| Self::PaymentMethodNotFound
| Self::MerchantAccountNotFound
| Self::MerchantConnectorAccountNotFound { .. }
+ | Self::MerchantConnectorAccountDisabled
| Self::MandateNotFound
| Self::ClientSecretNotGiven
| Self::ClientSecretExpired
@@ -443,6 +446,9 @@ impl common_utils::errors::ErrorSwitch<api_models::errors::types::ApiErrorRespon
Self::MerchantConnectorAccountNotFound { id } => {
AER::NotFound(ApiError::new("HE", 2, format!("Merchant connector account with id '{id}' does not exist in our records"), None))
}
+ Self::MerchantConnectorAccountDisabled => {
+ AER::BadRequest(ApiError::new("HE", 3, "The selected merchant connector account is disabled", None))
+ }
Self::ResourceIdNotFound => {
AER::NotFound(ApiError::new("HE", 2, "Resource ID does not exist in our records", None))
}
diff --git a/crates/router/src/core/payments/helpers.rs b/crates/router/src/core/payments/helpers.rs
index 6171025ec4..ed5afe925d 100644
--- a/crates/router/src/core/payments/helpers.rs
+++ b/crates/router/src/core/payments/helpers.rs
@@ -1573,6 +1573,15 @@ impl MerchantConnectorAccountType {
Self::CacheVal(val) => val.connector_account_details.peek().to_owned(),
}
}
+
+ pub fn is_disabled(&self) -> bool {
+ match self {
+ Self::DbVal(ref inner) => inner.disabled.unwrap_or(false),
+ // Cached merchant connector account, only contains the account details,
+ // the merchant connector account must only be cached if it's not disabled
+ Self::CacheVal(_) => false,
+ }
+ }
}
pub async fn get_merchant_connector_account(
diff --git a/crates/router/src/core/payments/transformers.rs b/crates/router/src/core/payments/transformers.rs
index 65e8c8dc1d..538ca4c189 100644
--- a/crates/router/src/core/payments/transformers.rs
+++ b/crates/router/src/core/payments/transformers.rs
@@ -1,5 +1,6 @@
use std::{fmt::Debug, marker::PhantomData};
+use common_utils::fp_utils;
use error_stack::{IntoReport, ResultExt};
use router_env::{instrument, tracing};
@@ -52,6 +53,10 @@ where
)
.await?;
+ fp_utils::when(merchant_connector_account.is_disabled(), || {
+ Err(errors::ApiErrorResponse::MerchantConnectorAccountDisabled)
+ })?;
+
let auth_type: types::ConnectorAuthType = merchant_connector_account
.get_connector_account_details()
.parse_value("ConnectorAuthType")