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(router/webhooks): correct webhook error mapping and make source verification optional for all connectors (#1333)

ItsMeShashank71315097dd01
diff --git a/Cargo.lock b/Cargo.lock
index 3690b93799..fd55c2dc31 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -3058,7 +3058,7 @@ dependencies = [
[[package]]
name = "opentelemetry"
version = "0.18.0"
-source = "git+https://github.com/open-telemetry/opentelemetry-rust?rev=44b90202fd744598db8b0ace5b8f0bad7ec45658#44b90202fd744598db8b0ace5b8f0bad7ec45658"
+source = "git+https://github.com/open-telemetry/opentelemetry-rust/?rev=44b90202fd744598db8b0ace5b8f0bad7ec45658#44b90202fd744598db8b0ace5b8f0bad7ec45658"
dependencies = [
"opentelemetry_api",
"opentelemetry_sdk",
@@ -3067,7 +3067,7 @@ dependencies = [
[[package]]
name = "opentelemetry-otlp"
version = "0.11.0"
-source = "git+https://github.com/open-telemetry/opentelemetry-rust?rev=44b90202fd744598db8b0ace5b8f0bad7ec45658#44b90202fd744598db8b0ace5b8f0bad7ec45658"
+source = "git+https://github.com/open-telemetry/opentelemetry-rust/?rev=44b90202fd744598db8b0ace5b8f0bad7ec45658#44b90202fd744598db8b0ace5b8f0bad7ec45658"
dependencies = [
"async-trait",
"futures",
@@ -3084,7 +3084,7 @@ dependencies = [
[[package]]
name = "opentelemetry-proto"
version = "0.1.0"
-source = "git+https://github.com/open-telemetry/opentelemetry-rust?rev=44b90202fd744598db8b0ace5b8f0bad7ec45658#44b90202fd744598db8b0ace5b8f0bad7ec45658"
+source = "git+https://github.com/open-telemetry/opentelemetry-rust/?rev=44b90202fd744598db8b0ace5b8f0bad7ec45658#44b90202fd744598db8b0ace5b8f0bad7ec45658"
dependencies = [
"futures",
"futures-util",
@@ -3096,7 +3096,7 @@ dependencies = [
[[package]]
name = "opentelemetry_api"
version = "0.18.0"
-source = "git+https://github.com/open-telemetry/opentelemetry-rust?rev=44b90202fd744598db8b0ace5b8f0bad7ec45658#44b90202fd744598db8b0ace5b8f0bad7ec45658"
+source = "git+https://github.com/open-telemetry/opentelemetry-rust/?rev=44b90202fd744598db8b0ace5b8f0bad7ec45658#44b90202fd744598db8b0ace5b8f0bad7ec45658"
dependencies = [
"fnv",
"futures-channel",
@@ -3111,7 +3111,7 @@ dependencies = [
[[package]]
name = "opentelemetry_sdk"
version = "0.18.0"
-source = "git+https://github.com/open-telemetry/opentelemetry-rust?rev=44b90202fd744598db8b0ace5b8f0bad7ec45658#44b90202fd744598db8b0ace5b8f0bad7ec45658"
+source = "git+https://github.com/open-telemetry/opentelemetry-rust/?rev=44b90202fd744598db8b0ace5b8f0bad7ec45658#44b90202fd744598db8b0ace5b8f0bad7ec45658"
dependencies = [
"async-trait",
"crossbeam-channel",
diff --git a/crates/router/src/connector/adyen.rs b/crates/router/src/connector/adyen.rs
index c5d160adc6..380a96c6b5 100644
--- a/crates/router/src/connector/adyen.rs
+++ b/crates/router/src/connector/adyen.rs
@@ -11,6 +11,7 @@ use storage_models::enums as storage_enums;
use self::transformers as adyen;
use crate::{
configs::settings,
+ connector::utils as conn_utils,
consts,
core::errors::{self, CustomResult},
db::StorageInterface,
@@ -797,13 +798,17 @@ impl api::IncomingWebhook for Adyen {
db: &dyn StorageInterface,
merchant_id: &str,
) -> CustomResult<Vec<u8>, errors::ConnectorError> {
- let key = format!("whsec_verification_{}_{}", self.id(), merchant_id);
- let secret = db
- .get_key(&key)
- .await
- .change_context(errors::ConnectorError::WebhookVerificationSecretNotFound)?;
-
- Ok(secret)
+ let key = conn_utils::get_webhook_merchant_secret_key(self.id(), merchant_id);
+ let secret = match db.find_config_by_key(&key).await {
+ Ok(config) => Some(config),
+ Err(e) => {
+ crate::logger::warn!("Unable to fetch merchant webhook secret from DB: {:#?}", e);
+ None
+ }
+ };
+ Ok(secret
+ .map(|conf| conf.config.into_bytes())
+ .unwrap_or_default())
}
fn get_webhook_object_reference_id(
diff --git a/crates/router/src/connector/airwallex.rs b/crates/router/src/connector/airwallex.rs
index 36fef0c5de..b508424d19 100644
--- a/crates/router/src/connector/airwallex.rs
+++ b/crates/router/src/connector/airwallex.rs
@@ -9,6 +9,7 @@ use transformers as airwallex;
use super::utils::{AccessTokenRequestInfo, RefundsRequestData};
use crate::{
configs::settings,
+ connector::utils as conn_utils,
core::{
errors::{self, CustomResult},
payments,
@@ -947,12 +948,17 @@ impl api::IncomingWebhook for Airwallex {
db: &dyn StorageInterface,
merchant_id: &str,
) -> CustomResult<Vec<u8>, errors::ConnectorError> {
- let key = format!("whsec_verification_{}_{}", self.id(), merchant_id);
- let secret = db
- .find_config_by_key(&key)
- .await
- .change_context(errors::ConnectorError::WebhookVerificationSecretNotFound)?;
- Ok(secret.config.into_bytes())
+ let key = conn_utils::get_webhook_merchant_secret_key(self.id(), merchant_id);
+ let secret = match db.find_config_by_key(&key).await {
+ Ok(config) => Some(config),
+ Err(e) => {
+ crate::logger::warn!("Unable to fetch merchant webhook secret from DB: {:#?}", e);
+ None
+ }
+ };
+ Ok(secret
+ .map(|conf| conf.config.into_bytes())
+ .unwrap_or_default())
}
fn get_webhook_object_reference_id(
diff --git a/crates/router/src/connector/authorizedotnet.rs b/crates/router/src/connector/authorizedotnet.rs
index c6bc558e9b..419cee8f26 100644
--- a/crates/router/src/connector/authorizedotnet.rs
+++ b/crates/router/src/connector/authorizedotnet.rs
@@ -9,6 +9,7 @@ use transformers as authorizedotnet;
use crate::{
configs::settings,
+ connector::utils as conn_utils,
consts,
core::errors::{self, CustomResult},
db::StorageInterface,
@@ -684,7 +685,7 @@ impl api::IncomingWebhook for Authorizedotnet {
db: &dyn StorageInterface,
merchant_id: &str,
) -> CustomResult<Vec<u8>, errors::ConnectorError> {
- let key = format!("whsec_verification_{}_{}", self.id(), merchant_id);
+ let key = conn_utils::get_webhook_merchant_secret_key(self.id(), merchant_id);
let secret = match db.find_config_by_key(&key).await {
Ok(config) => Some(config),
Err(e) => {
diff --git a/crates/router/src/connector/bluesnap.rs b/crates/router/src/connector/bluesnap.rs
index 1a394a8d14..a24b24a190 100644
--- a/crates/router/src/connector/bluesnap.rs
+++ b/crates/router/src/connector/bluesnap.rs
@@ -15,6 +15,7 @@ use super::utils::{
};
use crate::{
configs::settings,
+ connector::utils as conn_utils,
consts,
core::{
errors::{self, CustomResult},
@@ -975,13 +976,17 @@ impl api::IncomingWebhook for Bluesnap {
db: &dyn StorageInterface,
merchant_id: &str,
) -> CustomResult<Vec<u8>, errors::ConnectorError> {
- let key = format!("whsec_verification_{}_{}", self.id(), merchant_id);
- let secret = db
- .find_config_by_key(&key)
- .await
- .change_context(errors::ConnectorError::WebhookVerificationSecretNotFound)?;
-
- Ok(secret.config.into_bytes())
+ let key = conn_utils::get_webhook_merchant_secret_key(self.id(), merchant_id);
+ let secret = match db.find_config_by_key(&key).await {
+ Ok(config) => Some(config),
+ Err(e) => {
+ crate::logger::warn!("Unable to fetch merchant webhook secret from DB: {:#?}", e);
+ None
+ }
+ };
+ Ok(secret
+ .map(|conf| conf.config.into_bytes())
+ .unwrap_or_default())
}
async fn verify_webhook_source(
diff --git a/crates/router/src/connector/braintree.rs b/crates/router/src/connector/braintree.rs
index 8e1f6d2c05..d7f8335f25 100644
--- a/crates/router/src/connector/braintree.rs
+++ b/crates/router/src/connector/braintree.rs
@@ -2,7 +2,7 @@ mod transformers;
use std::fmt::Debug;
-use error_stack::ResultExt;
+use error_stack::{IntoReport, ResultExt};
use self::transformers as braintree;
use crate::{
@@ -688,20 +688,20 @@ impl api::IncomingWebhook for Braintree {
&self,
_request: &api::IncomingWebhookRequestDetails<'_>,
) -> CustomResult<api_models::webhooks::ObjectReferenceId, errors::ConnectorError> {
- Err(errors::ConnectorError::NotImplemented("braintree".to_string()).into())
+ Err(errors::ConnectorError::WebhooksNotImplemented).into_report()
}
fn get_webhook_event_type(
&self,
_request: &api::IncomingWebhookRequestDetails<'_>,
) -> CustomResult<api::IncomingWebhookEvent, errors::ConnectorError> {
- Err(errors::ConnectorError::NotImplemented("braintree".to_string()).into())
+ Err(errors::ConnectorError::WebhooksNotImplemented).into_report()
}
fn get_webhook_resource_object(
&self,
_request: &api::IncomingWebhookRequestDetails<'_>,
) -> CustomResult<serde_json::Value, errors::ConnectorError> {
- Err(errors::ConnectorError::NotImplemented("braintree".to_string()).into())
+ Err(errors::ConnectorError::WebhooksNotImplemented).into_report()
}
}
diff --git a/crates/router/src/connector/checkout.rs b/crates/router/src/connector/checkout.rs
index cc45ef619c..74c2a32b27 100644
--- a/crates/router/src/connector/checkout.rs
+++ b/crates/router/src/connector/checkout.rs
@@ -1079,7 +1079,7 @@ impl api::IncomingWebhook for Checkout {
db: &dyn StorageInterface,
merchant_id: &str,
) -> CustomResult<Vec<u8>, errors::ConnectorError> {
- let key = format!("whsec_verification_{}_{}", self.id(), merchant_id);
+ let key = conn_utils::get_webhook_merchant_secret_key(self.id(), merchant_id);
let secret = match db.find_config_by_key(&key).await {
Ok(config) => Some(config),
Err(e) => {
diff --git a/crates/router/src/connector/coinbase.rs b/crates/router/src/connector/coinbase.rs
index 20805ced1d..0fe23c244a 100644
--- a/crates/router/src/connector/coinbase.rs
+++ b/crates/router/src/connector/coinbase.rs
@@ -523,13 +523,17 @@ impl api::IncomingWebhook for Coinbase {
db: &dyn db::StorageInterface,
merchant_id: &str,
) -> CustomResult<Vec<u8>, errors::ConnectorError> {
- let key = format!("whsec_verification_{}_{}", self.id(), merchant_id);
- let secret = db
- .get_key(&key)
- .await
- .change_context(errors::ConnectorError::WebhookVerificationSecretNotFound)?;
-
- Ok(secret)
+ let key = utils::get_webhook_merchant_secret_key(self.id(), merchant_id);
+ let secret = match db.find_config_by_key(&key).await {
+ Ok(config) => Some(config),
+ Err(e) => {
+ crate::logger::warn!("Unable to fetch merchant webhook secret from DB: {:#?}", e);
+ None
+ }
+ };
+ Ok(secret
+ .map(|conf| conf.config.into_bytes())
+ .unwrap_or_default())
}
fn get_webhook_object_reference_id(
diff --git a/crates/router/src/connector/cybersource.rs b/crates/router/src/connector/cybersource.rs
index 301394c2af..829c6e13b7 100644
--- a/crates/router/src/connector/cybersource.rs
+++ b/crates/router/src/connector/cybersource.rs
@@ -717,20 +717,20 @@ impl api::IncomingWebhook for Cybersource {
&self,
_request: &api::IncomingWebhookRequestDetails<'_>,
) -> CustomResult<api_models::webhooks::ObjectReferenceId, errors::ConnectorError> {
- Err(errors::ConnectorError::NotImplemented("cybersource".to_string()).into())
+ Err(errors::ConnectorError::WebhooksNotImplemented).into_report()
}
fn get_webhook_event_type(
&self,
_request: &api::IncomingWebhookRequestDetails<'_>,
) -> CustomResult<api::IncomingWebhookEvent, errors::ConnectorError> {
- Err(errors::ConnectorError::NotImplemented("cybersource".to_string()).into())
+ Err(errors::ConnectorError::WebhooksNotImplemented).into_report()
}
fn get_webhook_resource_object(
&self,
_request: &api::IncomingWebhookRequestDetails<'_>,
) -> CustomResult<serde_json::Value, errors::ConnectorError> {
- Err(errors::ConnectorError::NotImplemented("cybersource".to_string()).into())
+ Err(errors::ConnectorError::WebhooksNotImplemented).into_report()
}
}
diff --git a/crates/router/src/connector/fiserv.rs b/crates/router/src/connector/fiserv.rs
index deb0371d37..463f37d0a8 100644
--- a/crates/router/src/connector/fiserv.rs
+++ b/crates/router/src/connector/fiserv.rs
@@ -3,7 +3,7 @@ mod transformers;
use std::fmt::Debug;
use base64::Engine;
-use error_stack::ResultExt;
+use error_stack::{IntoReport, ResultExt};
use ring::hmac;
use time::OffsetDateTime;
use transformers as fiserv;
@@ -684,20 +684,20 @@ impl api::IncomingWebhook for Fiserv {
&self,
_request: &api::IncomingWebhookRequestDetails<'_>,
) -> CustomResult<api_models::webhooks::ObjectReferenceId, errors::ConnectorError> {
- Err(errors::ConnectorError::NotImplemented("fiserv".to_string()).into())
+ Err(errors::ConnectorError::WebhooksNotImplemented).into_report()
}
fn get_webhook_event_type(
&self,
_request: &api::IncomingWebhookRequestDetails<'_>,
) -> CustomResult<api::IncomingWebhookEvent, errors::ConnectorError> {
- Err(errors::ConnectorError::NotImplemented("fiserv".to_string()).into())
+ Err(errors::ConnectorError::WebhooksNotImplemented).into_report()
}
fn get_webhook_resource_object(
&self,
_request: &api::IncomingWebhookRequestDetails<'_>,
) -> CustomResult<serde_json::Value, errors::ConnectorError> {
- Err(errors::ConnectorError::NotImplemented("fiserv".to_string()).into())
+ Err(errors::ConnectorError::WebhooksNotImplemented).into_report()
}
}
diff --git a/crates/router/src/connector/globalpay.rs b/crates/router/src/connector/globalpay.rs
index c2ba074584..2986123952 100644
--- a/crates/router/src/connector/globalpay.rs
+++ b/crates/router/src/connector/globalpay.rs
@@ -808,12 +808,17 @@ impl api::IncomingWebhook for Globalpay {
db: &dyn db::StorageInterface,
merchant_id: &str,
) -> CustomResult<Vec<u8>, errors::ConnectorError> {
- let key = format!("whsec_verification_{}_{}", self.id(), merchant_id);
- let secret = db
- .find_config_by_key(&key)
- .await
- .change_context(errors::ConnectorError::WebhookVerificationSecretNotFound)?;
- Ok(secret.config.into_bytes())
+ let key = conn_utils::get_webhook_merchant_secret_key(self.id(), merchant_id);
+ let secret = match db.find_config_by_key(&key).await {
+ Ok(config) => Some(config),
+ Err(e) => {
+ crate::logger::warn!("Unable to fetch merchant webhook secret from DB: {:#?}", e);
+ None
+ }
+ };
+ Ok(secret
+ .map(|conf| conf.config.into_bytes())
+ .unwrap_or_default())
}
fn get_webhook_source_verification_signature(
diff --git a/crates/router/src/connector/iatapay.rs b/crates/router/src/connector/iatapay.rs
index 4e7306cbe8..271e37e1f6 100644
--- a/crates/router/src/connector/iatapay.rs
+++ b/crates/router/src/connector/iatapay.rs
@@ -633,13 +633,17 @@ impl api::IncomingWebhook for Iatapay {
db: &dyn db::StorageInterface,
merchant_id: &str,
) -> CustomResult<Vec<u8>, errors::ConnectorError> {
- let key = format!("whsec_verification_{}_{}", self.id(), merchant_id);
- let secret = db
- .get_key(&key)
- .await
- .change_context(errors::ConnectorError::WebhookVerificationSecretNotFound)?;
-
- Ok(secret)
+ let key = utils::get_webhook_merchant_secret_key(self.id(), merchant_id);
+ let secret = match db.find_config_by_key(&key).await {
+ Ok(config) => Some(config),
+ Err(e) => {
+ crate::logger::warn!("Unable to fetch merchant webhook secret from DB: {:#?}", e);
+ None
+ }
+ };
+ Ok(secret
+ .map(|conf| conf.config.into_bytes())
+ .unwrap_or_default())
}
fn get_webhook_object_reference_id(
diff --git a/crates/router/src/connector/nuvei.rs b/crates/router/src/connector/nuvei.rs
index 97f26f6c97..43b6f6dc41 100644
--- a/crates/router/src/connector/nuvei.rs
+++ b/crates/router/src/connector/nuvei.rs
@@ -852,12 +852,17 @@ impl api::IncomingWebhook for Nuvei {
db: &dyn StorageInterface,
merchant_id: &str,
) -> CustomResult<Vec<u8>, errors::ConnectorError> {
- let key = format!("wh_mer_sec_verification_{}_{}", self.id(), merchant_id);
- let secret = db
- .get_key(&key)
- .await
- .change_context(errors::ConnectorError::WebhookVerificationSecretNotFound)?;
- Ok(secret)
+ let key = utils::get_webhook_merchant_secret_key(self.id(), merchant_id);
+ let secret = match db.find_config_by_key(&key).await {
+ Ok(config) => Some(config),
+ Err(e) => {
+ crate::logger::warn!("Unable to fetch merchant webhook secret from DB: {:#?}", e);
+ None
+ }
+ };
+ Ok(secret
+ .map(|conf| conf.config.into_bytes())
+ .unwrap_or_default())
}
fn get_webhook_source_verification_message(
diff --git a/crates/router/src/connector/opennode.rs b/crates/router/src/connector/opennode.rs
index fa66aa5e12..09bcf15b87 100644
--- a/crates/router/src/connector/opennode.rs
+++ b/crates/router/src/connector/opennode.rs
@@ -9,6 +9,7 @@ use transformers as opennode;
use self::opennode::OpennodeWebhookDetails;
use crate::{
configs::settings,
+ connector::utils as conn_utils,
core::errors::{self, CustomResult},
db, headers,
services::{self, ConnectorIntegration},
@@ -527,13 +528,17 @@ impl api::IncomingWebhook for Opennode {
db: &dyn db::StorageInterface,
merchant_id: &str,
) -> CustomResult<Vec<u8>, errors::ConnectorError> {
- let key = format!("whsec_verification_{}_{}", self.id(), merchant_id);
- let secret = db
- .get_key(&key)
- .await
- .change_context(errors::ConnectorError::WebhookVerificationSecretNotFound)?;
-
- Ok(secret)
+ let key = conn_utils::get_webhook_merchant_secret_key(self.id(), merchant_id);
+ let secret = match db.find_config_by_key(&key).await {
+ Ok(config) => Some(config),
+ Err(e) => {
+ crate::logger::warn!("Unable to fetch merchant webhook secret from DB: {:#?}", e);
+ None
+ }
+ };
+ Ok(secret
+ .map(|conf| conf.config.into_bytes())
+ .unwrap_or_default())
}
fn get_webhook_object_reference_id(
diff --git a/crates/router/src/connector/rapyd.rs b/crates/router/src/connector/rapyd.rs
index 05c28efba5..65c131b71f 100644
--- a/crates/router/src/connector/rapyd.rs
+++ b/crates/router/src/connector/rapyd.rs
@@ -702,13 +702,17 @@ impl api::IncomingWebhook for Rapyd {
db: &dyn StorageInterface,
merchant_id: &str,
) -> CustomResult<Vec<u8>, errors::ConnectorError> {
- let key = format!("wh_mer_sec_verification_{}_{}", self.id(), merchant_id);
- let secret = db
- .get_key(&key)
- .await
- .change_context(errors::ConnectorError::WebhookVerificationSecretNotFound)?;
-
- Ok(secret)
+ let key = conn_utils::get_webhook_merchant_secret_key(self.id(), merchant_id);
+ let secret = match db.find_config_by_key(&key).await {
+ Ok(config) => Some(config),
+ Err(e) => {
+ crate::logger::warn!("Unable to fetch merchant webhook secret from DB: {:#?}", e);
+ None
+ }
+ };
+ Ok(secret
+ .map(|conf| conf.config.into_bytes())
+ .unwrap_or_default())
}
fn get_webhook_source_verification_message(
diff --git a/crates/router/src/connector/stripe.rs b/crates/router/src/connector/stripe.rs
index 7190397ca7..fa56cc155f 100644
--- a/crates/router/src/connector/stripe.rs
+++ b/crates/router/src/connector/stripe.rs
@@ -10,6 +10,7 @@ use self::transformers as stripe;
use super::utils::RefundsRequestData;
use crate::{
configs::settings,
+ connector::utils as conn_utils,
consts,
core::{
errors::{self, CustomResult},
@@ -1620,13 +1621,17 @@ impl api::IncomingWebhook for Stripe {
db: &dyn StorageInterface,
merchant_id: &str,
) -> CustomResult<Vec<u8>, errors::ConnectorError> {
- let key = format!("whsec_verification_{}_{}", self.id(), merchant_id);
- let secret = db
- .get_key(&key)
- .await
- .change_context(errors::ConnectorError::WebhookVerificationSecretNotFound)?;
-
- Ok(secret)
+ let key = conn_utils::get_webhook_merchant_secret_key(self.id(), merchant_id);
+ let secret = match db.find_config_by_key(&key).await {
+ Ok(config) => Some(config),
+ Err(e) => {
+ crate::logger::warn!("Unable to fetch merchant webhook secret from DB: {:#?}", e);
+ None
+ }
+ };
+ Ok(secret
+ .map(|conf| conf.config.into_bytes())
+ .unwrap_or_default())
}
fn get_webhook_object_reference_id(
diff --git a/crates/router/src/connector/trustpay.rs b/crates/router/src/connector/trustpay.rs
index af0a334561..ce61f5620b 100644
--- a/crates/router/src/connector/trustpay.rs
+++ b/crates/router/src/connector/trustpay.rs
@@ -10,6 +10,7 @@ use transformers as trustpay;
use super::utils::collect_and_sort_values_by_removing_signature;
use crate::{
configs::settings,
+ connector::utils as conn_utils,
consts,
core::{
errors::{self, CustomResult},
@@ -729,12 +730,17 @@ impl api::IncomingWebhook for Trustpay {
db: &dyn crate::db::StorageInterface,
merchant_id: &str,
) -> CustomResult<Vec<u8>, errors::ConnectorError> {
- let key = format!("whsec_verification_{}_{}", self.id(), merchant_id);
- let secret = db
- .get_key(&key)
- .await
- .change_context(errors::ConnectorError::WebhookVerificationSecretNotFound)?;
- Ok(secret)
+ let key = conn_utils::get_webhook_merchant_secret_key(self.id(), merchant_id);
+ let secret = match db.find_config_by_key(&key).await {
+ Ok(config) => Some(config),
+ Err(e) => {
+ crate::logger::warn!("Unable to fetch merchant webhook secret from DB: {:#?}", e);
+ None
+ }
+ };
+ Ok(secret
+ .map(|conf| conf.config.into_bytes())
+ .unwrap_or_default())
}
fn get_dispute_details(
diff --git a/crates/router/src/connector/utils.rs b/crates/router/src/connector/utils.rs
index 5c312dc5d9..758839287e 100644
--- a/crates/router/src/connector/utils.rs
+++ b/crates/router/src/connector/utils.rs
@@ -793,3 +793,8 @@ pub fn collect_and_sort_values_by_removing_signature(
values.sort();
values
}
+
+#[inline]
+pub fn get_webhook_merchant_secret_key(connector: &str, merchant_id: &str) -> String {
+ format!("whsec_verification_{connector}_{merchant_id}")
+}
diff --git a/crates/router/src/connector/worldline.rs b/crates/router/src/connector/worldline.rs
index f4d17b0af3..b5568bf22e 100644
--- a/crates/router/src/connector/worldline.rs
+++ b/crates/router/src/connector/worldline.rs
@@ -713,13 +713,17 @@ impl api::IncomingWebhook for Worldline {
db: &dyn StorageInterface,
merchant_id: &str,
) -> CustomResult<Vec<u8>, errors::ConnectorError> {
- let key = format!("whsec_verification_{}_{}", self.id(), merchant_id);
- let secret = db
- .get_key(&key)
- .await
- .change_context(errors::ConnectorError::WebhookVerificationSecretNotFound)?;
-
- Ok(secret)
+ let key = conn_utils::get_webhook_merchant_secret_key(self.id(), merchant_id);
+ let secret = match db.find_config_by_key(&key).await {
+ Ok(config) => Some(config),
+ Err(e) => {
+ crate::logger::warn!("Unable to fetch merchant webhook secret from DB: {:#?}", e);
+ None
+ }
+ };
+ Ok(secret
+ .map(|conf| conf.config.into_bytes())
+ .unwrap_or_default())
}
fn get_webhook_object_reference_id(
diff --git a/crates/router/src/connector/worldpay.rs b/crates/router/src/connector/worldpay.rs
index 6839636d8a..4469142c5c 100644
--- a/crates/router/src/connector/worldpay.rs
+++ b/crates/router/src/connector/worldpay.rs
@@ -641,12 +641,17 @@ impl api::IncomingWebhook for Worldpay {
db: &dyn StorageInterface,
merchant_id: &str,
) -> CustomResult<Vec<u8>, errors::ConnectorError> {
- let key = format!("wh_mer_sec_verification_{}_{}", self.id(), merchant_id);
- let secret = db
- .get_key(&key)
- .await
- .change_context(errors::ConnectorError::WebhookVerificationSecretNotFound)?;
- Ok(secret)
+ let key = utils::get_webhook_merchant_secret_key(self.id(), merchant_id);
+ let secret = match db.find_config_by_key(&key).await {
+ Ok(config) => Some(config),
+ Err(e) => {
+ crate::logger::warn!("Unable to fetch merchant webhook secret from DB: {:#?}", e);
+ None
+ }
+ };
+ Ok(secret
+ .map(|conf| conf.config.into_bytes())
+ .unwrap_or_default())
}
fn get_webhook_source_verification_message(
diff --git a/crates/router/src/connector/zen.rs b/crates/router/src/connector/zen.rs
index c4ee6d1e9c..9e80f55654 100644
--- a/crates/router/src/connector/zen.rs
+++ b/crates/router/src/connector/zen.rs
@@ -11,6 +11,7 @@ use self::transformers::{ZenPaymentStatus, ZenWebhookTxnType};
use super::utils::RefundsRequestData;
use crate::{
configs::settings,
+ connector::utils as conn_utils,
core::{
errors::{self, CustomResult},
payments,
@@ -477,13 +478,17 @@ impl api::IncomingWebhook for Zen {
db: &dyn StorageInterface,
merchant_id: &str,
) -> CustomResult<Vec<u8>, errors::ConnectorError> {
- let key = format!("whsec_verification_{}_{}", self.id(), merchant_id);
- let secret = db
- .find_config_by_key(&key)
- .await
- .change_context(errors::ConnectorError::WebhookVerificationSecretNotFound)?;
-
- Ok(secret.config.into_bytes())
+ let key = conn_utils::get_webhook_merchant_secret_key(self.id(), merchant_id);
+ let secret = match db.find_config_by_key(&key).await {
+ Ok(config) => Some(config),
+ Err(e) => {
+ crate::logger::warn!("Unable to fetch merchant webhook secret from DB: {:#?}", e);
+ None
+ }
+ };
+ Ok(secret
+ .map(|conf| conf.config.into_bytes())
+ .unwrap_or_default())
}
async fn verify_webhook_source(
diff --git a/crates/router/src/core/webhooks.rs b/crates/router/src/core/webhooks.rs
index e4ad140cf9..cf328ba213 100644
--- a/crates/router/src/core/webhooks.rs
+++ b/crates/router/src/core/webhooks.rs
@@ -629,7 +629,9 @@ pub async fn webhooks_core<W: api::OutgoingWebhookType>(
connector_name,
api::GetToken::Connector,
)
- .change_context(errors::ApiErrorResponse::InternalServerError)
+ .change_context(errors::ApiErrorResponse::InvalidRequestData {
+ message: "invalid connnector name received".to_string(),
+ })
.attach_printable("Failed construction of ConnectorData")?;
let connector = connector.connector;
@@ -654,7 +656,7 @@ pub async fn webhooks_core<W: api::OutgoingWebhookType>(
let event_type = connector
.get_webhook_event_type(&request_details)
- .change_context(errors::ApiErrorResponse::InternalServerError)
+ .switch()
.attach_printable("Could not find event type in incoming webhook body")?;
let process_webhook_further = utils::lookup_webhook_event(
diff --git a/crates/router/src/core/webhooks/utils.rs b/crates/router/src/core/webhooks/utils.rs
index bec61f7e2a..647d06de19 100644
--- a/crates/router/src/core/webhooks/utils.rs
+++ b/crates/router/src/core/webhooks/utils.rs
@@ -66,7 +66,8 @@ impl<T> WebhookApiErrorSwitch<T> for errors::CustomResult<T, errors::ConnectorEr
| errors::ConnectorError::WebhookReferenceIdNotFound
| errors::ConnectorError::WebhookEventTypeNotFound
| errors::ConnectorError::WebhookResourceObjectNotFound
- | errors::ConnectorError::WebhookBodyDecodingFailed => {
+ | errors::ConnectorError::WebhookBodyDecodingFailed
+ | errors::ConnectorError::WebhooksNotImplemented => {
Err(e).change_context(errors::ApiErrorResponse::WebhookBadRequest)
}