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
fix(webhooks): prefer merchant txn id over connector id in UCS webhook bridge (#14514)
Amitsingh Tanware8c465e228f5
diff --git a/crates/hyperswitch_interfaces/src/helpers.rs b/crates/hyperswitch_interfaces/src/helpers.rsindex cd07ccad18..9a09a773b4 100644--- a/crates/hyperswitch_interfaces/src/helpers.rs+++ b/crates/hyperswitch_interfaces/src/helpers.rs@@ -106,6 +106,7 @@ pub async fn serialize_comparison_results_and_send<S, F, RouterDReq, RouterDResp}/// Webhook-flow analogue of `serialize_router_data_and_send_to_comparison_service`.+#[allow(clippy::too_many_arguments)]pub async fn serialize_webhook_outcome_and_send_to_comparison_service<P, S>(state: &dyn api_client::ApiClientWrapper,primary: &P,@@ -114,6 +115,7 @@ pub async fn serialize_webhook_outcome_and_send_to_comparison_service<P, S>(connector_name: String,request_id: Option<String>,merchant_id: Option<&id_type::MerchantId>,+ webhook_flow_name: Option<String>,) whereP: serde::Serialize + std::fmt::Debug,S: serde::Serialize + std::fmt::Debug,@@ -137,7 +139,7 @@ pub async fn serialize_webhook_outcome_and_send_to_comparison_service<P, S>(comparison_data,comparison_service_config,connector_name,- Some("webhook".to_string()),+ webhook_flow_name.or_else(|| Some("webhook".to_string())),request_id,merchant_id,None,diff --git a/crates/router/src/core/webhooks/gateway.rs b/crates/router/src/core/webhooks/gateway.rsindex 1797e2fcfa..be61e6b54e 100644--- a/crates/router/src/core/webhooks/gateway.rs+++ b/crates/router/src/core/webhooks/gateway.rs@@ -178,6 +178,7 @@ pub async fn get_webhook_event_details_from_ucs(connector_name: &str,merchant_connector_account: Option<&domain::MerchantConnectorAccount>,request: &IncomingWebhookRequestDetails<'_>,+ execution_mode: ExecutionMode,) -> (Option<payments_grpc::EventReference>,Option<IncomingWebhookEvent>,@@ -194,7 +195,7 @@ pub async fn get_webhook_event_details_from_ucs(connector_name: connector_name.to_string(),merchant_connector_account: merchant_connector_account.cloned(),execution_path: ExecutionPath::Direct,- execution_mode: ExecutionMode::NotApplicable,+ execution_mode,ucs_reference: None,ucs_event_type: None,};@@ -214,7 +215,7 @@ pub async fn get_webhook_event_details_from_ucs(Err(_) => return (None, None),};- let parse_headers = build_ucs_headers_builder(&ctx, None, ExecutionMode::NotApplicable);+ let parse_headers = build_ucs_headers_builder(&ctx, None, execution_mode);let parse_response = match unified_connector_service::ucs_webhook_logging_wrapper(state,@@ -706,6 +707,11 @@ async fn report_shadow_diff(api_client::ApiClientWrapper, helpers::GetComparisonServiceConfig,};if let Some(config) = state.get_comparison_service_config() {+ let webhook_flow_name = primary.event_type.map(|event_type| {+ let flow: api_models::webhooks::WebhookFlow = event_type.into();+ format!("webhook_{}", flow.to_string().to_lowercase())+ });+hyperswitch_interfaces::helpers::serialize_webhook_outcome_and_send_to_comparison_service(state,primary,@@ -714,6 +720,7 @@ async fn report_shadow_diff(connector_name.to_string(),state.get_request_id_str(),merchant_id.as_ref(),+ webhook_flow_name,).await;}@@ -917,26 +924,28 @@ fn event_reference_to_object_ref(let out = match resource {Resource::Payment(payment) => {- if let Some(ctx_id) = payment.connector_transaction_id.as_ref() {+ if let Some(merchant_txn_id) = payment.merchant_transaction_id.as_ref() {Some(ObjectReferenceId::PaymentId(- api_payments::PaymentIdType::ConnectorTransactionId(ctx_id.clone()),+ api_payments::PaymentIdType::PaymentAttemptId(merchant_txn_id.clone()),))} else {- payment.merchant_transaction_id.as_ref().map(|mref| {- ObjectReferenceId::PaymentId(api_payments::PaymentIdType::PaymentAttemptId(- mref.clone(),- ))+ payment.connector_transaction_id.as_ref().map(|ctx_id| {+ ObjectReferenceId::PaymentId(+ api_payments::PaymentIdType::ConnectorTransactionId(ctx_id.clone()),+ )})}}Resource::Refund(refund) => {- if let Some(cr_id) = refund.connector_refund_id.as_ref() {+ if let Some(merchant_refund_id) = refund.merchant_refund_id.as_ref() {Some(ObjectReferenceId::RefundId(- api_webhooks::RefundIdType::ConnectorRefundId(cr_id.clone()),+ api_webhooks::RefundIdType::RefundId(merchant_refund_id.clone()),))} else {- refund.merchant_refund_id.as_ref().map(|mid| {- ObjectReferenceId::RefundId(api_webhooks::RefundIdType::RefundId(mid.clone()))+ refund.connector_refund_id.as_ref().map(|cr_id| {+ ObjectReferenceId::RefundId(api_webhooks::RefundIdType::ConnectorRefundId(+ cr_id.clone(),+ ))})}}@@ -956,14 +965,14 @@ fn event_reference_to_object_ref(}),#[cfg(feature = "payouts")]Resource::Payout(payout) => {- if let Some(cid) = payout.connector_payout_id.as_ref() {+ if let Some(merchant_payout_id) = payout.merchant_payout_id.as_ref() {Some(ObjectReferenceId::PayoutId(- api_webhooks::PayoutIdType::ConnectorPayoutId(cid.clone()),+ api_webhooks::PayoutIdType::PayoutAttemptId(merchant_payout_id.clone()),))} else {- payout.merchant_payout_id.as_ref().map(|mid| {- ObjectReferenceId::PayoutId(api_webhooks::PayoutIdType::PayoutAttemptId(- mid.clone(),+ payout.connector_payout_id.as_ref().map(|cid| {+ ObjectReferenceId::PayoutId(api_webhooks::PayoutIdType::ConnectorPayoutId(+ cid.clone(),))})}diff --git a/crates/router/src/core/webhooks/incoming.rs b/crates/router/src/core/webhooks/incoming.rsindex 75703d27e3..8c980a6f6c 100644--- a/crates/router/src/core/webhooks/incoming.rs+++ b/crates/router/src/core/webhooks/incoming.rs@@ -271,8 +271,19 @@ async fn incoming_webhooks_core<W: types::OutgoingWebhookType>();let (ucs_event_reference, ucs_event_type) = match candidate_path {- common_enums::ExecutionPath::UnifiedConnectorService- | common_enums::ExecutionPath::ShadowUnifiedConnectorService => {+ common_enums::ExecutionPath::UnifiedConnectorService => {+ super::gateway::get_webhook_event_details_from_ucs(+ &state,+ &platform,+ connector.clone(),+ &connector_name,+ mca_ref,+ &request_details,+ common_enums::ExecutionMode::Primary,+ )+ .await+ }+ common_enums::ExecutionPath::ShadowUnifiedConnectorService => {super::gateway::get_webhook_event_details_from_ucs(&state,&platform,@@ -280,6 +291,7 @@ async fn incoming_webhooks_core<W: types::OutgoingWebhookType>(&connector_name,mca_ref,&request_details,+ common_enums::ExecutionMode::Shadow,).await}