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
feat(core): add webhook setup event handler (#9420)
Sakil Mostak740f3af64304
diff --git a/crates/api_models/src/webhooks.rs b/crates/api_models/src/webhooks.rsindex bb58a0dc44..5885f7fb98 100644--- a/crates/api_models/src/webhooks.rs+++ b/crates/api_models/src/webhooks.rs@@ -66,6 +66,7 @@ pub enum IncomingWebhookEvent {RecoveryPaymentPending,#[cfg(all(feature = "revenue_recovery", feature = "v2"))]RecoveryInvoiceCancel,+ SetupWebhook,}impl IncomingWebhookEvent {@@ -143,6 +144,7 @@ pub enum WebhookFlow {FraudCheck,#[cfg(all(feature = "revenue_recovery", feature = "v2"))]Recovery,+ Setup,}#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]@@ -297,6 +299,7 @@ impl From<IncomingWebhookEvent> for WebhookFlow {| IncomingWebhookEvent::RecoveryPaymentFailure| IncomingWebhookEvent::RecoveryPaymentPending| IncomingWebhookEvent::RecoveryPaymentSuccess => Self::Recovery,+ IncomingWebhookEvent::SetupWebhook => Self::Setup,}}}diff --git a/crates/hyperswitch_connectors/src/connectors/wise.rs b/crates/hyperswitch_connectors/src/connectors/wise.rsindex e3c2e8f5ad..dc79d97997 100644--- a/crates/hyperswitch_connectors/src/connectors/wise.rs+++ b/crates/hyperswitch_connectors/src/connectors/wise.rs@@ -756,6 +756,16 @@ impl ConnectorIntegration<Execute, RefundsData, RefundsResponseData> for Wise {}impl ConnectorIntegration<RSync, RefundsData, RefundsResponseData> for Wise {}+#[cfg(feature = "payouts")]+fn is_setup_webhook_event(request: &IncomingWebhookRequestDetails<'_>) -> bool {+ let test_webhook_header = request+ .headers+ .get("X-Test-Notification")+ .and_then(|header_value| String::from_utf8(header_value.as_bytes().to_vec()).ok());++ test_webhook_header == Some("true".to_string())+}+#[async_trait::async_trait]impl IncomingWebhook for Wise {fn get_webhook_source_verification_algorithm(@@ -833,6 +843,10 @@ impl IncomingWebhook for Wise {) -> CustomResult<IncomingWebhookEvent, ConnectorError> {#[cfg(feature = "payouts")]{+ if is_setup_webhook_event(request) {+ return Ok(IncomingWebhookEvent::SetupWebhook);+ }+let payload: wise::WisePayoutsWebhookBody = request.body.parse_struct("WisePayoutsWebhookBody")diff --git a/crates/router/src/core/webhooks/incoming.rs b/crates/router/src/core/webhooks/incoming.rsindex 44322d4384..84a1a7bd47 100644--- a/crates/router/src/core/webhooks/incoming.rs+++ b/crates/router/src/core/webhooks/incoming.rs@@ -271,6 +271,15 @@ async fn incoming_webhooks_core<W: types::OutgoingWebhookType>(.await?};+ // if it is a setup webhook event, return ok status+ if webhook_processing_result.event_type == webhooks::IncomingWebhookEvent::SetupWebhook {+ return Ok((+ services::ApplicationResponse::StatusOk,+ WebhookResponseTracker::NoEffect,+ serde_json::Value::default(),+ ));+ }+// Update request_details with the appropriate body (decoded for non-UCS, raw for UCS)let final_request_details = match &webhook_processing_result.decoded_body {Some(decoded_body) => IncomingWebhookRequestDetails {@@ -1443,6 +1452,7 @@ async fn relay_incoming_webhook_flow(| webhooks::WebhookFlow::ReturnResponse| webhooks::WebhookFlow::BankTransfer| webhooks::WebhookFlow::Mandate+ | webhooks::WebhookFlow::Setup| webhooks::WebhookFlow::ExternalAuthentication| webhooks::WebhookFlow::FraudCheck => Err(errors::ApiErrorResponse::NotSupported {message: "Relay webhook flow types not supported".to_string(),diff --git a/crates/router/src/core/webhooks/incoming_v2.rs b/crates/router/src/core/webhooks/incoming_v2.rsindex 25eff5d799..975a6ea3b8 100644--- a/crates/router/src/core/webhooks/incoming_v2.rs+++ b/crates/router/src/core/webhooks/incoming_v2.rs@@ -221,6 +221,15 @@ async fn incoming_webhooks_core<W: types::OutgoingWebhookType>(};logger::info!(event_type=?event_type);+ // if it is a setup webhook event, return ok status+ if event_type == webhooks::IncomingWebhookEvent::SetupWebhook {+ return Ok((+ services::ApplicationResponse::StatusOk,+ WebhookResponseTracker::NoEffect,+ serde_json::Value::default(),+ ));+ }+let is_webhook_event_supported = !matches!(event_type,webhooks::IncomingWebhookEvent::EventNotSupported@@ -360,6 +369,7 @@ async fn incoming_webhooks_core<W: types::OutgoingWebhookType>(api::WebhookFlow::ExternalAuthentication => todo!(),api::WebhookFlow::FraudCheck => todo!(),+ api::WebhookFlow::Setup => WebhookResponseTracker::NoEffect,#[cfg(feature = "payouts")]api::WebhookFlow::Payout => todo!(),diff --git a/crates/router/src/core/webhooks/recovery_incoming.rs b/crates/router/src/core/webhooks/recovery_incoming.rsindex b56477cdac..fab407e416 100644--- a/crates/router/src/core/webhooks/recovery_incoming.rs+++ b/crates/router/src/core/webhooks/recovery_incoming.rs@@ -1455,7 +1455,8 @@ impl RecoveryAction {| webhooks::IncomingWebhookEvent::PayoutCancelled| webhooks::IncomingWebhookEvent::PayoutCreated| webhooks::IncomingWebhookEvent::PayoutExpired- | webhooks::IncomingWebhookEvent::PayoutReversed => {+ | webhooks::IncomingWebhookEvent::PayoutReversed+ | webhooks::IncomingWebhookEvent::SetupWebhook => {common_types::payments::RecoveryAction::InvalidAction}webhooks::IncomingWebhookEvent::RecoveryPaymentFailure => match attempt_triggered_by {