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

This commit is contained in:
sweta-sharma
2025-10-16 15:12:46 +05:30
committed by GitHub
parent 6f045d84f1
commit ac8c6c966c
6 changed files with 61 additions and 0 deletions

View File

@ -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(

View File

@ -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};

View File

@ -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))
}
}

View File

@ -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);

View File

@ -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,

View File

@ -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,
}
}
}