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
Rust adyenbeginner-friendlyfeaturedfinancefintechhacktoberfesthigh-performanceopen-sourceorchestrationpaymentpayment-gatewaypayment-integrationpayment-processingpaymentspayments-platformrestful-apirustsdkstripeworks-with-react
fix: store and retrieve merchant secret from MCA table for webhooks source verification (#1331)
Hrithikesha6645bd3540f
diff --git a/Cargo.lock b/Cargo.lockindex e42e38db86..bd81825ee3 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -1639,7 +1639,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "907076dfda823b0b36d2a1bb5f90c96660a5bbcd7729e10727f07858f22c4edc"dependencies = ["cfg-if",- "hashbrown 0.12.3",+ "hashbrown","lock_api","once_cell","parking_lot_core",@@ -1856,12 +1856,6 @@ dependencies = ["termcolor",]-[[package]]-name = "equivalent"-version = "1.0.0"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "88bffebc5d80432c9b140ee17875ff173a8ab62faad5b257da912bd2f6c1c0a1"-[[package]]name = "errno"version = "0.3.1"@@ -2307,7 +2301,7 @@ dependencies = ["futures-sink","futures-util","http",- "indexmap 1.9.3",+ "indexmap","slab","tokio","tokio-util",@@ -2323,12 +2317,6 @@ dependencies = ["ahash 0.7.6",]-[[package]]-name = "hashbrown"-version = "0.14.0"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "2c6201b9ff9fd90a5a3bac2e56a830d0caa509576f0e503818ee82c181b3437a"-[[package]]name = "heck"version = "0.4.1"@@ -2567,20 +2555,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99"dependencies = ["autocfg",- "hashbrown 0.12.3",+ "hashbrown","serde",]-[[package]]-name = "indexmap"-version = "2.0.0"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "d5477fe2230a79769d8dc68e0eabf5437907c0457a5614a9e8dddb67f65eb65d"-dependencies = [- "equivalent",- "hashbrown 0.14.0",-]-[[package]]name = "infer"version = "0.2.3"@@ -3237,7 +3215,7 @@ dependencies = ["fnv","futures-channel","futures-util",- "indexmap 1.9.3",+ "indexmap","once_cell","pin-project-lite","thiserror",@@ -3273,7 +3251,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "ccd746e37177e1711c20dd619a1620f34f5c8b569c53590a72dedd5344d8924a"dependencies = ["dlv-list",- "hashbrown 0.12.3",+ "hashbrown",][[package]]@@ -4029,7 +4007,6 @@ version = "0.1.0"dependencies = ["darling 0.14.4","diesel",- "indexmap 2.0.0","proc-macro2","quote","serde",@@ -4302,7 +4279,7 @@ version = "1.0.96"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "057d394a50403bcac12672b2b18fb387ab6d289d957dab67dd201875391e52f1"dependencies = [- "indexmap 1.9.3",+ "indexmap","itoa","ryu","serde",@@ -4389,7 +4366,7 @@ dependencies = ["base64 0.21.2","chrono","hex",- "indexmap 1.9.3",+ "indexmap","serde","serde_json","serde_with_macros",@@ -4998,7 +4975,7 @@ version = "0.19.10"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "2380d56e8670370eee6566b0bfd4265f65b3f432e8c6d85623f728d4fa31f739"dependencies = [- "indexmap 1.9.3",+ "indexmap","serde","serde_spanned","toml_datetime",@@ -5045,7 +5022,7 @@ checksum = "b8fa9be0de6cf49e536ce1851f987bd21a43b771b09473c3549a6c853db37c1c"dependencies = ["futures-core","futures-util",- "indexmap 1.9.3",+ "indexmap","pin-project","pin-project-lite","rand 0.8.5",@@ -5302,7 +5279,7 @@ version = "3.3.0"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "68ae74ef183fae36d650f063ae7bde1cacbe1cd7e72b617cbe1e985551878b98"dependencies = [- "indexmap 1.9.3",+ "indexmap","serde","serde_json","utoipa-gen",diff --git a/crates/api_models/src/admin.rs b/crates/api_models/src/admin.rsindex 895b137679..4e69aea9c9 100644--- a/crates/api_models/src/admin.rs+++ b/crates/api_models/src/admin.rs@@ -475,6 +475,21 @@ pub struct MerchantConnectorCreate {/// Business Sub label of the merchant#[schema(example = "chase")]pub business_sub_label: Option<String>,++ /// Webhook details of this merchant connector+ #[schema(example = json!({+ "connector_webhook_details": {+ "merchant_secret": "1234567890987654321"+ }+ }))]+ pub connector_webhook_details: Option<MerchantConnectorWebhookDetails>,+}++#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]+#[serde(deny_unknown_fields)]+pub struct MerchantConnectorWebhookDetails {+ #[schema(value_type = String, example = "12345678900987654321")]+ pub merchant_secret: Secret<String>,}/// Response of creating a new Merchant Connector for the merchant account."@@ -562,6 +577,14 @@ pub struct MerchantConnectorResponse {}]))]pub frm_configs: Option<FrmConfigs>,++ /// Webhook details of this merchant connector+ #[schema(example = json!({+ "connector_webhook_details": {+ "merchant_secret": "1234567890987654321"+ }+ }))]+ pub connector_webhook_details: Option<MerchantConnectorWebhookDetails>,}/// Create a new Merchant Connector for the merchant account. The connector could be a payment processor / facilitator / acquirer or specialized services like Fraud / Accounting etc."@@ -631,6 +654,14 @@ pub struct MerchantConnectorUpdate {}]))]pub frm_configs: Option<FrmConfigs>,++ /// Webhook details of this merchant connector+ #[schema(example = json!({+ "connector_webhook_details": {+ "merchant_secret": "1234567890987654321"+ }+ }))]+ pub connector_webhook_details: Option<MerchantConnectorWebhookDetails>,}///Details of FrmConfigs are mentioned here... it should be passed in payment connector create api call, and stored in merchant_connector_tablediff --git a/crates/diesel_models/src/merchant_connector_account.rs b/crates/diesel_models/src/merchant_connector_account.rsindex ed34ab2673..135e1eda62 100644--- a/crates/diesel_models/src/merchant_connector_account.rs+++ b/crates/diesel_models/src/merchant_connector_account.rs@@ -35,6 +35,7 @@ pub struct MerchantConnectorAccount {pub frm_configs: Option<Secret<serde_json::Value>>,pub created_at: time::PrimitiveDateTime,pub modified_at: time::PrimitiveDateTime,+ pub connector_webhook_details: Option<pii::SecretSerdeValue>,}#[derive(Clone, Debug, Insertable, router_derive::DebugAsDisplay)]@@ -56,9 +57,10 @@ pub struct MerchantConnectorAccountNew {pub frm_configs: Option<Secret<serde_json::Value>>,pub created_at: time::PrimitiveDateTime,pub modified_at: time::PrimitiveDateTime,+ pub connector_webhook_details: Option<pii::SecretSerdeValue>,}-#[derive(Clone, Debug, Default, AsChangeset, router_derive::DebugAsDisplay)]+#[derive(Clone, Debug, AsChangeset, router_derive::DebugAsDisplay)]#[diesel(table_name = merchant_connector_account)]pub struct MerchantConnectorAccountUpdateInternal {pub merchant_id: Option<String>,@@ -72,6 +74,7 @@ pub struct MerchantConnectorAccountUpdateInternal {pub metadata: Option<pii::SecretSerdeValue>,pub frm_configs: Option<Secret<serde_json::Value>>,pub modified_at: Option<time::PrimitiveDateTime>,+ pub connector_webhook_details: Option<pii::SecretSerdeValue>,}impl MerchantConnectorAccountUpdateInternal {diff --git a/crates/diesel_models/src/schema.rs b/crates/diesel_models/src/schema.rsindex 254399ee8c..6c0e28db19 100644--- a/crates/diesel_models/src/schema.rs+++ b/crates/diesel_models/src/schema.rs@@ -359,6 +359,7 @@ diesel::table! {frm_configs -> Nullable<Jsonb>,created_at -> Timestamp,modified_at -> Timestamp,+ connector_webhook_details -> Nullable<Jsonb>,}}diff --git a/crates/router/src/compatibility/stripe/app.rs b/crates/router/src/compatibility/stripe/app.rsindex 540cb5df6a..dd687deb70 100644--- a/crates/router/src/compatibility/stripe/app.rs+++ b/crates/router/src/compatibility/stripe/app.rs@@ -101,7 +101,7 @@ impl Webhooks {web::scope("/webhooks").app_data(web::Data::new(config)).service(- web::resource("/{merchant_id}/{connector}")+ web::resource("/{merchant_id}/{connector_label}").route(web::post().to(webhooks::receive_incoming_webhook::<StripeOutgoingWebhook>),)diff --git a/crates/router/src/connector/adyen.rs b/crates/router/src/connector/adyen.rsindex f03d7edef1..8a5b2f6960 100644--- a/crates/router/src/connector/adyen.rs+++ b/crates/router/src/connector/adyen.rs@@ -12,7 +12,6 @@ use router_env::{instrument, tracing};use self::transformers as adyen;use crate::{configs::settings,- connector::utils as conn_utils,consts,core::errors::{self, CustomResult},db::StorageInterface,@@ -24,6 +23,7 @@ use crate::{types::{self,api::{self, ConnectorCommon},+ domain,transformers::ForeignFrom,},utils::{self, crypto, ByteSliceExt, BytesExt, OptionExt},@@ -826,35 +826,24 @@ impl api::IncomingWebhook for Adyen {Ok(message.into_bytes())}- async fn get_webhook_source_verification_merchant_secret(- &self,- db: &dyn StorageInterface,- merchant_id: &str,- ) -> CustomResult<Vec<u8>, errors::ConnectorError> {- 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(&self,db: &dyn StorageInterface,request: &api::IncomingWebhookRequestDetails<'_>,merchant_id: &str,+ connector_label: &str,+ key_store: &domain::MerchantKeyStore,) -> CustomResult<bool, errors::ConnectorError> {let signature = self.get_webhook_source_verification_signature(request).change_context(errors::ConnectorError::WebhookSourceVerificationFailed)?;let secret = self- .get_webhook_source_verification_merchant_secret(db, merchant_id)+ .get_webhook_source_verification_merchant_secret(+ db,+ merchant_id,+ connector_label,+ key_store,+ ).await.change_context(errors::ConnectorError::WebhookSourceVerificationFailed)?;let message = selfdiff --git a/crates/router/src/connector/airwallex.rs b/crates/router/src/connector/airwallex.rsindex 3b674a295b..30ed42d448 100644--- a/crates/router/src/connector/airwallex.rs+++ b/crates/router/src/connector/airwallex.rs@@ -9,12 +9,10 @@ use transformers as airwallex;use super::utils::{AccessTokenRequestInfo, RefundsRequestData};use crate::{configs::settings,- connector::utils as conn_utils,core::{errors::{self, CustomResult},payments,},- db::StorageInterface,headers, logger, routes,services::{self,@@ -967,24 +965,6 @@ impl api::IncomingWebhook for Airwallex {Ok(format!("{}{}", timestamp, String::from_utf8_lossy(request.body)).into_bytes())}- async fn get_webhook_source_verification_merchant_secret(- &self,- db: &dyn StorageInterface,- merchant_id: &str,- ) -> CustomResult<Vec<u8>, errors::ConnectorError> {- 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(&self,request: &api::IncomingWebhookRequestDetails<'_>,diff --git a/crates/router/src/connector/authorizedotnet.rs b/crates/router/src/connector/authorizedotnet.rsindex 7305c076e7..2543d416c9 100644--- a/crates/router/src/connector/authorizedotnet.rs+++ b/crates/router/src/connector/authorizedotnet.rs@@ -9,10 +9,8 @@ use transformers as authorizedotnet;use crate::{configs::settings,- connector::utils as conn_utils,consts,core::errors::{self, CustomResult},- db::StorageInterface,headers,services::{self, request, ConnectorIntegration},types::{@@ -686,24 +684,6 @@ impl api::IncomingWebhook for Authorizedotnet {}}- async fn get_webhook_source_verification_merchant_secret(- &self,- db: &dyn StorageInterface,- merchant_id: &str,- ) -> CustomResult<Vec<u8>, errors::ConnectorError> {- 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_event_type(&self,request: &api::IncomingWebhookRequestDetails<'_>,diff --git a/crates/router/src/connector/bluesnap.rs b/crates/router/src/connector/bluesnap.rsindex 2e87e37daf..1553e5b746 100644--- a/crates/router/src/connector/bluesnap.rs+++ b/crates/router/src/connector/bluesnap.rs@@ -15,7 +15,6 @@ use super::utils::{};use crate::{configs::settings,- connector::utils as conn_utils,consts,core::{errors::{self, CustomResult},@@ -31,6 +30,7 @@ use crate::{types::{self,api::{self, ConnectorCommon, ConnectorCommonExt},+ domain,storage::enums,ErrorResponse, Response,},@@ -986,29 +986,13 @@ impl api::IncomingWebhook for Bluesnap {Ok(msg.into_bytes())}- async fn get_webhook_source_verification_merchant_secret(- &self,- db: &dyn StorageInterface,- merchant_id: &str,- ) -> CustomResult<Vec<u8>, errors::ConnectorError> {- 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(&self,db: &dyn StorageInterface,request: &api::IncomingWebhookRequestDetails<'_>,merchant_id: &str,+ connector_label: &str,+ key_store: &domain::MerchantKeyStore,) -> CustomResult<bool, errors::ConnectorError> {let algorithm = self.get_webhook_source_verification_algorithm(request)@@ -1018,7 +1002,12 @@ impl api::IncomingWebhook for Bluesnap {.get_webhook_source_verification_signature(request).change_context(errors::ConnectorError::WebhookSourceVerificationFailed)?;let mut secret = self- .get_webhook_source_verification_merchant_secret(db, merchant_id)+ .get_webhook_source_verification_merchant_secret(+ db,+ merchant_id,+ connector_label,+ key_store,+ ).await.change_context(errors::ConnectorError::WebhookSourceVerificationFailed)?;let mut message = selfdiff --git a/crates/router/src/connector/cashtocode.rs b/crates/router/src/connector/cashtocode.rsindex a68985b1e7..a18e397fa1 100644--- a/crates/router/src/connector/cashtocode.rs+++ b/crates/router/src/connector/cashtocode.rs@@ -19,6 +19,7 @@ use crate::{types::{self,api::{self, ConnectorCommon, ConnectorCommonExt},+ domain,storage::{self},ErrorResponse, Response,},@@ -323,35 +324,24 @@ impl api::IncomingWebhook for Cashtocode {Ok(signature)}- async fn get_webhook_source_verification_merchant_secret(- &self,- db: &dyn StorageInterface,- merchant_id: &str,- ) -> CustomResult<Vec<u8>, errors::ConnectorError> {- 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(&self,db: &dyn StorageInterface,request: &api::IncomingWebhookRequestDetails<'_>,merchant_id: &str,+ connector_label: &str,+ key_store: &domain::MerchantKeyStore,) -> CustomResult<bool, errors::ConnectorError> {let signature = self.get_webhook_source_verification_signature(request).change_context(errors::ConnectorError::WebhookSourceVerificationFailed)?;let secret = self- .get_webhook_source_verification_merchant_secret(db, merchant_id)+ .get_webhook_source_verification_merchant_secret(+ db,+ merchant_id,+ connector_label,+ key_store,+ ).await.change_context(errors::ConnectorError::WebhookSourceVerificationFailed)?;let secret_auth = String::from_utf8(secret.to_vec())diff --git a/crates/router/src/connector/checkout.rs b/crates/router/src/connector/checkout.rsindex b37d5eb134..1824124b43 100644--- a/crates/router/src/connector/checkout.rs+++ b/crates/router/src/connector/checkout.rs@@ -16,7 +16,6 @@ use crate::{errors::{self, CustomResult},payments,},- db::StorageInterface,headers,services::{self,@@ -1106,23 +1105,6 @@ impl api::IncomingWebhook for Checkout {) -> CustomResult<Vec<u8>, errors::ConnectorError> {Ok(format!("{}", String::from_utf8_lossy(request.body)).into_bytes())}- async fn get_webhook_source_verification_merchant_secret(- &self,- db: &dyn StorageInterface,- merchant_id: &str,- ) -> CustomResult<Vec<u8>, errors::ConnectorError> {- 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(&self,request: &api::IncomingWebhookRequestDetails<'_>,diff --git a/crates/router/src/connector/coinbase.rs b/crates/router/src/connector/coinbase.rsindex 5adadb56f5..1d4d5764e2 100644--- a/crates/router/src/connector/coinbase.rs+++ b/crates/router/src/connector/coinbase.rs@@ -11,7 +11,7 @@ use super::utils;use crate::{configs::settings,core::errors::{self, CustomResult},- db, headers,+ headers,services::{self,request::{self, Mask},@@ -533,24 +533,6 @@ impl api::IncomingWebhook for Coinbase {Ok(message.to_string().into_bytes())}- async fn get_webhook_source_verification_merchant_secret(- &self,- db: &dyn db::StorageInterface,- merchant_id: &str,- ) -> CustomResult<Vec<u8>, errors::ConnectorError> {- 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(&self,request: &api::IncomingWebhookRequestDetails<'_>,diff --git a/crates/router/src/connector/cryptopay.rs b/crates/router/src/connector/cryptopay.rsindex a23d9fdbc9..4fa8c4e8da 100644--- a/crates/router/src/connector/cryptopay.rs+++ b/crates/router/src/connector/cryptopay.rs@@ -19,7 +19,7 @@ use crate::{configs::settings,consts,core::errors::{self, CustomResult},- db, headers,+ headers,services::{self,request::{self, Mask},@@ -386,24 +386,6 @@ impl api::IncomingWebhook for Cryptopay {Ok(message.to_string().into_bytes())}- async fn get_webhook_source_verification_merchant_secret(- &self,- db: &dyn db::StorageInterface,- merchant_id: &str,- ) -> CustomResult<Vec<u8>, errors::ConnectorError> {- 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(&self,request: &api::IncomingWebhookRequestDetails<'_>,diff --git a/crates/router/src/connector/globalpay.rs b/crates/router/src/connector/globalpay.rsindex 12294afd20..9ca12514ec 100644--- a/crates/router/src/connector/globalpay.rs+++ b/crates/router/src/connector/globalpay.rs@@ -23,7 +23,7 @@ use crate::{errors::{self, CustomResult},payments,},- db, headers,+ headers,services::{self,request::{self, Mask},@@ -814,24 +814,6 @@ impl api::IncomingWebhook for Globalpay {Ok(Box::new(crypto::Sha512))}- async fn get_webhook_source_verification_merchant_secret(- &self,- db: &dyn db::StorageInterface,- merchant_id: &str,- ) -> CustomResult<Vec<u8>, errors::ConnectorError> {- 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(&self,request: &api::IncomingWebhookRequestDetails<'_>,diff --git a/crates/router/src/connector/iatapay.rs b/crates/router/src/connector/iatapay.rsindex b27b945b4b..220dceef7c 100644--- a/crates/router/src/connector/iatapay.rs+++ b/crates/router/src/connector/iatapay.rs@@ -13,7 +13,7 @@ use crate::{configs::settings,consts,core::errors::{self, CustomResult},- db, headers,+ headers,services::{self,request::{self, Mask},@@ -642,24 +642,6 @@ impl api::IncomingWebhook for Iatapay {Ok(message.to_string().into_bytes())}- async fn get_webhook_source_verification_merchant_secret(- &self,- db: &dyn db::StorageInterface,- merchant_id: &str,- ) -> CustomResult<Vec<u8>, errors::ConnectorError> {- 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(&self,request: &api::IncomingWebhookRequestDetails<'_>,diff --git a/crates/router/src/connector/noon.rs b/crates/router/src/connector/noon.rsindex 576b8687f8..ef5021dbfd 100644--- a/crates/router/src/connector/noon.rs+++ b/crates/router/src/connector/noon.rs@@ -15,7 +15,6 @@ use crate::{errors::{self, CustomResult},payments,},- db::StorageInterface,headers,services::{self,@@ -637,24 +636,6 @@ impl api::IncomingWebhook for Noon {Ok(message.into_bytes())}- async fn get_webhook_source_verification_merchant_secret(- &self,- db: &dyn StorageInterface,- merchant_id: &str,- ) -> CustomResult<Vec<u8>, errors::ConnectorError> {- let key = format!("whsec_verification_{}_{}", 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(&self,request: &api::IncomingWebhookRequestDetails<'_>,diff --git a/crates/router/src/connector/nuvei.rs b/crates/router/src/connector/nuvei.rsindex 1f771be9b1..560eea6f09 100644--- a/crates/router/src/connector/nuvei.rs+++ b/crates/router/src/connector/nuvei.rs@@ -17,7 +17,6 @@ use crate::{errors::{self, CustomResult},payments,},- db::StorageInterface,headers,services::{self, request, ConnectorIntegration},types::{@@ -861,24 +860,6 @@ impl api::IncomingWebhook for Nuvei {.change_context(errors::ConnectorError::WebhookResponseEncodingFailed)}- async fn get_webhook_source_verification_merchant_secret(- &self,- db: &dyn StorageInterface,- merchant_id: &str,- ) -> CustomResult<Vec<u8>, errors::ConnectorError> {- 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(&self,request: &api::IncomingWebhookRequestDetails<'_>,diff --git a/crates/router/src/connector/opennode.rs b/crates/router/src/connector/opennode.rsindex d0510561fc..36eba82093 100644--- a/crates/router/src/connector/opennode.rs+++ b/crates/router/src/connector/opennode.rs@@ -9,10 +9,9 @@ use transformers as opennode;use self::opennode::OpennodeWebhookDetails;use crate::{configs::settings,- connector::utils as conn_utils,consts,core::errors::{self, CustomResult},- db, headers,+ headers,services::{self,request::{self, Mask},@@ -535,24 +534,6 @@ impl api::IncomingWebhook for Opennode {Ok(message.to_string().into_bytes())}- async fn get_webhook_source_verification_merchant_secret(- &self,- db: &dyn db::StorageInterface,- merchant_id: &str,- ) -> CustomResult<Vec<u8>, errors::ConnectorError> {- 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(&self,request: &api::IncomingWebhookRequestDetails<'_>,diff --git a/crates/router/src/connector/payme.rs b/crates/router/src/connector/payme.rsindex 593eae7c17..b33b78ee5c 100644--- a/crates/router/src/connector/payme.rs+++ b/crates/router/src/connector/payme.rs@@ -9,12 +9,10 @@ use transformers as payme;use crate::{configs::settings,- connector::utils as conn_utils,core::{errors::{self, CustomResult},payments,},- db::StorageInterface,headers, routes,services::{self, request, ConnectorIntegration},types::{@@ -636,24 +634,6 @@ impl api::IncomingWebhook for Payme {Ok(api::IncomingWebhookEvent::from(resource.notify_type))}- async fn get_webhook_source_verification_merchant_secret(- &self,- db: &dyn StorageInterface,- merchant_id: &str,- ) -> CustomResult<Vec<u8>, errors::ConnectorError> {- 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_resource_object(&self,request: &api::IncomingWebhookRequestDetails<'_>,diff --git a/crates/router/src/connector/rapyd.rs b/crates/router/src/connector/rapyd.rsindex 118a5f7858..768a51f89e 100644--- a/crates/router/src/connector/rapyd.rs+++ b/crates/router/src/connector/rapyd.rs@@ -23,7 +23,7 @@ use crate::{types::{self,api::{self, ConnectorCommon},- ErrorResponse,+ domain, ErrorResponse,},utils::{self, crypto, ByteSliceExt, BytesExt},};@@ -725,24 +725,6 @@ impl api::IncomingWebhook for Rapyd {Ok(signature)}- async fn get_webhook_source_verification_merchant_secret(- &self,- db: &dyn StorageInterface,- merchant_id: &str,- ) -> CustomResult<Vec<u8>, errors::ConnectorError> {- 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(&self,request: &api::IncomingWebhookRequestDetails<'_>,@@ -777,12 +759,19 @@ impl api::IncomingWebhook for Rapyd {db: &dyn StorageInterface,request: &api::IncomingWebhookRequestDetails<'_>,merchant_id: &str,+ connector_label: &str,+ key_store: &domain::MerchantKeyStore,) -> CustomResult<bool, errors::ConnectorError> {let signature = self.get_webhook_source_verification_signature(request).change_context(errors::ConnectorError::WebhookSourceVerificationFailed)?;let secret = self- .get_webhook_source_verification_merchant_secret(db, merchant_id)+ .get_webhook_source_verification_merchant_secret(+ db,+ merchant_id,+ connector_label,+ key_store,+ ).await.change_context(errors::ConnectorError::WebhookSourceVerificationFailed)?;let message = selfdiff --git a/crates/router/src/connector/stripe.rs b/crates/router/src/connector/stripe.rsindex 21da444d4d..ecc76e9593 100644--- a/crates/router/src/connector/stripe.rs+++ b/crates/router/src/connector/stripe.rs@@ -10,13 +10,11 @@ use self::transformers as stripe;use super::utils::RefundsRequestData;use crate::{configs::settings,- connector::utils as conn_utils,consts,core::{errors::{self, CustomResult},payments,},- db::StorageInterface,headers, logger,services::{self,@@ -1692,24 +1690,6 @@ impl api::IncomingWebhook for Stripe {.into_bytes())}- async fn get_webhook_source_verification_merchant_secret(- &self,- db: &dyn StorageInterface,- merchant_id: &str,- ) -> CustomResult<Vec<u8>, errors::ConnectorError> {- 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(&self,request: &api::IncomingWebhookRequestDetails<'_>,diff --git a/crates/router/src/connector/trustpay.rs b/crates/router/src/connector/trustpay.rsindex e71c418224..d6e623eaa7 100644--- a/crates/router/src/connector/trustpay.rs+++ b/crates/router/src/connector/trustpay.rs@@ -10,7 +10,6 @@ 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},@@ -875,24 +874,6 @@ impl api::IncomingWebhook for Trustpay {Ok(payload.into_bytes())}- async fn get_webhook_source_verification_merchant_secret(- &self,- db: &dyn crate::db::StorageInterface,- merchant_id: &str,- ) -> CustomResult<Vec<u8>, errors::ConnectorError> {- 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(&self,request: &api::IncomingWebhookRequestDetails<'_>,diff --git a/crates/router/src/connector/utils.rs b/crates/router/src/connector/utils.rsindex 2c559c91be..49a29b78e9 100644--- a/crates/router/src/connector/utils.rs+++ b/crates/router/src/connector/utils.rs@@ -934,8 +934,8 @@ pub fn collect_and_sort_values_by_removing_signature(}#[inline]-pub fn get_webhook_merchant_secret_key(connector: &str, merchant_id: &str) -> String {- format!("whsec_verification_{connector}_{merchant_id}")+pub fn get_webhook_merchant_secret_key(connector_label: &str, merchant_id: &str) -> String {+ format!("whsec_verification_{connector_label}_{merchant_id}")}impl ForeignTryFrom<String> for UsStatesAbbreviation {diff --git a/crates/router/src/connector/worldline.rs b/crates/router/src/connector/worldline.rsindex 04c101a22e..b4e1d4fcc2 100644--- a/crates/router/src/connector/worldline.rs+++ b/crates/router/src/connector/worldline.rs@@ -16,7 +16,6 @@ use crate::{connector::utils as conn_utils,consts,core::errors::{self, CustomResult},- db::StorageInterface,headers, logger,services::{self,@@ -723,24 +722,6 @@ impl api::IncomingWebhook for Worldline {Ok(request.body.to_vec())}- async fn get_webhook_source_verification_merchant_secret(- &self,- db: &dyn StorageInterface,- merchant_id: &str,- ) -> CustomResult<Vec<u8>, errors::ConnectorError> {- 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(&self,request: &api::IncomingWebhookRequestDetails<'_>,diff --git a/crates/router/src/connector/worldpay.rs b/crates/router/src/connector/worldpay.rsindex 7e6c37ff00..12f5abf6b3 100644--- a/crates/router/src/connector/worldpay.rs+++ b/crates/router/src/connector/worldpay.rs@@ -14,7 +14,6 @@ use super::utils::{self, RefundsRequestData};use crate::{configs::settings,core::errors::{self, CustomResult},- db::StorageInterface,headers,services::{self,@@ -650,24 +649,6 @@ impl api::IncomingWebhook for Worldpay {.change_context(errors::ConnectorError::WebhookResponseEncodingFailed)}- async fn get_webhook_source_verification_merchant_secret(- &self,- db: &dyn StorageInterface,- merchant_id: &str,- ) -> CustomResult<Vec<u8>, errors::ConnectorError> {- 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(&self,request: &api::IncomingWebhookRequestDetails<'_>,diff --git a/crates/router/src/connector/zen.rs b/crates/router/src/connector/zen.rsindex b298cf7527..cae788c20c 100644--- a/crates/router/src/connector/zen.rs+++ b/crates/router/src/connector/zen.rs@@ -11,7 +11,6 @@ use self::transformers::{ZenPaymentStatus, ZenWebhookTxnType};use super::utils::RefundsRequestData;use crate::{configs::settings,- connector::utils as conn_utils,consts,core::{errors::{self, CustomResult},@@ -27,7 +26,7 @@ use crate::{types::{self,api::{self, ConnectorCommon, ConnectorCommonExt},- ErrorResponse, Response,+ domain, ErrorResponse, Response,},utils::{self, BytesExt},};@@ -553,35 +552,24 @@ impl api::IncomingWebhook for Zen {Ok(msg.into_bytes())}- async fn get_webhook_source_verification_merchant_secret(- &self,- db: &dyn StorageInterface,- merchant_id: &str,- ) -> CustomResult<Vec<u8>, errors::ConnectorError> {- 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(&self,db: &dyn StorageInterface,request: &api::IncomingWebhookRequestDetails<'_>,merchant_id: &str,+ connector_label: &str,+ key_store: &domain::MerchantKeyStore,) -> CustomResult<bool, errors::ConnectorError> {let algorithm = self.get_webhook_source_verification_algorithm(request)?;let signature = self.get_webhook_source_verification_signature(request)?;let mut secret = self- .get_webhook_source_verification_merchant_secret(db, merchant_id)+ .get_webhook_source_verification_merchant_secret(+ db,+ merchant_id,+ connector_label,+ key_store,+ ).await?;let mut message =self.get_webhook_source_verification_message(request, merchant_id, &secret)?;diff --git a/crates/router/src/core/admin.rs b/crates/router/src/core/admin.rsindex 666207eabc..390e03e94e 100644--- a/crates/router/src/core/admin.rs+++ b/crates/router/src/core/admin.rs@@ -2,7 +2,7 @@ use api_models::admin::PrimaryBusinessDetails;use common_utils::{crypto::{generate_cryptographically_secure_random_string, OptionalSecretValue},date_time,- ext_traits::ValueExt,+ ext_traits::{Encode, ValueExt},};use diesel_models::enums;use error_stack::{report, FutureExt, ResultExt};@@ -528,6 +528,18 @@ pub async fn create_payment_connector(created_at: common_utils::date_time::now(),modified_at: common_utils::date_time::now(),id: None,+ connector_webhook_details: match req.connector_webhook_details {+ Some(connector_webhook_details) => {+ Encode::<api_models::admin::MerchantConnectorWebhookDetails>::encode_to_value(+ &connector_webhook_details,+ )+ .change_context(errors::ApiErrorResponse::InternalServerError)+ .attach_printable(format!("Failed to serialize api_models::admin::MerchantConnectorWebhookDetails for Merchant: {}", merchant_id))+ .map(Some)?+ .map(masking::Secret::new)+ }+ None => None,+ },};let mca = store@@ -549,7 +561,6 @@ pub async fn create_payment_connector();let mca_response = mca.try_into()?;-Ok(service_api::ApplicationResponse::Json(mca_response))}@@ -685,6 +696,17 @@ pub async fn update_payment_connector(payment_methods_enabled,metadata: req.metadata,frm_configs,+ connector_webhook_details: match &req.connector_webhook_details {+ Some(connector_webhook_details) => {+ Encode::<api_models::admin::MerchantConnectorWebhookDetails>::encode_to_value(+ connector_webhook_details,+ )+ .change_context(errors::ApiErrorResponse::InternalServerError)+ .map(Some)?+ .map(masking::Secret::new)+ }+ None => None,+ },};let updated_mca = db@@ -715,6 +737,17 @@ pub async fn delete_payment_connector(.await.to_not_found_response(errors::ApiErrorResponse::MerchantAccountNotFound)?;+ let _mca = db+ .find_by_merchant_connector_account_merchant_id_merchant_connector_id(+ &merchant_id,+ &merchant_connector_id,+ &key_store,+ )+ .await+ .to_not_found_response(errors::ApiErrorResponse::MerchantConnectorAccountNotFound {+ id: merchant_connector_id.clone(),+ })?;+let is_deleted = db.delete_merchant_connector_account_by_merchant_id_merchant_connector_id(&merchant_id,@@ -724,6 +757,7 @@ pub async fn delete_payment_connector(.to_not_found_response(errors::ApiErrorResponse::MerchantConnectorAccountNotFound {id: merchant_connector_id.clone(),})?;+let response = api::MerchantConnectorDeleteResponse {merchant_id,merchant_connector_id,diff --git a/crates/router/src/core/webhooks.rs b/crates/router/src/core/webhooks.rsindex 5f0201fb74..4d07c5beb4 100644--- a/crates/router/src/core/webhooks.rs+++ b/crates/router/src/core/webhooks.rs@@ -653,9 +653,18 @@ pub async fn webhooks_core<W: api::OutgoingWebhookType>(req: &actix_web::HttpRequest,merchant_account: domain::MerchantAccount,key_store: domain::MerchantKeyStore,- connector_name: &str,+ connector_label: &str,body: actix_web::web::Bytes,) -> RouterResponse<serde_json::Value> {+ let connector_name = connector_label+ .split('_') //connector_name will be the first string after splitting connector_label+ .next()+ .ok_or(errors::ApiErrorResponse::InvalidDataValue {+ field_name: "connector_label",+ })+ .into_report()+ .attach_printable("Failed to infer connector_name from connector_label")?;+metrics::WEBHOOK_INCOMING_COUNT.add(&metrics::CONTEXT,1,@@ -702,7 +711,7 @@ pub async fn webhooks_core<W: api::OutgoingWebhookType>(let process_webhook_further = utils::lookup_webhook_event(&*state.store,- connector_name,+ connector_label,&merchant_account.merchant_id,&event_type,)@@ -718,6 +727,8 @@ pub async fn webhooks_core<W: api::OutgoingWebhookType>(&*state.store,&request_details,&merchant_account.merchant_id,+ connector_label,+ &key_store,).await.switch()diff --git a/crates/router/src/db/configs.rs b/crates/router/src/db/configs.rsindex d671922029..6684e42f80 100644--- a/crates/router/src/db/configs.rs+++ b/crates/router/src/db/configs.rs@@ -52,6 +52,7 @@ impl ConfigInterface for Store {config.insert(&conn).await.map_err(Into::into).into_report()}+ //fetch directly from DBasync fn find_config_by_key(&self,key: &str,@@ -74,6 +75,8 @@ impl ConfigInterface for Store {.map_err(Into::into).into_report()}++ //update in DB and remove in redis and cacheasync fn update_config_cached(&self,key: &str,@@ -85,6 +88,7 @@ impl ConfigInterface for Store {.await}+ //check in cache, then redis then finally DB, and on the way back populate redis and cacheasync fn find_config_by_key_cached(&self,key: &str,diff --git a/crates/router/src/db/merchant_connector_account.rs b/crates/router/src/db/merchant_connector_account.rsindex 6672d118a0..5f25d43c92 100644--- a/crates/router/src/db/merchant_connector_account.rs+++ b/crates/router/src/db/merchant_connector_account.rs@@ -457,6 +457,7 @@ impl MerchantConnectorAccountInterface for MockDb {business_sub_label: t.business_sub_label,created_at: common_utils::date_time::now(),modified_at: common_utils::date_time::now(),+ connector_webhook_details: t.connector_webhook_details,};accounts.push(account.clone());account@@ -618,6 +619,7 @@ mod merchant_connector_account_cache_tests {business_sub_label: None,created_at: date_time::now(),modified_at: date_time::now(),+ connector_webhook_details: None,};let key_store = dbdiff --git a/crates/router/src/openapi.rs b/crates/router/src/openapi.rsindex 02851c76f8..d0fe046118 100644--- a/crates/router/src/openapi.rs+++ b/crates/router/src/openapi.rs@@ -161,6 +161,7 @@ Never share your secret api keys. Keep them guarded and secure.api_models::admin::PaymentMethodsEnabled,api_models::admin::MerchantConnectorDetailsWrap,api_models::admin::MerchantConnectorDetails,+ api_models::admin::MerchantConnectorWebhookDetails,api_models::disputes::DisputeResponse,api_models::disputes::DisputeResponsePaymentsRetrieve,api_models::payments::AddressDetails,diff --git a/crates/router/src/routes/app.rs b/crates/router/src/routes/app.rsindex eb863d6f3a..34446d4674 100644--- a/crates/router/src/routes/app.rs+++ b/crates/router/src/routes/app.rs@@ -410,7 +410,7 @@ impl Webhooks {web::scope("/webhooks").app_data(web::Data::new(config)).service(- web::resource("/{merchant_id}/{connector}")+ web::resource("/{merchant_id}/{connector_label}").route(web::post().to(receive_incoming_webhook::<webhook_type::OutgoingWebhook>),)diff --git a/crates/router/src/routes/webhooks.rs b/crates/router/src/routes/webhooks.rsindex 722b627c83..9566038127 100644--- a/crates/router/src/routes/webhooks.rs+++ b/crates/router/src/routes/webhooks.rs@@ -16,7 +16,7 @@ pub async fn receive_incoming_webhook<W: api_types::OutgoingWebhookType>(path: web::Path<(String, String)>,) -> impl Responder {let flow = Flow::IncomingWebhookReceive;- let (merchant_id, connector_name) = path.into_inner();+ let (merchant_id, connector_label) = path.into_inner();api::server_wrap(flow,@@ -29,7 +29,7 @@ pub async fn receive_incoming_webhook<W: api_types::OutgoingWebhookType>(&req,auth.merchant_account,auth.key_store,- &connector_name,+ &connector_label,body,)},diff --git a/crates/router/src/types/api/webhooks.rs b/crates/router/src/types/api/webhooks.rsindex cdc57c98d4..fd0adf1566 100644--- a/crates/router/src/types/api/webhooks.rs+++ b/crates/router/src/types/api/webhooks.rs@@ -1,14 +1,18 @@+use api_models::admin::MerchantConnectorWebhookDetails;pub use api_models::webhooks::{IncomingWebhookDetails, IncomingWebhookEvent, MerchantWebhookConfig, ObjectReferenceId,OutgoingWebhook, OutgoingWebhookContent, OutgoingWebhookType, WebhookFlow,};-use error_stack::ResultExt;+use common_utils::ext_traits::ValueExt;+use error_stack::{IntoReport, ResultExt};+use masking::ExposeInterface;use super::ConnectorCommon;use crate::{core::errors::{self, CustomResult},db::StorageInterface,services,+ types::domain,utils::crypto,};@@ -73,10 +77,47 @@ pub trait IncomingWebhook: ConnectorCommon + Sync {async fn get_webhook_source_verification_merchant_secret(&self,- _db: &dyn StorageInterface,- _merchant_id: &str,+ db: &dyn StorageInterface,+ merchant_id: &str,+ connector_label: &str,+ key_store: &domain::MerchantKeyStore,) -> CustomResult<Vec<u8>, errors::ConnectorError> {- Ok(Vec::new())+ let debug_suffix = format!(+ "For merchant_id: {}, and connector_label: {}",+ merchant_id, connector_label+ );+ let merchant_connector_webhook_details = db+ .find_merchant_connector_account_by_merchant_id_connector_label(+ merchant_id,+ connector_label,+ key_store,+ )+ .await+ .change_context(errors::ConnectorError::WebhookSourceVerificationFailed)+ .attach_printable_lazy(|| {+ format!(+ "Fetch merchant_webhook_secret from MCA table failed {}",+ debug_suffix+ )+ })?+ .connector_webhook_details;+ let merchant_secret = merchant_connector_webhook_details+ .ok_or(errors::ConnectorError::WebhookSourceVerificationFailed)+ .into_report()+ .attach_printable_lazy(|| format!("Merchant Secret not configured {}", debug_suffix))?+ .expose()+ .parse_value::<MerchantConnectorWebhookDetails>("MerchantConnectorWebhookDetails")+ .change_context_lazy(|| errors::ConnectorError::WebhookSourceVerificationFailed)+ .attach_printable_lazy(|| {+ format!(+ "Deserializing MerchantConnectorWebhookDetails failed {}",+ debug_suffix+ )+ })?+ .merchant_secret+ .expose();+ //need to fetch merchant secret from config table with caching in future for enhanced performance+ Ok(merchant_secret.into_bytes())}fn get_webhook_source_verification_signature(@@ -100,6 +141,8 @@ pub trait IncomingWebhook: ConnectorCommon + Sync {db: &dyn StorageInterface,request: &IncomingWebhookRequestDetails<'_>,merchant_id: &str,+ connector_label: &str,+ key_store: &domain::MerchantKeyStore,) -> CustomResult<bool, errors::ConnectorError> {let algorithm = self.get_webhook_source_verification_algorithm(request)@@ -109,7 +152,12 @@ pub trait IncomingWebhook: ConnectorCommon + Sync {.get_webhook_source_verification_signature(request).change_context(errors::ConnectorError::WebhookSourceVerificationFailed)?;let secret = self- .get_webhook_source_verification_merchant_secret(db, merchant_id)+ .get_webhook_source_verification_merchant_secret(+ db,+ merchant_id,+ connector_label,+ key_store,+ ).await.change_context(errors::ConnectorError::WebhookSourceVerificationFailed)?;let message = selfdiff --git a/crates/router/src/types/domain/merchant_connector_account.rs b/crates/router/src/types/domain/merchant_connector_account.rsindex 20b8f78f70..0188ee177b 100644--- a/crates/router/src/types/domain/merchant_connector_account.rs+++ b/crates/router/src/types/domain/merchant_connector_account.rs@@ -31,6 +31,7 @@ pub struct MerchantConnectorAccount {pub business_sub_label: Option<String>,pub created_at: time::PrimitiveDateTime,pub modified_at: time::PrimitiveDateTime,+ pub connector_webhook_details: Option<pii::SecretSerdeValue>,}#[derive(Debug)]@@ -46,6 +47,7 @@ pub enum MerchantConnectorAccountUpdate {payment_methods_enabled: Option<Vec<serde_json::Value>>,metadata: Option<pii::SecretSerdeValue>,frm_configs: Option<Secret<serde_json::Value>>,+ connector_webhook_details: Option<pii::SecretSerdeValue>,},}@@ -76,6 +78,7 @@ impl behaviour::Conversion for MerchantConnectorAccount {business_sub_label: self.business_sub_label,created_at: self.created_at,modified_at: self.modified_at,+ connector_webhook_details: self.connector_webhook_details,},)}@@ -111,6 +114,7 @@ impl behaviour::Conversion for MerchantConnectorAccount {business_sub_label: other.business_sub_label,created_at: other.created_at,modified_at: other.modified_at,+ connector_webhook_details: other.connector_webhook_details,})}@@ -133,6 +137,7 @@ impl behaviour::Conversion for MerchantConnectorAccount {business_sub_label: self.business_sub_label,created_at: now,modified_at: now,+ connector_webhook_details: self.connector_webhook_details,})}}@@ -151,6 +156,7 @@ impl From<MerchantConnectorAccountUpdate> for MerchantConnectorAccountUpdateIntepayment_methods_enabled,metadata,frm_configs,+ connector_webhook_details,} => Self {merchant_id,connector_type,@@ -163,6 +169,7 @@ impl From<MerchantConnectorAccountUpdate> for MerchantConnectorAccountUpdateIntemetadata,frm_configs,modified_at: Some(common_utils::date_time::now()),+ connector_webhook_details,},}}diff --git a/crates/router/src/types/transformers.rs b/crates/router/src/types/transformers.rsindex f9a00d1428..2d3d2e74ee 100644--- a/crates/router/src/types/transformers.rs+++ b/crates/router/src/types/transformers.rs@@ -2,7 +2,7 @@ use api_models::enums as api_enums;use common_utils::{crypto::Encryptable, ext_traits::ValueExt};use diesel_models::enums as storage_enums;use error_stack::ResultExt;-use masking::PeekInterface;+use masking::{ExposeInterface, PeekInterface};use super::domain;use crate::{@@ -482,6 +482,17 @@ impl TryFrom<domain::MerchantConnectorAccount> for api_models::admin::MerchantCobusiness_label: item.business_label,business_sub_label: item.business_sub_label,frm_configs,+ connector_webhook_details: item+ .connector_webhook_details+ .map(|webhook_details| {+ serde_json::Value::parse_value(+ webhook_details.expose(),+ "MerchantConnectorWebhookDetails",+ )+ .attach_printable("Unable to deserialize connector_webhook_details")+ .change_context(errors::ApiErrorResponse::InternalServerError)+ })+ .transpose()?,})}}diff --git a/migrations/2023-05-31-152153_add_connector_webhook_details_to_mca/down.sql b/migrations/2023-05-31-152153_add_connector_webhook_details_to_mca/down.sqlnew file mode 100644index 0000000000..f30f509acc--- /dev/null+++ b/migrations/2023-05-31-152153_add_connector_webhook_details_to_mca/down.sql@@ -0,0 +1,2 @@+-- This file should undo anything in `up.sql`+ALTER TABLE merchant_connector_account DROP COLUMN connector_webhook_details;\ No newline at end of filediff --git a/migrations/2023-05-31-152153_add_connector_webhook_details_to_mca/up.sql b/migrations/2023-05-31-152153_add_connector_webhook_details_to_mca/up.sqlnew file mode 100644index 0000000000..18820717bc--- /dev/null+++ b/migrations/2023-05-31-152153_add_connector_webhook_details_to_mca/up.sql@@ -0,0 +1,3 @@+-- Your SQL goes here+ALTER TABLE merchant_connector_account+ADD COLUMN IF NOT EXISTS connector_webhook_details JSONB DEFAULT NULL;\ No newline at end of filediff --git a/openapi/openapi_spec.json b/openapi/openapi_spec.jsonindex 7bf717cb30..3025a6ed25 100644--- a/openapi/openapi_spec.json+++ b/openapi/openapi_spec.json@@ -5202,6 +5202,14 @@"description": "Business Sub label of the merchant","example": "chase","nullable": true+ },+ "connector_webhook_details": {+ "allOf": [+ {+ "$ref": "#/components/schemas/MerchantConnectorWebhookDetails"+ }+ ],+ "nullable": true}}},@@ -5399,6 +5407,14 @@}],"nullable": true+ },+ "connector_webhook_details": {+ "allOf": [+ {+ "$ref": "#/components/schemas/MerchantConnectorWebhookDetails"+ }+ ],+ "nullable": true}}},@@ -5487,6 +5503,26 @@}],"nullable": true+ },+ "connector_webhook_details": {+ "allOf": [+ {+ "$ref": "#/components/schemas/MerchantConnectorWebhookDetails"+ }+ ],+ "nullable": true+ }+ }+ },+ "MerchantConnectorWebhookDetails": {+ "type": "object",+ "required": [+ "merchant_secret"+ ],+ "properties": {+ "merchant_secret": {+ "type": "string",+ "example": "12345678900987654321"}}},