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(core): Implement Diff Checker for Webhooks (#10019)

Debarshi Gupta03b299f5877e
diff --git a/crates/router/src/compatibility/stripe/payment_intents.rs b/crates/router/src/compatibility/stripe/payment_intents.rs
index c1666386c5..6a046d1a11 100644
--- a/crates/router/src/compatibility/stripe/payment_intents.rs
+++ b/crates/router/src/compatibility/stripe/payment_intents.rs
@@ -94,6 +94,7 @@ pub async fn payment_intents_create(
req,
api::AuthFlow::Merchant,
payments::CallConnectorAction::Trigger,
+ None,
eligible_connectors,
hyperswitch_domain_models::payments::HeaderPayload::default(),
)
@@ -176,6 +177,7 @@ pub async fn payment_intents_retrieve(
auth_flow,
payments::CallConnectorAction::Trigger,
None,
+ None,
hyperswitch_domain_models::payments::HeaderPayload::default(),
)
},
@@ -262,6 +264,7 @@ pub async fn payment_intents_retrieve_with_gateway_creds(
api::AuthFlow::Merchant,
payments::CallConnectorAction::Trigger,
None,
+ None,
hyperswitch_domain_models::payments::HeaderPayload::default(),
)
},
@@ -344,6 +347,7 @@ pub async fn payment_intents_update(
req,
auth_flow,
payments::CallConnectorAction::Trigger,
+ None,
eligible_connectors,
hyperswitch_domain_models::payments::HeaderPayload::default(),
)
@@ -436,6 +440,7 @@ pub async fn payment_intents_confirm(
req,
auth_flow,
payments::CallConnectorAction::Trigger,
+ None,
eligible_connectors,
hyperswitch_domain_models::payments::HeaderPayload::default(),
)
@@ -510,6 +515,7 @@ pub async fn payment_intents_capture(
api::AuthFlow::Merchant,
payments::CallConnectorAction::Trigger,
None,
+ None,
hyperswitch_domain_models::payments::HeaderPayload::default(),
)
},
@@ -595,6 +601,7 @@ pub async fn payment_intents_cancel(
auth_flow,
payments::CallConnectorAction::Trigger,
None,
+ None,
hyperswitch_domain_models::payments::HeaderPayload::default(),
)
},
diff --git a/crates/router/src/compatibility/stripe/setup_intents.rs b/crates/router/src/compatibility/stripe/setup_intents.rs
index 8e4e8eb101..0e64d9ff0c 100644
--- a/crates/router/src/compatibility/stripe/setup_intents.rs
+++ b/crates/router/src/compatibility/stripe/setup_intents.rs
@@ -79,6 +79,7 @@ pub async fn setup_intents_create(
api::AuthFlow::Merchant,
payments::CallConnectorAction::Trigger,
None,
+ None,
hyperswitch_domain_models::payments::HeaderPayload::default(),
)
},
@@ -160,6 +161,7 @@ pub async fn setup_intents_retrieve(
auth_flow,
payments::CallConnectorAction::Trigger,
None,
+ None,
hyperswitch_domain_models::payments::HeaderPayload::default(),
)
},
@@ -243,6 +245,7 @@ pub async fn setup_intents_update(
auth_flow,
payments::CallConnectorAction::Trigger,
None,
+ None,
hyperswitch_domain_models::payments::HeaderPayload::default(),
)
},
@@ -327,6 +330,7 @@ pub async fn setup_intents_confirm(
auth_flow,
payments::CallConnectorAction::Trigger,
None,
+ None,
hyperswitch_domain_models::payments::HeaderPayload::default(),
)
},
diff --git a/crates/router/src/core/fraud_check/operation/fraud_check_post.rs b/crates/router/src/core/fraud_check/operation/fraud_check_post.rs
index 5ebeadf900..118e9c1de4 100644
--- a/crates/router/src/core/fraud_check/operation/fraud_check_post.rs
+++ b/crates/router/src/core/fraud_check/operation/fraud_check_post.rs
@@ -271,6 +271,7 @@ where
api::AuthFlow::Merchant,
payments::CallConnectorAction::Trigger,
None,
+ None,
HeaderPayload::default(),
))
.await?;
@@ -326,6 +327,7 @@ where
api::AuthFlow::Merchant,
payments::CallConnectorAction::Trigger,
None,
+ None,
HeaderPayload::default(),
))
.await?;
diff --git a/crates/router/src/core/payments.rs b/crates/router/src/core/payments.rs
index f5e4884087..c8f2d0f14a 100644
--- a/crates/router/src/core/payments.rs
+++ b/crates/router/src/core/payments.rs
@@ -551,6 +551,7 @@ pub async fn payments_operation_core<'a, F, Req, Op, FData, D>(
operation: Op,
req: Req,
call_connector_action: CallConnectorAction,
+ shadow_ucs_call_connector_action: Option<CallConnectorAction>,
auth_flow: services::AuthFlow,
eligible_connectors: Option<Vec<common_enums::RoutableConnectors>>,
header_payload: HeaderPayload,
@@ -841,6 +842,7 @@ where
&mut payment_data,
&customer,
call_connector_action.clone(),
+ shadow_ucs_call_connector_action.clone(),
&validate_result,
schedule_time,
header_payload.clone(),
@@ -974,6 +976,7 @@ where
&mut payment_data,
&customer,
call_connector_action.clone(),
+ shadow_ucs_call_connector_action,
&validate_result,
schedule_time,
header_payload.clone(),
@@ -2118,6 +2121,7 @@ pub async fn payments_core<F, Res, Req, Op, FData, D>(
req: Req,
auth_flow: services::AuthFlow,
call_connector_action: CallConnectorAction,
+ shadow_ucs_call_connector_action: Option<CallConnectorAction>,
eligible_connectors: Option<Vec<enums::Connector>>,
header_payload: HeaderPayload,
) -> RouterResponse<Res>
@@ -2153,6 +2157,7 @@ where
operation.clone(),
req,
call_connector_action,
+ shadow_ucs_call_connector_action,
auth_flow,
eligible_routable_connectors,
header_payload.clone(),
@@ -3141,6 +3146,7 @@ impl PaymentRedirectFlow for PaymentRedirectCompleteAuthorize {
services::api::AuthFlow::Merchant,
connector_action,
None,
+ None,
HeaderPayload::default(),
))
.await?;
@@ -3302,6 +3308,7 @@ impl PaymentRedirectFlow for PaymentRedirectSync {
services::api::AuthFlow::Merchant,
connector_action,
None,
+ None,
HeaderPayload::default(),
),
)
@@ -3646,6 +3653,7 @@ impl PaymentRedirectFlow for PaymentAuthenticateCompleteAuthorize {
services::api::AuthFlow::Merchant,
connector_action,
None,
+ None,
HeaderPayload::with_source(enums::PaymentSource::ExternalAuthenticator),
))
.await?
@@ -3678,6 +3686,7 @@ impl PaymentRedirectFlow for PaymentAuthenticateCompleteAuthorize {
services::api::AuthFlow::Merchant,
connector_action,
None,
+ None,
HeaderPayload::default(),
),
)
@@ -4253,6 +4262,7 @@ pub async fn decide_unified_connector_service_call<'a, F, RouterDReq, ApiRequest
payment_data: &'a mut D,
customer: &Option<domain::Customer>,
call_connector_action: CallConnectorAction,
+ shadow_ucs_call_connector_action: Option<CallConnectorAction>,
validate_result: &'a operations::ValidateResult,
schedule_time: Option<time::PrimitiveDateTime>,
header_payload: HeaderPayload,
@@ -4286,6 +4296,7 @@ where
&router_data,
Some(payment_data),
call_connector_action.clone(),
+ shadow_ucs_call_connector_action.clone(),
)
.await?;
@@ -4324,6 +4335,7 @@ where
payment_data,
customer,
call_connector_action,
+ shadow_ucs_call_connector_action,
validate_result,
schedule_time,
header_payload,
@@ -4818,6 +4830,7 @@ where
&router_data,
Some(payment_data),
call_connector_action.clone(),
+ None,
)
.await?;
@@ -4961,6 +4974,7 @@ where
&router_data,
Some(payment_data),
call_connector_action.clone(),
+ None,
)
.await?;
if matches!(execution, ExecutionPath::UnifiedConnectorService) {
diff --git a/crates/router/src/core/payments/helpers.rs b/crates/router/src/core/payments/helpers.rs
index fbf0935c32..e3e3863795 100644
--- a/crates/router/src/core/payments/helpers.rs
+++ b/crates/router/src/core/payments/helpers.rs
@@ -8496,6 +8496,7 @@ pub async fn process_through_direct_with_shadow_unified_connector_service<
payment_data: &'a mut D,
customer: &Option<domain::Customer>,
call_connector_action: CallConnectorAction,
+ shadow_ucs_call_connector_action: Option<CallConnectorAction>,
validate_result: &'a OperationsValidateResult,
schedule_time: Option<time::PrimitiveDateTime>,
header_payload: domain_payments::HeaderPayload,
@@ -8595,6 +8596,7 @@ where
unified_connector_service_merchant_context,
unified_connector_service_merchant_order_reference_id,
call_connector_action,
+ shadow_ucs_call_connector_action,
unified_connector_service_customer,
unified_connector_service_payment_attempt_data,
unified_connector_service_connector_label,
@@ -8628,6 +8630,7 @@ pub async fn execute_shadow_unified_connector_service_call<F, RouterDReq>(
merchant_context: domain::MerchantContext,
merchant_order_reference_id: Option<String>,
call_connector_action: CallConnectorAction,
+ shadow_ucs_call_connector_action: Option<CallConnectorAction>,
customer: Option<domain::Customer>,
payment_attempt_data: PaymentAttempt,
unified_connector_service_connector_label: Option<String>,
@@ -8665,7 +8668,7 @@ where
connector_data,
ExecutionMode::Shadow, // Shadow mode for UCS
merchant_order_reference_id,
- call_connector_action,
+ shadow_ucs_call_connector_action.unwrap_or(call_connector_action),
)
.await
.map_err(|e| router_env::logger::debug!("Shadow UCS call failed: {:?}", e));
diff --git a/crates/router/src/core/payments/retry.rs b/crates/router/src/core/payments/retry.rs
index 5f9ff29e67..a4ce3c2273 100644
--- a/crates/router/src/core/payments/retry.rs
+++ b/crates/router/src/core/payments/retry.rs
@@ -405,6 +405,7 @@ where
payment_data,
customer,
payments::CallConnectorAction::Trigger,
+ None,
validate_result,
schedule_time,
hyperswitch_domain_models::payments::HeaderPayload::default(),
diff --git a/crates/router/src/core/refunds.rs b/crates/router/src/core/refunds.rs
index 72348017fd..2bf04ee35a 100644
--- a/crates/router/src/core/refunds.rs
+++ b/crates/router/src/core/refunds.rs
@@ -236,6 +236,7 @@ pub async fn trigger_refund_to_gateway(
&router_data,
None::<&payments::PaymentData<api::Execute>>, // No payment data for refunds
payments::CallConnectorAction::Trigger,
+ None,
)
.await?;
@@ -838,6 +839,7 @@ pub async fn sync_refund_with_gateway(
&router_data,
None::<&payments::PaymentData<api::RSync>>, // No payment data for refunds
payments::CallConnectorAction::Trigger,
+ None,
)
.await?;
diff --git a/crates/router/src/core/unified_connector_service.rs b/crates/router/src/core/unified_connector_service.rs
index 96182d41e2..e0917f26f8 100644
--- a/crates/router/src/core/unified_connector_service.rs
+++ b/crates/router/src/core/unified_connector_service.rs
@@ -176,6 +176,7 @@ pub async fn should_call_unified_connector_service<F: Clone, T, R, D>(
router_data: &RouterData<F, T, R>,
payment_data: Option<&D>,
call_connector_action: CallConnectorAction,
+ shadow_ucs_call_connector_action: Option<CallConnectorAction>,
) -> RouterResult<(ExecutionPath, SessionState)>
where
D: OperationSessionGetters<F>,
@@ -269,7 +270,14 @@ where
router_env::logger::info!(
"CallConnectorAction HandleResponse received, using Direct gateway"
);
- (GatewaySystem::Direct, ExecutionPath::Direct)
+ if shadow_ucs_call_connector_action.is_some() {
+ (
+ GatewaySystem::Direct,
+ ExecutionPath::ShadowUnifiedConnectorService,
+ )
+ } else {
+ (GatewaySystem::Direct, ExecutionPath::Direct)
+ }
}
CallConnectorAction::Trigger
| CallConnectorAction::Avoid
@@ -562,36 +570,90 @@ pub async fn should_call_unified_connector_service_for_webhooks(
state: &SessionState,
merchant_context: &MerchantContext,
connector_name: &str,
-) -> RouterResult<bool> {
- if state.grpc_client.unified_connector_service_client.is_none() {
- logger::debug!(
- connector = connector_name.to_string(),
- "Unified Connector Service client is not available for webhooks"
- );
- return Ok(false);
- }
-
- let ucs_config_key = consts::UCS_ENABLED;
-
- if !is_ucs_enabled(state, ucs_config_key).await {
- return Ok(false);
- }
-
+) -> RouterResult<ExecutionPath> {
+ // Extract context information
let merchant_id = merchant_context
.get_merchant_account()
.get_id()
.get_string_repr();
- let config_key = format!(
- "{}_{}_{}_Webhooks",
+ let connector_enum = Connector::from_str(connector_name)
+ .change_context(errors::ApiErrorResponse::IncorrectConnectorNameGiven)
+ .attach_printable_lazy(|| format!("Failed to parse connector name: {}", connector_name))?;
+
+ let flow_name = "Webhooks";
+
+ // Check UCS availability using idiomatic helper
+ let ucs_availability = check_ucs_availability(state).await;
+
+ // Build rollout keys - webhooks don't use payment method, so use a simplified key format
+ let rollout_key = format!(
+ "{}_{}_{}_{}",
consts::UCS_ROLLOUT_PERCENT_CONFIG_PREFIX,
merchant_id,
- connector_name
+ connector_name,
+ flow_name
);
+ let shadow_rollout_key = format!("{rollout_key}_shadow");
+
+ // Determine connector integration type
+ let connector_integration_type =
+ determine_connector_integration_type(state, connector_enum, &rollout_key).await?;
+
+ // For webhooks, there is no previous gateway system to consider (webhooks are stateless)
+ let previous_gateway = None;
- let rollout_result = should_execute_based_on_rollout(state, &config_key).await?;
+ // Check both rollout keys to determine priority based on shadow percentage
+ let rollout_result = should_execute_based_on_rollout(state, &rollout_key).await?;
+ let shadow_rollout_result = should_execute_based_on_rollout(state, &shadow_rollout_key).await?;
+
+ // Get shadow percentage to determine priority
+ let shadow_percentage = get_rollout_percentage(state, &shadow_rollout_key)
+ .await
+ .unwrap_or(0.0);
+
+ let shadow_rollout_availability =
+ if shadow_rollout_result.should_execute && shadow_percentage != 0.0 {
+ // Shadow is present and percentage is non-zero, use shadow
+ router_env::logger::debug!(
+ shadow_percentage = shadow_percentage,
+ "Shadow rollout is present with non-zero percentage for webhooks, using shadow"
+ );
+ ShadowRolloutAvailability::IsAvailable
+ } else if rollout_result.should_execute {
+ // Either shadow is 0.0 or not present, use rollout if available
+ router_env::logger::debug!(
+ shadow_percentage = shadow_percentage,
+ "Shadow rollout is 0.0 or not present for webhooks, using rollout"
+ );
+ ShadowRolloutAvailability::IsAvailable
+ } else {
+ ShadowRolloutAvailability::NotAvailable
+ };
+
+ // Use the same decision logic as payments, with no call_connector_action to consider
+ let (gateway_system, execution_path) = if ucs_availability == UcsAvailability::Disabled {
+ router_env::logger::debug!("UCS is disabled for webhooks, using Direct gateway");
+ (GatewaySystem::Direct, ExecutionPath::Direct)
+ } else {
+ // UCS is enabled, use decide function with no previous gateway for webhooks
+ decide_execution_path(
+ connector_integration_type,
+ previous_gateway,
+ shadow_rollout_availability,
+ )?
+ };
+
+ router_env::logger::info!(
+ "Webhook gateway decision: gateway={:?}, execution_path={:?} - merchant_id={}, connector={}, flow={}",
+ gateway_system,
+ execution_path,
+ merchant_id,
+ connector_name,
+ flow_name
+ );
- Ok(rollout_result.should_execute)
+ Ok(execution_path)
}
pub fn build_unified_connector_service_payment_method(
diff --git a/crates/router/src/core/webhooks/incoming.rs b/crates/router/src/core/webhooks/incoming.rs
index 65abf6b2f8..f03604859f 100644
--- a/crates/router/src/core/webhooks/incoming.rs
+++ b/crates/router/src/core/webhooks/incoming.rs
@@ -229,15 +229,17 @@ async fn incoming_webhooks_core<W: types::OutgoingWebhookType>(
fetch_optional_mca_and_connector(&state, &merchant_context, connector_name_or_mca_id)
.await?;
- // Determine webhook processing path (UCS vs non-UCS) and handle event type extraction
- let webhook_processing_result =
- match if unified_connector_service::should_call_unified_connector_service_for_webhooks(
+ // Determine webhook processing path (Direct vs UCS vs Shadow UCS) and handle event type extraction
+ let execution_path =
+ unified_connector_service::should_call_unified_connector_service_for_webhooks(
&state,
&merchant_context,
&connector_name,
)
- .await?
- {
+ .await?;
+
+ let webhook_processing_result = match execution_path {
+ common_enums::ExecutionPath::UnifiedConnectorService => {
logger::info!(
connector = connector_name,
"Using Unified Connector Service for webhook processing",
@@ -251,8 +253,29 @@ async fn incoming_webhooks_core<W: types::OutgoingWebhookType>(
merchant_connector_account.as_ref(),
)
.await
- } else {
- // NON-UCS PATH: Need to decode body first
+ }
+ common_enums::ExecutionPath::ShadowUnifiedConnectorService => {
+ logger::info!(
+ connector = connector_name,
+ "Using Shadow Unified Connector Service for webhook processing",
+ );
+ process_shadow_ucs_webhook_transform(
+ &state,
+ &merchant_context,
+ &connector,
+ &connector_name,
+ &body,
+ &request_details,
+ merchant_connector_account.as_ref(),
+ )
+ .await
+ }
+ common_enums::ExecutionPath::Direct => {
+ logger::info!(
+ connector = connector_name,
+ "Using Direct connector processing for webhook",
+ );
+ // DIRECT PATH: Need to decode body first
let decoded_body = connector
.decode_webhook_body(
&request_details,
@@ -275,24 +298,27 @@ async fn incoming_webhooks_core<W: types::OutgoingWebhookType>(
&request_details,
)
.await
- } {
- Ok(result) => result,
- Err(error) => {
- let error_result = handle_incoming_webhook_error(
- error,
- &connector,
- connector_name.as_str(),
- &request_details,
- merchant_context.get_merchant_account().get_id(),
- );
- match error_result {
- Ok((response, webhook_tracker, serialized_request)) => {
- return Ok((response, webhook_tracker, serialized_request));
- }
- Err(e) => return Err(e),
+ }
+ };
+
+ let mut webhook_processing_result = match webhook_processing_result {
+ Ok(result) => result,
+ Err(error) => {
+ let error_result = handle_incoming_webhook_error(
+ error,
+ &connector,
+ connector_name.as_str(),
+ &request_details,
+ merchant_context.get_merchant_account().get_id(),
+ );
+ match error_result {
+ Ok((response, webhook_tracker, serialized_request)) => {
+ return Ok((response, webhook_tracker, serialized_request));
}
+ Err(e) => return Err(e),
}
- };
+ }
+ };
// if it is a setup webhook event, return ok status
if webhook_processing_result.event_type == webhooks::IncomingWebhookEvent::SetupWebhook {
@@ -305,14 +331,14 @@ async fn incoming_webhooks_core<W: types::OutgoingWebhookType>(
// 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 {
+ Some(decoded_body) => &IncomingWebhookRequestDetails {
method: request_details.method.clone(),
uri: request_details.uri.clone(),
headers: request_details.headers,
query_params: request_details.query_params.clone(),
body: decoded_body,
},
- None => request_details, // Use original request details for UCS
+ None => &request_details, // Use original request details for UCS
};
logger::info!(event_type=?webhook_processing_result.event_type);
@@ -347,7 +373,8 @@ async fn incoming_webhooks_core<W: types::OutgoingWebhookType>(
webhook_processing_result.event_type,
webhook_processing_result.source_verified,
&webhook_processing_result.transform_data,
- &final_request_details,
+ &mut webhook_processing_result.shadow_ucs_data,
+ final_request_details,
is_relay_webhook,
)
.await;
@@ -358,7 +385,7 @@ async fn incoming_webhooks_core<W: types::OutgoingWebhookType>(
event_object = extract_webhook_event_object(
&webhook_processing_result.transform_data,
&connector,
- &final_request_details,
+ final_request_details,
)?;
response
}
@@ -367,7 +394,7 @@ async fn incoming_webhooks_core<W: types::OutgoingWebhookType>(
error,
&connector,
connector_name.as_str(),
- &final_request_details,
+ final_request_details,
merchant_context.get_merchant_account().get_id(),
);
match error_result {
@@ -391,7 +418,7 @@ async fn incoming_webhooks_core<W: types::OutgoingWebhookType>(
// Generate response
let response = connector
- .get_webhook_api_response(&final_request_details, None)
+ .get_webhook_api_response(final_request_details, None)
.switch()
.attach_printable("Could not get incoming webhook api response from connector")?;
@@ -404,14 +431,14 @@ async fn incoming_webhooks_core<W: types::OutgoingWebhookType>(
}
/// Process UCS webhook transformation using the high-level UCS abstraction
-async fn process_ucs_webhook_transform(
- state: &SessionState,
- merchant_context: &domain::MerchantContext,
- connector_name: &str,
- body: &actix_web::web::Bytes,
- request_details: &IncomingWebhookRequestDetails<'_>,
- merchant_connector_account: Option<&domain::MerchantConnectorAccount>,
-) -> errors::RouterResult<WebhookProcessingResult> {
+async fn process_ucs_webhook_transform<'a>(
+ state: &'a SessionState,
+ merchant_context: &'a domain::MerchantContext,
+ connector_name: &'a str,
+ body: &'a actix_web::web::Bytes,
+ request_details: &'a IncomingWebhookRequestDetails<'a>,
+ merchant_connector_account: Option<&'a domain::MerchantConnectorAccount>,
+) -> errors::RouterResult<WebhookProcessingResult<'a>> {
// Use the new UCS abstraction which provides clean separation
let (event_type, source_verified, transform_data) =
unified_connector_service::call_unified_connector_service_for_webhook(
@@ -428,25 +455,154 @@ async fn process_ucs_webhook_transform(
source_verified,
transform_data: Some(Box::new(transform_data)),
decoded_body: None, // UCS path uses raw body
+ shadow_ucs_data: None,
})
}
+
+/// Shadow UCS data container
+#[allow(dead_code)]
+pub struct ShadowUcsData<'a> {
+ ucs_source_verified: bool,
+ ucs_event_type: webhooks::IncomingWebhookEvent,
+ ucs_transform_data: Box<unified_connector_service::WebhookTransformData>,
+ request_details: &'a IncomingWebhookRequestDetails<'a>,
+ webhook_details: Option<api::IncomingWebhookDetails>,
+}
+
/// Result type for webhook processing path determination
-pub struct WebhookProcessingResult {
+pub struct WebhookProcessingResult<'a> {
event_type: webhooks::IncomingWebhookEvent,
source_verified: bool,
transform_data: Option<Box<unified_connector_service::WebhookTransformData>>,
decoded_body: Option<actix_web::web::Bytes>,
+ shadow_ucs_data: Option<ShadowUcsData<'a>>,
+}
+
+/// Process shadow UCS webhook transformation with dual execution (UCS + Direct)
+async fn process_shadow_ucs_webhook_transform<'a>(
+ state: &'a SessionState,
+ merchant_context: &'a domain::MerchantContext,
+ connector: &'a ConnectorEnum,
+ connector_name: &'a str,
+ body: &'a actix_web::web::Bytes,
+ request_details: &'a IncomingWebhookRequestDetails<'a>,
+ merchant_connector_account: Option<&'a domain::MerchantConnectorAccount>,
+) -> errors::RouterResult<WebhookProcessingResult<'a>> {
+ // Execute UCS path
+ let ucs_result = unified_connector_service::call_unified_connector_service_for_webhook(
+ state,
+ merchant_context,
+ connector_name,
+ body,
+ request_details,
+ merchant_connector_account,
+ )
+ .await;
+
+ // Execute Direct path for comparison
+ let direct_result = async {
+ // Decode body for direct processing
+ let decoded_body = connector
+ .decode_webhook_body(
+ request_details,
+ merchant_context.get_merchant_account().get_id(),
+ merchant_connector_account.and_then(|mca| mca.connector_webhook_details.clone()),
+ connector_name,
+ )
+ .await
+ .switch()
+ .attach_printable(
+ "There was an error in incoming webhook body decoding for shadow processing",
+ )?;
+
+ // Reuse existing process_non_ucs_webhook function
+ process_non_ucs_webhook(
+ state,
+ merchant_context,
+ connector,
+ connector_name,
+ decoded_body.into(),
+ request_details,
+ )
+ .await
+ }
+ .await;
+
+ // Handle results and comparison
+ match (ucs_result, direct_result) {
+ (
+ Ok((ucs_event_type, ucs_source_verified, ucs_transform_data)),
+ Ok(mut direct_processing_result),
+ ) => {
+ // Log both calls succeeded
+ logger::info!(
+ connector = connector_name,
+ merchant_id = ?merchant_context.get_merchant_account().get_id(),
+ "Shadow UCS: Both UCS and Direct calls succeeded"
+ );
+
+ // Create ShadowUcsData with UCS results
+ let shadow_ucs_data = ShadowUcsData {
+ ucs_source_verified,
+ ucs_event_type,
+ ucs_transform_data: Box::new(ucs_transform_data),
+ request_details,
+ webhook_details: None,
+ };
+
+ // Return Direct result as primary with UCS data in shadow_ucs_data
+ direct_processing_result.shadow_ucs_data = Some(shadow_ucs_data);
+ Ok(direct_processing_result)
+ }
+ (Ok((_, _, _)), Err(direct_error)) => {
+ // Log UCS call succeeded, direct call failed
+ logger::info!(
+ connector = connector_name,
+ merchant_id = ?merchant_context.get_merchant_account().get_id(),
+ direct_error = ?direct_error,
+ "Shadow UCS: UCS call succeeded, Direct call failed"
+ );
+
+ // Return direct_result error as required
+ Err(direct_error)
+ }
+ (Err(ucs_error), Ok(direct_processing_result)) => {
+ // Log the UCS error and direct result succeeded
+ logger::info!(
+ connector = connector_name,
+ merchant_id = ?merchant_context.get_merchant_account().get_id(),
+ ucs_error = ?ucs_error,
+ "Shadow UCS: UCS call failed, Direct call succeeded"
+ );
+
+ // In shadow mode, if UCS fails, fall back to Direct result
+ Ok(direct_processing_result)
+ }
+ (Err(ucs_error), Err(direct_error)) => {
+ // Log both the errors and both call failed
+ logger::error!(
+ connector = connector_name,
+ merchant_id = ?merchant_context.get_merchant_account().get_id(),
+ ucs_error = ?ucs_error,
+ direct_error = ?direct_error,
+ "Shadow UCS: Both UCS and Direct calls failed"
+ );
+
+ // Return direct_result error as required
+ Err(direct_error)
+ }
+ }
}
/// Process non-UCS webhook using traditional connector processing
-async fn process_non_ucs_webhook(
- state: &SessionState,
- merchant_context: &domain::MerchantContext,
- connector: &ConnectorEnum,
- connector_name: &str,
+async fn process_non_ucs_webhook<'a>(
+ state: &'a SessionState,
+ merchant_context: &'a domain::MerchantContext,
+ connector: &'a ConnectorEnum,
+ connector_name: &'a str,
decoded_body: actix_web::web::Bytes,
- request_details: &IncomingWebhookRequestDetails<'_>,
-) -> errors::RouterResult<WebhookProcessingResult> {
+ request_details: &'a IncomingWebhookRequestDetails<'a>,
+) -> errors::RouterResult<WebhookProcessingResult<'a>> {
// Create request_details with decoded body for connector processing
let updated_request_details = IncomingWebhookRequestDetails {
method: request_details.method.clone(),
@@ -475,6 +631,7 @@ async fn process_non_ucs_webhook(
source_verified: false,
transform_data: None,
decoded_body: Some(decoded_body),
+ shadow_ucs_data: None,
}),
None => {
metrics::WEBHOOK_EVENT_TYPE_IDENTIFICATION_FAILURE_COUNT.add(
@@ -555,6 +712,7 @@ async fn process_webhook_business_logic(
event_type: webhooks::IncomingWebhookEvent,
source_verified_via_ucs: bool,
webhook_transform_data: &Option<Box<unified_connector_service::WebhookTransformData>>,
+ shadow_ucs_data: &mut Option<ShadowUcsData<'_>>,
request_details: &IncomingWebhookRequestDetails<'_>,
is_relay_webhook: bool,
) -> errors::RouterResult<WebhookResponseTracker> {
@@ -696,6 +854,73 @@ async fn process_webhook_business_logic(
)?,
};
+ // Create shadow_event_object and shadow_webhook_details using shadow UCS data
+ let shadow_event_object: Option<Box<dyn masking::ErasedMaskSerialize>> =
+ shadow_ucs_data.as_ref().and_then(|shadow_data| {
+ // Create shadow event object using UCS transform data and shadow request details
+ let shadow_event_result = shadow_data
+ .ucs_transform_data
+ .webhook_content
+ .as_ref()
+ .map(|webhook_response_content| {
+ get_ucs_webhook_resource_object(webhook_response_content)
+ })
+ .unwrap_or_else(|| {
+ // Fall back to connector extraction using shadow request details
+ connector
+ .get_webhook_resource_object(shadow_data.request_details)
+ .switch()
+ .attach_printable(
+ "Could not find resource object in shadow incoming webhook body",
+ )
+ });
+
+ match shadow_event_result {
+ Ok(shadow_obj) => Some(shadow_obj),
+ Err(error) => {
+ logger::warn!(
+ connector = connector_name,
+ merchant_id = ?merchant_context.get_merchant_account().get_id(),
+ error = ?error,
+ "Failed to create shadow event object from UCS transform data"
+ );
+ None
+ }
+ }
+ });
+
+ let shadow_webhook_details: Option<api::IncomingWebhookDetails> =
+ shadow_event_object.as_ref().and_then(|shadow_obj| {
+ let resource_object_result = serde_json::to_vec(shadow_obj)
+ .change_context(errors::ParsingError::EncodeError("byte-vec"))
+ .attach_printable("Unable to convert shadow webhook payload to a value")
+ .change_context(errors::ApiErrorResponse::InternalServerError)
+ .attach_printable(
+ "There was an issue when encoding the shadow incoming webhook body to bytes",
+ );
+
+ match resource_object_result {
+ Ok(resource_object) => Some(api::IncomingWebhookDetails {
+ object_reference_id: object_ref_id.clone(),
+ resource_object,
+ }),
+ Err(error) => {
+ logger::warn!(
+ connector = connector_name,
+ merchant_id = ?merchant_context.get_merchant_account().get_id(),
+ error = ?error,
+ "Failed to serialize shadow webhook payload to bytes"
+ );
+ None
+ }
+ }
+ });
+
+ // Assign shadow_webhook_details to shadow_ucs_data
+ if let Some(shadow_data) = shadow_ucs_data.as_mut() {
+ shadow_data.webhook_details = shadow_webhook_details;
+ }
+
let profile_id = &merchant_connector_account.profile_id;
let key_manager_state = &(state).into();
@@ -760,6 +985,7 @@ async fn process_webhook_business_logic(
request_details,
event_type,
webhook_transform_data,
+ shadow_ucs_data,
))
.await
.attach_printable("Incoming webhook flow for payments failed"),
@@ -1026,6 +1252,7 @@ async fn payments_incoming_webhook_flow(
request_details: &IncomingWebhookRequestDetails<'_>,
event_type: webhooks::IncomingWebhookEvent,
webhook_transform_data: &Option<Box<unified_connector_service::WebhookTransformData>>,
+ shadow_ucs_data: &Option<ShadowUcsData<'_>>,
) -> CustomResult<WebhookResponseTracker, errors::ApiErrorResponse> {
let consume_or_trigger_flow = if source_verified {
// Determine the appropriate action based on UCS availability
@@ -1049,6 +1276,31 @@ async fn payments_incoming_webhook_flow(
} else {
payments::CallConnectorAction::Trigger
};
+
+ // Determine shadow UCS call connector action based on shadow UCS data
+ let shadow_ucs_call_connector_action = shadow_ucs_data.as_ref().and_then(|shadow_data| {
+ if shadow_data.ucs_source_verified {
+ // Proceed with the match case of webhook_transformation_status
+ shadow_data.webhook_details.as_ref().map(|webhook_details| {
+ match shadow_data.ucs_transform_data.webhook_transformation_status {
+ unified_connector_service::WebhookTransformationStatus::Complete => {
+ payments::CallConnectorAction::UCSConsumeResponse(
+ webhook_details.resource_object.clone(),
+ )
+ }
+ unified_connector_service::WebhookTransformationStatus::Incomplete => {
+ payments::CallConnectorAction::UCSHandleResponse(
+ webhook_details.resource_object.clone(),
+ )
+ }
+ }
+ })
+ } else {
+ // If ucs_source_verified is not true, use Trigger action
+ Some(payments::CallConnectorAction::Trigger)
+ }
+ });
+
let payments_response = match webhook_details.object_reference_id {
webhooks::ObjectReferenceId::PaymentId(ref id) => {
let payment_id = get_payment_id(
@@ -1102,6 +1354,7 @@ async fn payments_incoming_webhook_flow(
},
services::AuthFlow::Merchant,
consume_or_trigger_flow.clone(),
+ shadow_ucs_call_connector_action,
None,
HeaderPayload::default(),
))
@@ -1793,6 +2046,7 @@ async fn external_authentication_incoming_webhook_flow(
services::api::AuthFlow::Merchant,
payments::CallConnectorAction::Trigger,
None,
+ None,
HeaderPayload::with_source(enums::PaymentSource::ExternalAuthenticator),
))
.await?;
@@ -1984,6 +2238,7 @@ async fn frm_incoming_webhook_flow(
services::api::AuthFlow::Merchant,
payments::CallConnectorAction::Trigger,
None,
+ None,
HeaderPayload::default(),
))
.await?
@@ -2012,6 +2267,7 @@ async fn frm_incoming_webhook_flow(
services::api::AuthFlow::Merchant,
payments::CallConnectorAction::Trigger,
None,
+ None,
HeaderPayload::default(),
))
.await?
@@ -2169,6 +2425,7 @@ async fn bank_transfer_webhook_flow(
services::api::AuthFlow::Merchant,
payments::CallConnectorAction::Trigger,
None,
+ None,
HeaderPayload::with_source(common_enums::PaymentSource::Webhook),
))
.await
diff --git a/crates/router/src/routes/payments.rs b/crates/router/src/routes/payments.rs
index 7bbd2bf1f5..44071619f6 100644
--- a/crates/router/src/routes/payments.rs
+++ b/crates/router/src/routes/payments.rs
@@ -525,6 +525,7 @@ pub async fn payments_start(
api::AuthFlow::Client,
payments::CallConnectorAction::Trigger,
None,
+ None,
HeaderPayload::default(),
)
},
@@ -611,6 +612,7 @@ pub async fn payments_retrieve(
auth_flow,
payments::CallConnectorAction::Trigger,
None,
+ None,
header_payload.clone(),
)
},
@@ -688,6 +690,7 @@ pub async fn payments_retrieve_with_gateway_creds(
api::AuthFlow::Merchant,
payments::CallConnectorAction::Trigger,
None,
+ None,
HeaderPayload::default(),
)
},
@@ -815,6 +818,7 @@ pub async fn payments_post_session_tokens(
api::AuthFlow::Client,
payments::CallConnectorAction::Trigger,
None,
+ None,
header_payload.clone(),
)
},
@@ -875,6 +879,7 @@ pub async fn payments_update_metadata(
api::AuthFlow::Client,
payments::CallConnectorAction::Trigger,
None,
+ None,
header_payload.clone(),
)
},
@@ -1012,6 +1017,7 @@ pub async fn payments_capture(
api::AuthFlow::Merchant,
payments::CallConnectorAction::Trigger,
None,
+ None,
HeaderPayload::default(),
)
},
@@ -1076,6 +1082,7 @@ pub async fn payments_dynamic_tax_calculation(
api::AuthFlow::Client,
payments::CallConnectorAction::Trigger,
None,
+ None,
header_payload.clone(),
)
},
@@ -1203,6 +1210,7 @@ pub async fn payments_connector_session(
api::AuthFlow::Client,
payments::CallConnectorAction::Trigger,
None,
+ None,
header_payload.clone(),
)
},
@@ -1482,6 +1490,7 @@ pub async fn payments_complete_authorize(
auth_flow,
payments::CallConnectorAction::Trigger,
None,
+ None,
HeaderPayload::default(),
)
},
@@ -1533,6 +1542,7 @@ pub async fn payments_cancel(
api::AuthFlow::Merchant,
payments::CallConnectorAction::Trigger,
None,
+ None,
HeaderPayload::default(),
)
},
@@ -1665,6 +1675,7 @@ pub async fn payments_cancel_post_capture(
api::AuthFlow::Merchant,
payments::CallConnectorAction::Trigger,
None,
+ None,
HeaderPayload::default(),
)
},
@@ -2037,6 +2048,7 @@ pub async fn payments_approve(
api::AuthFlow::Merchant,
payments::CallConnectorAction::Trigger,
None,
+ None,
HeaderPayload::default(),
)
},
@@ -2109,6 +2121,7 @@ pub async fn payments_reject(
api::AuthFlow::Merchant,
payments::CallConnectorAction::Trigger,
None,
+ None,
HeaderPayload::default(),
)
},
@@ -2217,6 +2230,7 @@ where
req,
auth_flow,
payments::CallConnectorAction::Trigger,
+ None,
eligible_connectors,
header_payload,
)
@@ -2239,6 +2253,7 @@ where
req,
auth_flow,
payments::CallConnectorAction::Trigger,
+ None,
eligible_connectors,
header_payload,
)
@@ -2290,6 +2305,7 @@ pub async fn payments_incremental_authorization(
api::AuthFlow::Merchant,
payments::CallConnectorAction::Trigger,
None,
+ None,
HeaderPayload::default(),
)
},
@@ -2342,6 +2358,7 @@ pub async fn payments_extend_authorization(
api::AuthFlow::Merchant,
payments::CallConnectorAction::Trigger,
None,
+ None,
HeaderPayload::default(),
)
},
diff --git a/crates/router/src/workflows/outgoing_webhook_retry.rs b/crates/router/src/workflows/outgoing_webhook_retry.rs
index 17c1062e24..5ba5e86540 100644
--- a/crates/router/src/workflows/outgoing_webhook_retry.rs
+++ b/crates/router/src/workflows/outgoing_webhook_retry.rs
@@ -421,6 +421,7 @@ async fn get_outgoing_webhook_content_and_event_type(
AuthFlow::Client,
CallConnectorAction::Avoid,
None,
+ None,
hyperswitch_domain_models::payments::HeaderPayload::default(),
))
.await?
diff --git a/crates/router/src/workflows/payment_sync.rs b/crates/router/src/workflows/payment_sync.rs
index a927e8a869..3c813190ff 100644
--- a/crates/router/src/workflows/payment_sync.rs
+++ b/crates/router/src/workflows/payment_sync.rs
@@ -95,6 +95,7 @@ impl ProcessTrackerWorkflow<SessionState> for PaymentsSyncWorkflow {
operations::PaymentStatus,
tracking_data.clone(),
payment_flows::CallConnectorAction::Trigger,
+ None,
services::AuthFlow::Client,
None,
hyperswitch_domain_models::payments::HeaderPayload::default(),
diff --git a/crates/router/tests/payments.rs b/crates/router/tests/payments.rs
index 75917f667b..6997704f9e 100644
--- a/crates/router/tests/payments.rs
+++ b/crates/router/tests/payments.rs
@@ -494,6 +494,7 @@ async fn payments_create_core() {
services::AuthFlow::Merchant,
payments::CallConnectorAction::Trigger,
None,
+ None,
hyperswitch_domain_models::payments::HeaderPayload::default(),
))
.await
@@ -781,6 +782,7 @@ async fn payments_create_core_adyen_no_redirect() {
services::AuthFlow::Merchant,
payments::CallConnectorAction::Trigger,
None,
+ None,
hyperswitch_domain_models::payments::HeaderPayload::default(),
))
.await
diff --git a/crates/router/tests/payments2.rs b/crates/router/tests/payments2.rs
index 676082cb05..246baa138f 100644
--- a/crates/router/tests/payments2.rs
+++ b/crates/router/tests/payments2.rs
@@ -257,6 +257,7 @@ async fn payments_create_core() {
services::AuthFlow::Merchant,
payments::CallConnectorAction::Trigger,
None,
+ None,
hyperswitch_domain_models::payments::HeaderPayload::default(),
))
.await
@@ -551,6 +552,7 @@ async fn payments_create_core_adyen_no_redirect() {
services::AuthFlow::Merchant,
payments::CallConnectorAction::Trigger,
None,
+ None,
hyperswitch_domain_models::payments::HeaderPayload::default(),
))
.await