From db7f9fa801d2bacf3abda6cc447220d254f56382 Mon Sep 17 00:00:00 2001 From: Hrithikesh <61539176+hrithikesh026@users.noreply.github.com> Date: Thu, 5 Oct 2023 15:22:19 +0530 Subject: [PATCH] fix: return appropriate error message during webhook call for invalid merchant_secret adyen (#2450) --- crates/router/src/compatibility/stripe/errors.rs | 5 ++++- crates/router/src/connector/adyen.rs | 2 +- crates/router/src/core/errors.rs | 2 ++ crates/router/src/core/errors/api_error_response.rs | 2 ++ crates/router/src/core/errors/transformers.rs | 6 ++++++ 5 files changed, 15 insertions(+), 2 deletions(-) diff --git a/crates/router/src/compatibility/stripe/errors.rs b/crates/router/src/compatibility/stripe/errors.rs index 02d9ff794237..d79533e73b40 100644 --- a/crates/router/src/compatibility/stripe/errors.rs +++ b/crates/router/src/compatibility/stripe/errors.rs @@ -576,7 +576,10 @@ impl From 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 bc6930891b5c..5089d86b803a 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 2e898006da08..6b205434a8dc 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 501839f4aef7..6805bc2be192 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 327b1f386cbe..37725b7391fa 100644 --- a/crates/router/src/core/errors/transformers.rs +++ b/crates/router/src/core/errors/transformers.rs @@ -252,6 +252,9 @@ impl ErrorSwitch 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 for ConnectorError { | Self::WebhookBodyDecodingFailed | Self::WebhooksNotImplemented => ApiErrorResponse::WebhookBadRequest, Self::WebhookEventTypeNotFound => ApiErrorResponse::WebhookUnprocessableEntity, + Self::WebhookVerificationSecretInvalid => { + ApiErrorResponse::WebhookInvalidMerchantSecret + } _ => ApiErrorResponse::InternalServerError, } }