Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions crates/common_enums/src/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1640,6 +1640,30 @@ pub enum WebhookDeliveryAttempt {
ManualRetry,
}

#[derive(
Clone,
Copy,
Debug,
Eq,
PartialEq,
serde::Deserialize,
serde::Serialize,
strum::Display,
strum::EnumString,
ToSchema,
)]
#[router_derive::diesel_enum(storage_type = "db_enum")]
#[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(
Expand Down
2 changes: 2 additions & 0 deletions crates/common_utils/src/id_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ mod relay;
mod routing;
mod subscription;
mod tenant;
mod webhook_endpoint;

use std::{borrow::Cow, fmt::Debug};

Expand Down Expand Up @@ -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};

Expand Down
24 changes: 24 additions & 0 deletions crates/common_utils/src/id_type/webhook_endpoint.rs
Original file line number Diff line number Diff line change
@@ -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))
}
}
9 changes: 9 additions & 0 deletions crates/diesel_models/src/business_profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -795,6 +795,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 {
Expand All @@ -808,6 +816,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);
Expand Down
17 changes: 16 additions & 1 deletion crates/hyperswitch_domain_models/src/business_profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use diesel_models::business_profile::RevenueRecoveryAlgorithmData;
use diesel_models::business_profile::{
self as storage_types, AuthenticationConnectorDetails, BusinessPaymentLinkConfig,
BusinessPayoutLinkConfig, CardTestingGuardConfig, ExternalVaultConnectorDetails,
ProfileUpdateInternal, WebhookDetails,
MultipleWebhookDetail, ProfileUpdateInternal, WebhookDetails,
};
use error_stack::ResultExt;
use masking::{ExposeInterface, PeekInterface, Secret};
Expand Down Expand Up @@ -91,6 +91,21 @@ pub struct Profile {
pub billing_processor_id: Option<common_utils::id_type::MerchantConnectorAccountId>,
}

#[cfg(feature = "v1")]
#[derive(Clone, Debug)]
pub struct WebhookDetail {
pub webhook_version: Option<String>,
pub webhook_username: Option<String>,
pub webhook_password: Option<Secret<String>>,
pub payment_created_enabled: Option<bool>,
pub payment_succeeded_enabled: Option<bool>,
pub payment_failed_enabled: Option<bool>,
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>>,
}

#[cfg(feature = "v1")]
#[derive(Clone, Debug)]
pub enum ExternalVaultDetails {
Expand Down
2 changes: 2 additions & 0 deletions crates/router/src/db/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions crates/router/src/types/transformers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2014,6 +2014,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,
}
}
}
Expand Down