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: return appropriate error message during webhook call for invalid merchant_secret adyen (#2450)

Hrithikeshdb7f9fa801d2
diff --git a/crates/router/src/compatibility/stripe/errors.rs b/crates/router/src/compatibility/stripe/errors.rs
index 02d9ff7942..d79533e73b 100644
--- a/crates/router/src/compatibility/stripe/errors.rs
+++ b/crates/router/src/compatibility/stripe/errors.rs
@@ -576,7 +576,10 @@ impl From<errors::ApiErrorResponse> for StripeErrorCode {
| errors::ApiErrorResponse::WebhookResourceNotFound
| errors::ApiErrorResponse::WebhookProcessingFailure
| errors::ApiErrorResponse::WebhookAuthenticationFailed
- | errors::ApiErrorResponse::WebhookUnprocessableEntity => Self::WebhookProcessingError,
+ | errors::ApiErrorResponse::WebhookUnprocessableEntity
+ | errors::ApiErrorResponse::WebhookInvalidMerchantSecret => {
+ Self::WebhookProcessingError
+ }
errors::ApiErrorResponse::IncorrectPaymentMethodConfiguration => {
Self::PaymentMethodUnactivated
}
diff --git a/crates/router/src/connector/adyen.rs b/crates/router/src/connector/adyen.rs
index bc6930891b..5089d86b80 100644
--- a/crates/router/src/connector/adyen.rs
+++ b/crates/router/src/connector/adyen.rs
@@ -1494,7 +1494,7 @@ impl api::IncomingWebhook for Adyen {
let raw_key = hex::decode(connector_webhook_secrets.secret)
.into_report()
- .change_context(errors::ConnectorError::WebhookSignatureNotFound)?;
+ .change_context(errors::ConnectorError::WebhookVerificationSecretInvalid)?;
let signing_key = hmac::Key::new(hmac::HMAC_SHA256, &raw_key);
let signed_messaged = hmac::sign(&signing_key, &message);
diff --git a/crates/router/src/core/errors.rs b/crates/router/src/core/errors.rs
index 2e898006da..6b205434a8 100644
--- a/crates/router/src/core/errors.rs
+++ b/crates/router/src/core/errors.rs
@@ -139,6 +139,8 @@ pub enum ConnectorError {
WebhookSourceVerificationFailed,
#[error("Could not find merchant secret in DB for incoming webhook source verification")]
WebhookVerificationSecretNotFound,
+ #[error("Merchant secret found for incoming webhook source verification is invalid")]
+ WebhookVerificationSecretInvalid,
#[error("Incoming webhook object reference ID not found")]
WebhookReferenceIdNotFound,
#[error("Incoming webhook event type not found")]
diff --git a/crates/router/src/core/errors/api_error_response.rs b/crates/router/src/core/errors/api_error_response.rs
index 501839f4ae..6805bc2be1 100644
--- a/crates/router/src/core/errors/api_error_response.rs
+++ b/crates/router/src/core/errors/api_error_response.rs
@@ -230,6 +230,8 @@ pub enum ApiErrorResponse {
IncorrectPaymentMethodConfiguration,
#[error(error_type = ErrorType::InvalidRequestError, code = "WE_05", message = "Unable to process the webhook body")]
WebhookUnprocessableEntity,
+ #[error(error_type = ErrorType::InvalidRequestError, code = "WE_05", message = "Merchant Secret set my merchant for webhook source verification is invalid")]
+ WebhookInvalidMerchantSecret,
#[error(error_type = ErrorType::InvalidRequestError, code = "IR_19", message = "{message}")]
CurrencyNotSupported { message: String },
}
diff --git a/crates/router/src/core/errors/transformers.rs b/crates/router/src/core/errors/transformers.rs
index 327b1f386c..37725b7391 100644
--- a/crates/router/src/core/errors/transformers.rs
+++ b/crates/router/src/core/errors/transformers.rs
@@ -252,6 +252,9 @@ impl ErrorSwitch<api_models::errors::types::ApiErrorResponse> for ApiErrorRespon
Self::WebhookProcessingFailure => {
AER::InternalServerError(ApiError::new("WE", 3, "There was an issue processing the webhook", None))
},
+ Self::WebhookInvalidMerchantSecret => {
+ AER::BadRequest(ApiError::new("WE", 2, "Merchant Secret set for webhook source verificartion is invalid", None))
+ }
Self::IncorrectPaymentMethodConfiguration => {
AER::BadRequest(ApiError::new("HE", 4, "No eligible connector was found for the current payment method configuration", None))
}
@@ -275,6 +278,9 @@ impl ErrorSwitch<ApiErrorResponse> for ConnectorError {
| Self::WebhookBodyDecodingFailed
| Self::WebhooksNotImplemented => ApiErrorResponse::WebhookBadRequest,
Self::WebhookEventTypeNotFound => ApiErrorResponse::WebhookUnprocessableEntity,
+ Self::WebhookVerificationSecretInvalid => {
+ ApiErrorResponse::WebhookInvalidMerchantSecret
+ }
_ => ApiErrorResponse::InternalServerError,
}
}