UCS webhook bridge resolves objects via connector transaction ID instead of merchant reference, diverging from the Direct webhook path
Context
When the Unified Connector Service (UCS) bridge is enabled, incoming connector webhooks are classified by UCS (EventServiceParseEvent) and the resulting EventReference is translated into a Hyperswitch ObjectReferenceId by event_reference_to_object_ref in crates/router/src/core/webhooks/gateway.rs.
Current behavior
event_reference_to_object_ref prefers the connector transaction ID (e.g. ConnectorTransactionId, ConnectorRefundId, ConnectorPayoutId) and falls back to the merchant-side reference only when the connector ID is absent.
Problem
Connectors echo back the HS-injected connector_request_reference_id as the merchant reference (e.g. Adyen merchantReference). This is exactly the key the Direct webhook path uses to resolve events — Adyen payment events resolve to PaymentAttemptId(merchant_reference) and refunds to RefundId(merchant_reference) in connectors/adyen.rs.
Because the UCS bridge prefers the connector ID, the same event resolves through a different lookup key than the Direct path:
- Lookup-key drift between the Direct and UCS webhook paths for the same connector event
- Failed/incorrect object resolution when the connector ID is absent or not indexed
- False diffs in UCS shadow-mode webhook comparisons
Expected behavior
The UCS bridge should prefer the merchant reference (PaymentAttemptId / RefundId / PayoutAttemptId) with the connector ID as fallback, aligning object resolution with the Direct webhook path. UCS already returns both IDs (it is a transparent parse layer), so Hyperswitch is free to choose the lookup key.
Connectors whose webhooks carry no merchant reference (Noon, Truelayer, Finix, Trustly, etc.) are unaffected since the connector-ID fallback still applies.
Proposed fix
Flip the preference in event_reference_to_object_ref (crates/router/src/core/webhooks/gateway.rs):
- Payment:
PaymentAttemptId(merchant_transaction_id), fallbackConnectorTransactionId - Refund:
RefundId(merchant_refund_id), fallbackConnectorRefundId - Payout:
PayoutAttemptId(merchant_payout_id), fallbackConnectorPayoutId
Pairs with juspay/hyperswitch-prism#2380 on the UCS side.
Source: juspay/hyperswitch