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

refactor(webhooks): default to triggering webhooks for all the states in payments, refunds and payouts flow (#11028)

Kashif553ac7aaca88
diff --git a/crates/common_types/src/consts.rs b/crates/common_types/src/consts.rs
index d950ce2165..320ab704a7 100644
--- a/crates/common_types/src/consts.rs
+++ b/crates/common_types/src/consts.rs
@@ -22,27 +22,3 @@ pub const CUSTOMER_LIST_UPPER_LIMIT: u16 = 100;
/// Customer List Default Limit
pub const CUSTOMER_LIST_DEFAULT_LIMIT: u16 = 20;
-
-/// Default payment intent statuses that trigger a webhook
-pub const DEFAULT_PAYMENT_WEBHOOK_TRIGGER_STATUSES: &[common_enums::IntentStatus] = &[
- common_enums::IntentStatus::Succeeded,
- common_enums::IntentStatus::Failed,
- common_enums::IntentStatus::PartiallyCaptured,
- common_enums::IntentStatus::RequiresMerchantAction,
- common_enums::IntentStatus::RequiresCapture,
-];
-
-/// Default refund statuses that trigger a webhook
-pub const DEFAULT_REFUND_WEBHOOK_TRIGGER_STATUSES: &[common_enums::RefundStatus] = &[
- common_enums::RefundStatus::Success,
- common_enums::RefundStatus::Failure,
- common_enums::RefundStatus::TransactionFailure,
-];
-
-/// Default payout statuses that trigger a webhook
-pub const DEFAULT_PAYOUT_WEBHOOK_TRIGGER_STATUSES: &[common_enums::PayoutStatus] = &[
- common_enums::PayoutStatus::Success,
- common_enums::PayoutStatus::Failed,
- common_enums::PayoutStatus::Initiated,
- common_enums::PayoutStatus::Pending,
-];
diff --git a/crates/hyperswitch_domain_models/src/business_profile.rs b/crates/hyperswitch_domain_models/src/business_profile.rs
index 8eded7234d..003b1f6975 100644
--- a/crates/hyperswitch_domain_models/src/business_profile.rs
+++ b/crates/hyperswitch_domain_models/src/business_profile.rs
@@ -1560,37 +1560,34 @@ impl Profile {
)
}
- pub fn get_payment_webhook_statuses(&self) -> Cow<'_, [common_enums::IntentStatus]> {
+ pub fn get_configured_payment_webhook_statuses(
+ &self,
+ ) -> Option<Cow<'_, [common_enums::IntentStatus]>> {
self.webhook_details
.as_ref()
.and_then(|details| details.payment_statuses_enabled.as_ref())
.filter(|statuses_vec| !statuses_vec.is_empty())
.map(|statuses_vec| Cow::Borrowed(statuses_vec.as_slice()))
- .unwrap_or_else(|| {
- Cow::Borrowed(common_types::consts::DEFAULT_PAYMENT_WEBHOOK_TRIGGER_STATUSES)
- })
}
- pub fn get_refund_webhook_statuses(&self) -> Cow<'_, [common_enums::RefundStatus]> {
+ pub fn get_configured_refund_webhook_statuses(
+ &self,
+ ) -> Option<Cow<'_, [common_enums::RefundStatus]>> {
self.webhook_details
.as_ref()
.and_then(|details| details.refund_statuses_enabled.as_ref())
.filter(|statuses_vec| !statuses_vec.is_empty())
.map(|statuses_vec| Cow::Borrowed(statuses_vec.as_slice()))
- .unwrap_or_else(|| {
- Cow::Borrowed(common_types::consts::DEFAULT_REFUND_WEBHOOK_TRIGGER_STATUSES)
- })
}
- pub fn get_payout_webhook_statuses(&self) -> Cow<'_, [common_enums::PayoutStatus]> {
+ pub fn get_configured_payout_webhook_statuses(
+ &self,
+ ) -> Option<Cow<'_, [common_enums::PayoutStatus]>> {
self.webhook_details
.as_ref()
.and_then(|details| details.payout_statuses_enabled.as_ref())
.filter(|statuses_vec| !statuses_vec.is_empty())
.map(|statuses_vec| Cow::Borrowed(statuses_vec.as_slice()))
- .unwrap_or_else(|| {
- Cow::Borrowed(common_types::consts::DEFAULT_PAYOUT_WEBHOOK_TRIGGER_STATUSES)
- })
}
pub fn get_billing_processor_id(
diff --git a/crates/router/src/utils.rs b/crates/router/src/utils.rs
index 18bbcaeb4d..8fd71114d8 100644
--- a/crates/router/src/utils.rs
+++ b/crates/router/src/utils.rs
@@ -1175,9 +1175,12 @@ where
D: payments_core::OperationSessionGetters<F>,
{
let status = payment_data.get_payment_intent().status;
+
+ // Trigger an outgoing webhook regardless of the current payment intent status if nothing is configured in the profile.
let should_trigger_webhook = business_profile
- .get_payment_webhook_statuses()
- .contains(&status);
+ .get_configured_payment_webhook_statuses()
+ .map(|statuses| statuses.contains(&status))
+ .unwrap_or(true);
if should_trigger_webhook {
let captures = payment_data
@@ -1277,9 +1280,11 @@ pub async fn trigger_refund_outgoing_webhook(
id: profile_id.get_string_repr().to_owned(),
})?;
+ // Trigger an outgoing webhook regardless of the current refund status if nothing is configured in the profile.
let should_trigger_webhook = business_profile
- .get_refund_webhook_statuses()
- .contains(&refund_status);
+ .get_configured_refund_webhook_statuses()
+ .map(|statuses| statuses.contains(&refund_status))
+ .unwrap_or(true);
if should_trigger_webhook {
let event_type = refund_status.into();
@@ -1348,9 +1353,12 @@ pub async fn trigger_payouts_webhook(
})?;
let status = &payout_response.status;
+
+ // Trigger an outgoing webhook regardless of the current payout status if nothing is configured in the profile.
let should_trigger_webhook = business_profile
- .get_payout_webhook_statuses()
- .contains(status);
+ .get_configured_payout_webhook_statuses()
+ .map(|statuses| statuses.contains(status))
+ .unwrap_or(true);
if should_trigger_webhook {
let event_type = (*status).into();