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

feat(framework): Diesel and domain model changes to support multiple outgoing webhooks (#9816)

sweta-sharmaac8c6c966c2a
diff --git a/crates/common_enums/src/enums.rs b/crates/common_enums/src/enums.rs
index 2cbd3a9e54..af81c2af82 100644
--- a/crates/common_enums/src/enums.rs
+++ b/crates/common_enums/src/enums.rs
@@ -1640,6 +1640,29 @@ pub enum WebhookDeliveryAttempt {
ManualRetry,
}
+#[derive(
+ Clone,
+ Copy,
+ Debug,
+ Eq,
+ PartialEq,
+ serde::Deserialize,
+ serde::Serialize,
+ strum::Display,
+ strum::EnumString,
+ ToSchema,
+)]
+#[serde(rename_all = "snake_case")]
+#[strum(serialize_all = "snake_case")]
+pub enum OutgoingWebhookEndpointStatus {
+ /// The webhook endpoint is active and operational.
+ Active,
+ /// The webhook endpoint is temporarily disabled.
+ Inactive,
+ /// The webhook endpoint is deprecated and can no longer be reactivated.
+ Deprecated,
+}
+
// TODO: This decision about using KV mode or not,
// should be taken at a top level rather than pushing it down to individual functions via an enum.
#[derive(
diff --git a/crates/common_utils/src/id_type.rs b/crates/common_utils/src/id_type.rs
index d1ab010668..aec6e5d4f9 100644
--- a/crates/common_utils/src/id_type.rs
+++ b/crates/common_utils/src/id_type.rs
@@ -20,6 +20,7 @@ mod relay;
mod routing;
mod subscription;
mod tenant;
+mod webhook_endpoint;
use std::{borrow::Cow, fmt::Debug};
@@ -60,6 +61,7 @@ pub use self::{
routing::RoutingId,
subscription::SubscriptionId,
tenant::TenantId,
+ webhook_endpoint::WebhookEndpointId,
};
use crate::{fp_utils::when, generate_id_with_default_len};
diff --git a/crates/common_utils/src/id_type/webhook_endpoint.rs b/crates/common_utils/src/id_type/webhook_endpoint.rs
new file mode 100644
index 0000000000..7e8f59c988
--- /dev/null
+++ b/crates/common_utils/src/id_type/webhook_endpoint.rs
@@ -0,0 +1,24 @@
+use crate::errors::{CustomResult, ValidationError};
+
+crate::id_type!(
+ WebhookEndpointId,
+ "A type for webhook_endpoint_id that can be used for unique identifier for a webhook_endpoint"
+);
+crate::impl_id_type_methods!(WebhookEndpointId, "webhook_endpoint_id");
+crate::impl_generate_id_id_type!(WebhookEndpointId, "whe");
+crate::impl_default_id_type!(WebhookEndpointId, "whe");
+
+// This is to display the `WebhookEndpointId` as WebhookEndpointId(abcd)
+crate::impl_debug_id_type!(WebhookEndpointId);
+crate::impl_try_from_cow_str_id_type!(WebhookEndpointId, "webhook_endpoint_id");
+
+crate::impl_serializable_secret_id_type!(WebhookEndpointId);
+crate::impl_queryable_id_type!(WebhookEndpointId);
+crate::impl_to_sql_from_sql_id_type!(WebhookEndpointId);
+
+impl WebhookEndpointId {
+ /// Get webhook_endpoint id from String
+ pub fn try_from_string(webhook_endpoint_id: String) -> CustomResult<Self, ValidationError> {
+ Self::try_from(std::borrow::Cow::from(webhook_endpoint_id))
+ }
+}
diff --git a/crates/diesel_models/src/business_profile.rs b/crates/diesel_models/src/business_profile.rs
index 854bf12f0f..da4c6c6bcb 100644
--- a/crates/diesel_models/src/business_profile.rs
+++ b/crates/diesel_models/src/business_profile.rs
@@ -805,6 +805,14 @@ impl Default for CardTestingGuardConfig {
}
}
+#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
+pub struct MultipleWebhookDetail {
+ pub webhook_endpoint_id: common_utils::id_type::WebhookEndpointId,
+ pub webhook_url: Secret<String>,
+ pub events: HashSet<common_enums::EventType>,
+ pub status: common_enums::OutgoingWebhookEndpointStatus,
+}
+
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize, diesel::AsExpression)]
#[diesel(sql_type = diesel::sql_types::Json)]
pub struct WebhookDetails {
@@ -818,6 +826,7 @@ pub struct WebhookDetails {
pub payment_statuses_enabled: Option<Vec<common_enums::IntentStatus>>,
pub refund_statuses_enabled: Option<Vec<common_enums::RefundStatus>>,
pub payout_statuses_enabled: Option<Vec<common_enums::PayoutStatus>>,
+ pub multiple_webhooks_list: Option<Vec<MultipleWebhookDetail>>,
}
common_utils::impl_to_sql_from_sql_json!(WebhookDetails);
diff --git a/crates/router/src/db/events.rs b/crates/router/src/db/events.rs
index f7d2e4bec0..2366fc01ab 100644
--- a/crates/router/src/db/events.rs
+++ b/crates/router/src/db/events.rs
@@ -1179,6 +1179,7 @@ mod tests {
payment_statuses_enabled: None,
refund_statuses_enabled: None,
payout_statuses_enabled: None,
+ multiple_webhooks_list: None,
}),
sub_merchants_enabled: None,
parent_merchant_id: None,
@@ -1246,6 +1247,7 @@ mod tests {
payment_statuses_enabled: None,
refund_statuses_enabled: None,
payout_statuses_enabled: None,
+ multiple_webhooks_list: None,
}),
metadata: None,
routing_algorithm: None,
diff --git a/crates/router/src/types/transformers.rs b/crates/router/src/types/transformers.rs
index 90e25b34cf..faf7cb2618 100644
--- a/crates/router/src/types/transformers.rs
+++ b/crates/router/src/types/transformers.rs
@@ -2015,6 +2015,7 @@ impl ForeignFrom<api_models::admin::WebhookDetails>
payment_statuses_enabled: item.payment_statuses_enabled,
refund_statuses_enabled: item.refund_statuses_enabled,
payout_statuses_enabled: item.payout_statuses_enabled,
+ multiple_webhooks_list: None,
}
}
}