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

fix(router): Prevent redundant api_event entries in case of webhooks (#12941)

Anurag Thakurb6a5a54d9604
diff --git a/crates/hyperswitch_connectors/src/connectors/adyen.rs b/crates/hyperswitch_connectors/src/connectors/adyen.rs
index c351ff3369..9128925450 100644
--- a/crates/hyperswitch_connectors/src/connectors/adyen.rs
+++ b/crates/hyperswitch_connectors/src/connectors/adyen.rs
@@ -16,7 +16,7 @@ use common_utils::{
};
use error_stack::{report, ResultExt};
use hyperswitch_domain_models::{
- api::ApplicationResponse,
+ api::WebhookResponse,
payment_method_data,
router_data::{AccessToken, ConnectorAuthType, ErrorResponse, RouterData},
router_flow_types::{
@@ -2177,8 +2177,8 @@ impl IncomingWebhook for Adyen {
_connector_authentication_type: Option<
common_utils::crypto::Encryptable<Secret<serde_json::Value>>,
>,
- ) -> CustomResult<ApplicationResponse<serde_json::Value>, errors::ConnectorError> {
- Ok(ApplicationResponse::TextPlain("[accepted]".to_string()))
+ ) -> CustomResult<WebhookResponse<serde_json::Value>, errors::ConnectorError> {
+ Ok(WebhookResponse::TextPlain("[accepted]".to_string()))
}
fn get_dispute_details(
diff --git a/crates/hyperswitch_connectors/src/connectors/adyenplatform.rs b/crates/hyperswitch_connectors/src/connectors/adyenplatform.rs
index 35aac2124a..8010694a2d 100644
--- a/crates/hyperswitch_connectors/src/connectors/adyenplatform.rs
+++ b/crates/hyperswitch_connectors/src/connectors/adyenplatform.rs
@@ -27,7 +27,7 @@ use hyperswitch_domain_models::router_flow_types::PoFulfill;
#[cfg(feature = "payouts")]
use hyperswitch_domain_models::types::{PayoutsData, PayoutsResponseData, PayoutsRouterData};
use hyperswitch_domain_models::{
- api::ApplicationResponse,
+ api::WebhookResponse,
router_data::{AccessToken, ConnectorAuthType},
router_flow_types::{
AccessTokenAuth, Authorize, Capture, Execute, PSync, PaymentMethodToken, RSync, Session,
@@ -412,9 +412,9 @@ impl IncomingWebhook for Adyenplatform {
_request: &IncomingWebhookRequestDetails<'_>,
error_kind: Option<IncomingWebhookFlowError>,
_connector_authentication_type: Option<crypto::Encryptable<Secret<serde_json::Value>>>,
- ) -> CustomResult<ApplicationResponse<serde_json::Value>, ConnectorError> {
+ ) -> CustomResult<WebhookResponse<serde_json::Value>, ConnectorError> {
if error_kind.is_some() {
- Ok(ApplicationResponse::JsonWithHeaders((
+ Ok(WebhookResponse::JsonWithHeaders((
serde_json::Value::Null,
vec![(
"x-http-code".to_string(),
@@ -422,7 +422,7 @@ impl IncomingWebhook for Adyenplatform {
)],
)))
} else {
- Ok(ApplicationResponse::StatusOk)
+ Ok(WebhookResponse::StatusOk)
}
}
diff --git a/crates/hyperswitch_connectors/src/connectors/braintree.rs b/crates/hyperswitch_connectors/src/connectors/braintree.rs
index 08549fdbf3..3ab8893056 100644
--- a/crates/hyperswitch_connectors/src/connectors/braintree.rs
+++ b/crates/hyperswitch_connectors/src/connectors/braintree.rs
@@ -18,7 +18,7 @@ use common_utils::{
};
use error_stack::{report, Report, ResultExt};
use hyperswitch_domain_models::{
- api::ApplicationResponse,
+ api::WebhookResponse,
router_data::{AccessToken, ConnectorAuthType, ErrorResponse, RouterData},
router_flow_types::{
access_token_auth::AccessTokenAuth,
@@ -1119,8 +1119,8 @@ impl IncomingWebhook for Braintree {
_request: &IncomingWebhookRequestDetails<'_>,
_error_kind: Option<IncomingWebhookFlowError>,
_connector_authentication_type: Option<crypto::Encryptable<Secret<serde_json::Value>>>,
- ) -> CustomResult<ApplicationResponse<serde_json::Value>, errors::ConnectorError> {
- Ok(ApplicationResponse::TextPlain("[accepted]".to_string()))
+ ) -> CustomResult<WebhookResponse<serde_json::Value>, errors::ConnectorError> {
+ Ok(WebhookResponse::TextPlain("[accepted]".to_string()))
}
fn get_dispute_details(
diff --git a/crates/hyperswitch_connectors/src/connectors/cashtocode.rs b/crates/hyperswitch_connectors/src/connectors/cashtocode.rs
index 2065f72e0c..0a218ded19 100644
--- a/crates/hyperswitch_connectors/src/connectors/cashtocode.rs
+++ b/crates/hyperswitch_connectors/src/connectors/cashtocode.rs
@@ -12,7 +12,7 @@ use common_utils::{
};
use error_stack::ResultExt;
use hyperswitch_domain_models::{
- api::ApplicationResponse,
+ api::WebhookResponse,
router_data::{AccessToken, ErrorResponse, RouterData},
router_flow_types::{
access_token_auth::AccessTokenAuth,
@@ -460,7 +460,7 @@ impl webhooks::IncomingWebhook for Cashtocode {
_connector_authentication_type: Option<
common_utils::crypto::Encryptable<Secret<serde_json::Value>>,
>,
- ) -> CustomResult<ApplicationResponse<serde_json::Value>, errors::ConnectorError> {
+ ) -> CustomResult<WebhookResponse<serde_json::Value>, errors::ConnectorError> {
let status = "EXECUTED".to_string();
let obj: transformers::CashtocodePaymentsSyncResponse = request
.body
@@ -468,7 +468,7 @@ impl webhooks::IncomingWebhook for Cashtocode {
.change_context(errors::ConnectorError::WebhookReferenceIdNotFound)?;
let response: serde_json::Value =
serde_json::json!({ "status": status, "transactionId" : obj.transaction_id});
- Ok(ApplicationResponse::Json(response))
+ Ok(WebhookResponse::Json(response))
}
}
diff --git a/crates/hyperswitch_connectors/src/connectors/trustly.rs b/crates/hyperswitch_connectors/src/connectors/trustly.rs
index 5ddc181e05..77ff8dcd0a 100644
--- a/crates/hyperswitch_connectors/src/connectors/trustly.rs
+++ b/crates/hyperswitch_connectors/src/connectors/trustly.rs
@@ -846,7 +846,7 @@ impl webhooks::IncomingWebhook for Trustly {
common_utils::crypto::Encryptable<hyperswitch_masking::Secret<serde_json::Value>>,
>,
) -> CustomResult<
- hyperswitch_domain_models::api::ApplicationResponse<serde_json::Value>,
+ hyperswitch_domain_models::api::WebhookResponse<serde_json::Value>,
ConnectorError,
> {
let request_body: trustly::TrustlyWebhookBody = request
@@ -884,7 +884,7 @@ impl webhooks::IncomingWebhook for Trustly {
let response_value = serde_json::to_value(response)
.change_context(ConnectorError::ResponseDeserializationFailed)?;
- Ok(hyperswitch_domain_models::api::ApplicationResponse::Json(
+ Ok(hyperswitch_domain_models::api::WebhookResponse::Json(
response_value,
))
}
diff --git a/crates/hyperswitch_connectors/src/connectors/worldline.rs b/crates/hyperswitch_connectors/src/connectors/worldline.rs
index 2d81553242..79ef8b9161 100644
--- a/crates/hyperswitch_connectors/src/connectors/worldline.rs
+++ b/crates/hyperswitch_connectors/src/connectors/worldline.rs
@@ -817,18 +817,18 @@ impl webhooks::IncomingWebhook for Worldline {
crypto::Encryptable<hyperswitch_masking::Secret<serde_json::Value>>,
>,
) -> CustomResult<
- hyperswitch_domain_models::api::ApplicationResponse<serde_json::Value>,
+ hyperswitch_domain_models::api::WebhookResponse<serde_json::Value>,
errors::ConnectorError,
> {
let verification_header = request.headers.get("x-gcs-webhooks-endpoint-verification");
let response = match verification_header {
- None => hyperswitch_domain_models::api::ApplicationResponse::StatusOk,
+ None => hyperswitch_domain_models::api::WebhookResponse::StatusOk,
Some(header_value) => {
let verification_signature_value = header_value
.to_str()
.change_context(errors::ConnectorError::WebhookResponseEncodingFailed)?
.to_string();
- hyperswitch_domain_models::api::ApplicationResponse::TextPlain(
+ hyperswitch_domain_models::api::WebhookResponse::TextPlain(
verification_signature_value,
)
}
diff --git a/crates/hyperswitch_connectors/src/connectors/zen.rs b/crates/hyperswitch_connectors/src/connectors/zen.rs
index 8faaa6a871..0f2f6c11ef 100644
--- a/crates/hyperswitch_connectors/src/connectors/zen.rs
+++ b/crates/hyperswitch_connectors/src/connectors/zen.rs
@@ -11,7 +11,7 @@ use common_utils::{
};
use error_stack::ResultExt;
use hyperswitch_domain_models::{
- api::ApplicationResponse,
+ api::WebhookResponse,
payment_method_data::PaymentMethodData,
router_data::{AccessToken, ConnectorAuthType, ErrorResponse, RouterData},
router_flow_types::{
@@ -690,8 +690,8 @@ impl IncomingWebhook for Zen {
_request: &IncomingWebhookRequestDetails<'_>,
_error_kind: Option<IncomingWebhookFlowError>,
_connector_authentication_type: Option<crypto::Encryptable<Secret<serde_json::Value>>>,
- ) -> CustomResult<ApplicationResponse<serde_json::Value>, errors::ConnectorError> {
- Ok(ApplicationResponse::Json(serde_json::json!({
+ ) -> CustomResult<WebhookResponse<serde_json::Value>, errors::ConnectorError> {
+ Ok(WebhookResponse::Json(serde_json::json!({
"status": "ok"
})))
}
diff --git a/crates/hyperswitch_connectors/src/connectors/zsl.rs b/crates/hyperswitch_connectors/src/connectors/zsl.rs
index 17962c3cbf..61a3ffe86e 100644
--- a/crates/hyperswitch_connectors/src/connectors/zsl.rs
+++ b/crates/hyperswitch_connectors/src/connectors/zsl.rs
@@ -11,7 +11,7 @@ use common_utils::{
};
use error_stack::ResultExt;
use hyperswitch_domain_models::{
- api::ApplicationResponse,
+ api::WebhookResponse,
router_data::{AccessToken, ConnectorAuthType, ErrorResponse, RouterData},
router_flow_types::{
access_token_auth::AccessTokenAuth,
@@ -446,8 +446,8 @@ impl IncomingWebhook for Zsl {
_connector_authentication_type: Option<
common_utils::crypto::Encryptable<Secret<serde_json::Value>>,
>,
- ) -> CustomResult<ApplicationResponse<serde_json::Value>, errors::ConnectorError> {
- Ok(ApplicationResponse::TextPlain("CALLBACK-OK".to_string()))
+ ) -> CustomResult<WebhookResponse<serde_json::Value>, errors::ConnectorError> {
+ Ok(WebhookResponse::TextPlain("CALLBACK-OK".to_string()))
}
}
diff --git a/crates/hyperswitch_domain_models/src/api.rs b/crates/hyperswitch_domain_models/src/api.rs
index 6ed5265fb0..13301c7b5c 100644
--- a/crates/hyperswitch_domain_models/src/api.rs
+++ b/crates/hyperswitch_domain_models/src/api.rs
@@ -3,6 +3,7 @@ use std::{collections::HashSet, fmt::Display};
use common_utils::{
events::{ApiEventMetric, ApiEventsType},
impl_api_event_type,
+ pii::SecretSerdeValue,
};
use super::payment_method_data::PaymentMethodData;
@@ -18,6 +19,42 @@ pub enum ApplicationResponse<R> {
FileData((Vec<u8>, mime::Mime)),
JsonWithHeaders((R, Vec<(String, hyperswitch_masking::Maskable<String>)>)),
GenericLinkForm(Box<GenericLinks>),
+ /// `response` contains the HTTP response sent back to the connector; `metadata` is consumed
+ /// by `server_wrap_util` for the ApiEvent log.
+ IncomingWebhookEvent {
+ response: Box<WebhookResponse<R>>,
+ metadata: IncomingWebhookEventMetadata,
+ },
+}
+
+/// A narrowed subset of [`ApplicationResponse`] representing the valid HTTP responses
+/// that can be sent back to a connector as a webhook acknowledgement.
+#[derive(Debug, PartialEq)]
+pub enum WebhookResponse<R> {
+ Json(R),
+ StatusOk,
+ TextPlain(String),
+ FileData((Vec<u8>, mime::Mime)),
+ JsonWithHeaders((R, Vec<(String, hyperswitch_masking::Maskable<String>)>)),
+}
+
+impl<R> From<WebhookResponse<R>> for ApplicationResponse<R> {
+ fn from(resp: WebhookResponse<R>) -> Self {
+ match resp {
+ WebhookResponse::Json(r) => Self::Json(r),
+ WebhookResponse::StatusOk => Self::StatusOk,
+ WebhookResponse::TextPlain(s) => Self::TextPlain(s),
+ WebhookResponse::FileData((v, m)) => Self::FileData((v, m)),
+ WebhookResponse::JsonWithHeaders((r, h)) => Self::JsonWithHeaders((r, h)),
+ }
+ }
+}
+
+#[derive(Debug, PartialEq)]
+pub struct IncomingWebhookEventMetadata {
+ pub event_type: ApiEventsType,
+ pub serialized_request: SecretSerdeValue,
+ pub webhook_tracker_data: Option<serde_json::Value>,
}
impl<R> ApplicationResponse<R> {
@@ -28,6 +65,7 @@ impl<R> ApplicationResponse<R> {
) -> common_utils::errors::CustomResult<R, common_utils::errors::ValidationError> {
match self {
Self::Json(body) | Self::JsonWithHeaders((body, _)) => Ok(body),
+ Self::IncomingWebhookEvent { response, .. } => Self::from(*response).get_json_body(),
Self::TextPlain(_)
| Self::JsonForRedirection(_)
| Self::Form(_)
@@ -47,6 +85,7 @@ impl<T: ApiEventMetric> ApiEventMetric for ApplicationResponse<T> {
match self {
Self::Json(r) => r.get_api_event_type(),
Self::JsonWithHeaders((r, _)) => r.get_api_event_type(),
+ Self::IncomingWebhookEvent { metadata, .. } => Some(metadata.event_type.clone()),
_ => None,
}
}
diff --git a/crates/hyperswitch_interfaces/src/connector_integration_interface.rs b/crates/hyperswitch_interfaces/src/connector_integration_interface.rs
index 88847be601..3efa926f90 100644
--- a/crates/hyperswitch_interfaces/src/connector_integration_interface.rs
+++ b/crates/hyperswitch_interfaces/src/connector_integration_interface.rs
@@ -5,7 +5,7 @@ use api_models::{
use common_enums::PaymentAction;
use common_utils::{crypto, errors::CustomResult, request::Request};
use hyperswitch_domain_models::{
- api::ApplicationResponse,
+ api::WebhookResponse,
connector_endpoints::Connectors,
errors::api_error_response::ApiErrorResponse,
router_data::{ConnectorAuthType, ErrorResponse, RouterData},
@@ -359,7 +359,7 @@ impl IncomingWebhook for ConnectorEnum {
connector_authentication_type: Option<
crypto::Encryptable<hyperswitch_masking::Secret<serde_json::Value>>,
>,
- ) -> CustomResult<ApplicationResponse<serde_json::Value>, errors::ConnectorError> {
+ ) -> CustomResult<WebhookResponse<serde_json::Value>, errors::ConnectorError> {
match self {
Self::Old(connector) => connector.get_webhook_api_response(
request,
diff --git a/crates/hyperswitch_interfaces/src/webhooks.rs b/crates/hyperswitch_interfaces/src/webhooks.rs
index 6fa8007a26..fa1a4add42 100644
--- a/crates/hyperswitch_interfaces/src/webhooks.rs
+++ b/crates/hyperswitch_interfaces/src/webhooks.rs
@@ -3,7 +3,7 @@
use common_utils::{crypto, errors::CustomResult, ext_traits::ValueExt};
use error_stack::ResultExt;
use hyperswitch_domain_models::{
- api::ApplicationResponse, errors::api_error_response::ApiErrorResponse,
+ api::WebhookResponse, errors::api_error_response::ApiErrorResponse,
};
use hyperswitch_masking::{ExposeInterface, Secret};
@@ -338,8 +338,8 @@ pub trait IncomingWebhook: ConnectorCommon + Sync {
_request: &IncomingWebhookRequestDetails<'_>,
_error_kind: Option<IncomingWebhookFlowError>,
_connector_authentication_type: Option<crypto::Encryptable<Secret<serde_json::Value>>>,
- ) -> CustomResult<ApplicationResponse<serde_json::Value>, errors::ConnectorError> {
- Ok(ApplicationResponse::StatusOk)
+ ) -> CustomResult<WebhookResponse<serde_json::Value>, errors::ConnectorError> {
+ Ok(WebhookResponse::StatusOk)
}
/// fn get_dispute_details
diff --git a/crates/router/src/compatibility/wrap.rs b/crates/router/src/compatibility/wrap.rs
index cfa7686711..1a024e24c3 100644
--- a/crates/router/src/compatibility/wrap.rs
+++ b/crates/router/src/compatibility/wrap.rs
@@ -55,6 +55,12 @@ where
)
.await
.map(|response| {
+ let response = match response {
+ api::ApplicationResponse::IncomingWebhookEvent {
+ response: inner, ..
+ } => api::ApplicationResponse::from(*inner),
+ other => other,
+ };
logger::info!(api_response =? response);
response
});
@@ -175,6 +181,9 @@ where
}
}
}
+ // This match arm should never be reached as we map the inner field of IncomingWebhookEvent
+ // to ApplicationResponse above
+ Ok(api::ApplicationResponse::IncomingWebhookEvent { .. }) => api::http_response_ok(),
Err(error) => api::log_and_return_error_response(error),
};
diff --git a/crates/router/src/core/webhooks/gateway.rs b/crates/router/src/core/webhooks/gateway.rs
index b6ec46eb50..ef2d0d68df 100644
--- a/crates/router/src/core/webhooks/gateway.rs
+++ b/crates/router/src/core/webhooks/gateway.rs
@@ -6,6 +6,7 @@ use common_enums::{ExecutionMode, ExecutionPath};
use common_utils::{errors::ReportSwitchExt, ext_traits::Encode};
use error_stack::ResultExt;
use external_services::grpc_client::LineageIds;
+use hyperswitch_domain_models::api::WebhookResponse;
use hyperswitch_interfaces::webhooks::{
IncomingWebhookRequestDetails, WebhookContext, WebhookResourceData,
};
@@ -33,7 +34,7 @@ use crate::{
},
},
routes::SessionState,
- services::{self, connector_integration_interface::ConnectorEnum},
+ services::connector_integration_interface::ConnectorEnum,
types::{api::IncomingWebhook, domain, transformers::ForeignTryFrom},
utils as helper_utils,
};
@@ -67,7 +68,7 @@ pub enum WebhookOutcome {
Skipped {
reference: Option<ObjectReferenceId>,
event_type: IncomingWebhookEvent,
- ack_response: services::ApplicationResponse<serde_json::Value>,
+ ack_response: WebhookResponse<serde_json::Value>,
},
Processed {
reference: ObjectReferenceId,
@@ -85,7 +86,7 @@ pub enum WebhookOutcome {
webhook_resource_data: Box<Option<WebhookResourceData>>,
masked_log_payload: common_utils::pii::SecretSerdeValue,
merchant_connector_account: Box<domain::MerchantConnectorAccount>,
- ack_response: services::ApplicationResponse<serde_json::Value>,
+ ack_response: WebhookResponse<serde_json::Value>,
},
}
@@ -432,7 +433,7 @@ impl IncomingWebhookGateway for UcsIncomingWebhookGateway {
FilterDecision::Skip => WebhookOutcome::Skipped {
reference,
event_type,
- ack_response: services::ApplicationResponse::StatusOk,
+ ack_response: WebhookResponse::StatusOk,
},
FilterDecision::Proceed => {
let reference = reference.ok_or_else(|| {
@@ -512,8 +513,8 @@ impl IncomingWebhookGateway for UcsIncomingWebhookGateway {
let ack_response = handle_response
.event_ack_response
- .map(ucs_ack_to_application_response)
- .unwrap_or(services::ApplicationResponse::StatusOk);
+ .map(ucs_ack_to_webhook_response)
+ .unwrap_or(WebhookResponse::StatusOk);
WebhookOutcome::Processed {
reference,
@@ -995,9 +996,9 @@ async fn build_event_context(
})
}
-fn ucs_ack_to_application_response(
+fn ucs_ack_to_webhook_response(
ack: payments_grpc::EventAckResponse,
-) -> services::ApplicationResponse<serde_json::Value> {
+) -> WebhookResponse<serde_json::Value> {
let payments_grpc::EventAckResponse {
status_code: _,
headers,
@@ -1005,7 +1006,7 @@ fn ucs_ack_to_application_response(
} = ack;
if body.is_empty() {
- return services::ApplicationResponse::StatusOk;
+ return WebhookResponse::StatusOk;
}
let masked_headers: Vec<(String, hyperswitch_masking::Maskable<String>)> = headers
@@ -1015,14 +1016,14 @@ fn ucs_ack_to_application_response(
if let Ok(value) = serde_json::from_slice::<serde_json::Value>(&body) {
return if masked_headers.is_empty() {
- services::ApplicationResponse::Json(value)
+ WebhookResponse::Json(value)
} else {
- services::ApplicationResponse::JsonWithHeaders((value, masked_headers))
+ WebhookResponse::JsonWithHeaders((value, masked_headers))
};
}
match String::from_utf8(body.clone()) {
- Ok(text) => services::ApplicationResponse::TextPlain(text),
- Err(_) => services::ApplicationResponse::FileData((body, mime::APPLICATION_OCTET_STREAM)),
+ Ok(text) => WebhookResponse::TextPlain(text),
+ Err(_) => WebhookResponse::FileData((body, mime::APPLICATION_OCTET_STREAM)),
}
}
diff --git a/crates/router/src/core/webhooks/incoming.rs b/crates/router/src/core/webhooks/incoming.rs
index eec4bc1053..323b55c9cf 100644
--- a/crates/router/src/core/webhooks/incoming.rs
+++ b/crates/router/src/core/webhooks/incoming.rs
@@ -1,6 +1,5 @@
-use std::{str::FromStr, time::Instant};
+use std::str::FromStr;
-use actix_web::FromRequest;
#[cfg(feature = "payouts")]
use api_models::payouts as payout_models;
use api_models::{
@@ -16,10 +15,11 @@ use common_utils::{
};
use diesel_models::{refund as diesel_refund, ConnectorMandateReferenceId};
use error_stack::{report, ResultExt};
-use hyperswitch_connectors::connectors::unified_authentication_service::transformers::WebhookResponse;
+use hyperswitch_connectors::connectors::unified_authentication_service::transformers::WebhookResponse as UasWebhookResponse;
#[cfg(feature = "payouts")]
use hyperswitch_domain_models::payouts::payouts::PayoutsUpdate;
use hyperswitch_domain_models::{
+ api::{IncomingWebhookEventMetadata, WebhookResponse},
mandates::CommonMandateReference,
payments::{payment_attempt::PaymentAttempt, HeaderPayload},
router_request_types::unified_authentication_service::UasAuthenticationResponseData,
@@ -27,8 +27,8 @@ use hyperswitch_domain_models::{
use hyperswitch_interfaces::webhooks::{
IncomingWebhookFlowError, IncomingWebhookRequestDetails, WebhookContext, WebhookResourceData,
};
-use hyperswitch_masking::{ExposeInterface, PeekInterface};
-use router_env::{instrument, tracing, RequestId};
+use hyperswitch_masking::{ExposeInterface, PeekInterface, Secret};
+use router_env::{instrument, tracing};
use super::{types, MERCHANT_ID};
use crate::{
@@ -47,16 +47,9 @@ use crate::{
unified_connector_service, utils as core_utils,
webhooks::{network_tokenization_incoming, utils},
},
- events::api_logs::ApiEvent,
logger,
- routes::{
- app::{ReqState, SessionStateInfo},
- lock_utils, SessionState,
- },
- services::{
- self, authentication as auth, connector_integration_interface::ConnectorEnum,
- ConnectorValidation,
- },
+ routes::{app::ReqState, lock_utils, SessionState},
+ services::{self, connector_integration_interface::ConnectorEnum, ConnectorValidation},
types::{
api::{
self, mandates::MandateResponseExt, ConnectorCommon, ConnectorData, GetToken,
@@ -73,7 +66,6 @@ use crate::{core::payouts, types::storage::PayoutAttemptUpdate};
#[allow(clippy::too_many_arguments)]
pub async fn incoming_webhooks_wrapper<W: types::OutgoingWebhookType>(
- flow: &impl router_env::types::FlowMetric,
state: SessionState,
req_state: ReqState,
req: &actix_web::HttpRequest,
@@ -82,8 +74,7 @@ pub async fn incoming_webhooks_wrapper<W: types::OutgoingWebhookType>(
body: actix_web::web::Bytes,
is_relay_webhook: bool,
) -> RouterResponse<serde_json::Value> {
- let start_instant = Instant::now();
- let (application_response, webhooks_response_tracker, serialized_req) =
+ let (webhook_response, webhooks_response_tracker, serialized_req) =
Box::pin(incoming_webhooks_core::<W>(
state.clone(),
req_state,
@@ -97,57 +88,32 @@ pub async fn incoming_webhooks_wrapper<W: types::OutgoingWebhookType>(
logger::info!(incoming_webhook_payload = ?serialized_req.peek());
- let request_duration = Instant::now()
- .saturating_duration_since(start_instant)
- .as_millis();
-
- let request_id = RequestId::extract(req)
- .await
- .attach_printable("Unable to extract request id from request")
- .change_context(errors::ApiErrorResponse::InternalServerError)?;
- let auth_type = auth::AuthenticationType::WebhookAuth {
- merchant_id: platform.get_processor().get_account().get_id().clone(),
- };
- let status_code = 200;
- let api_event = ApiEventsType::Webhooks {
- connector: connector_name_or_mca_id.to_string(),
- payment_id: webhooks_response_tracker.get_payment_id(),
- refund_id: webhooks_response_tracker.get_refund_id(),
+ let metadata = IncomingWebhookEventMetadata {
+ event_type: ApiEventsType::Webhooks {
+ connector: connector_name_or_mca_id.to_string(),
+ payment_id: webhooks_response_tracker.get_payment_id(),
+ refund_id: webhooks_response_tracker.get_refund_id(),
+ },
+ serialized_request: serialized_req,
+ webhook_tracker_data: serde_json::to_value(&webhooks_response_tracker)
+ .inspect_err(
+ |err| logger::error!(error = ?err, "Could not convert webhook effect to string"),
+ )
+ .ok(),
};
- let response_value = serde_json::to_value(&webhooks_response_tracker)
- .change_context(errors::ApiErrorResponse::InternalServerError)
- .attach_printable("Could not convert webhook effect to string")?;
- let infra = state.infra_components.clone();
- let api_event = ApiEvent::new(
- state.tenant.tenant_id.clone(),
- Some(platform.get_processor().get_account().get_id().clone()),
- flow,
- &request_id,
- request_duration,
- status_code,
- serialized_req.peek().clone(),
- Some(response_value),
- None,
- auth_type,
- None,
- api_event,
- req,
- req.method(),
- infra,
- );
- state.event_handler().log_event(&api_event);
- Ok(application_response)
+
+ Ok(services::ApplicationResponse::IncomingWebhookEvent {
+ response: Box::new(webhook_response),
+ metadata,
+ })
}
#[cfg(feature = "v1")]
pub async fn network_token_incoming_webhooks_wrapper<W: types::OutgoingWebhookType>(
- flow: &impl router_env::types::FlowMetric,
state: SessionState,
req: &actix_web::HttpRequest,
body: actix_web::web::Bytes,
) -> RouterResponse<serde_json::Value> {
- let start_instant = Instant::now();
-
let request_details: IncomingWebhookRequestDetails<'_> = IncomingWebhookRequestDetails {
method: req.method().clone(),
uri: req.uri().clone(),
@@ -156,49 +122,29 @@ pub async fn network_token_incoming_webhooks_wrapper<W: types::OutgoingWebhookTy
body: &body,
};
- let (application_response, webhooks_response_tracker, serialized_req, merchant_id) = Box::pin(
+ let (webhook_response, webhooks_response_tracker, serialized_req, _merchant_id) = Box::pin(
network_token_incoming_webhooks_core::<W>(&state, request_details),
)
.await?;
logger::info!(incoming_webhook_payload = ?serialized_req);
- let request_duration = Instant::now()
- .saturating_duration_since(start_instant)
- .as_millis();
-
- let request_id = RequestId::extract(req)
- .await
- .change_context(errors::ApiErrorResponse::InternalServerError)
- .attach_printable("Unable to extract request id from request")?;
- let auth_type = auth::AuthenticationType::NoAuth;
- let status_code = 200;
- let api_event = ApiEventsType::NetworkTokenWebhook {
- payment_method_id: webhooks_response_tracker.get_payment_method_id(),
+ let metadata = IncomingWebhookEventMetadata {
+ event_type: ApiEventsType::NetworkTokenWebhook {
+ payment_method_id: webhooks_response_tracker.get_payment_method_id(),
+ },
+ serialized_request: Secret::new(serialized_req),
+ webhook_tracker_data: serde_json::to_value(&webhooks_response_tracker)
+ .inspect_err(
+ |err| logger::error!(error = ?err, "Could not convert webhook effect to string"),
+ )
+ .ok(),
};
- let response_value = serde_json::to_value(&webhooks_response_tracker)
- .change_context(errors::ApiErrorResponse::InternalServerError)
- .attach_printable("Could not convert webhook effect to string")?;
- let infra = state.infra_components.clone();
- let api_event = ApiEvent::new(
- state.tenant.tenant_id.clone(),
- Some(merchant_id),
- flow,
- &request_id,
- request_duration,
- status_code,
- serialized_req,
- Some(response_value),
- None,
- auth_type,
- None,
- api_event,
- req,
- req.method(),
- infra,
- );
- state.event_handler().log_event(&api_event);
- Ok(application_response)
+
+ Ok(services::ApplicationResponse::IncomingWebhookEvent {
+ response: Box::new(webhook_response),
+ metadata,
+ })
}
fn confirm_path_for_flow(
@@ -227,7 +173,7 @@ async fn incoming_webhooks_core<W: types::OutgoingWebhookType>(
body: actix_web::web::Bytes,
is_relay_webhook: bool,
) -> errors::RouterResult<(
- services::ApplicationResponse<serde_json::Value>,
+ WebhookResponse<serde_json::Value>,
WebhookResponseTracker,
common_utils::pii::SecretSerdeValue,
)> {
@@ -376,9 +322,9 @@ async fn incoming_webhooks_core<W: types::OutgoingWebhookType>(
Ok(outcome) if outcome.event_type() == webhooks::IncomingWebhookEvent::SetupWebhook
) {
return Ok((
- services::ApplicationResponse::StatusOk,
+ WebhookResponse::StatusOk,
WebhookResponseTracker::NoEffect,
- hyperswitch_masking::Secret::new(serde_json::Value::default()),
+ Secret::new(serde_json::Value::default()),
));
}
@@ -399,7 +345,7 @@ async fn incoming_webhooks_core<W: types::OutgoingWebhookType>(
(
ack_response,
WebhookResponseTracker::NoEffect,
- hyperswitch_masking::Secret::new(serde_json::Value::Null),
+ Secret::new(serde_json::Value::Null),
)
}
Ok(super::gateway::WebhookOutcome::Processed {
@@ -783,7 +729,7 @@ fn handle_incoming_webhook_error(
request_details: &IncomingWebhookRequestDetails<'_>,
merchant_id: &common_utils::id_type::MerchantId,
) -> errors::RouterResult<(
- services::ApplicationResponse<serde_json::Value>,
+ WebhookResponse<serde_json::Value>,
WebhookResponseTracker,
common_utils::pii::SecretSerdeValue,
)> {
@@ -816,7 +762,7 @@ fn handle_incoming_webhook_error(
Ok((
response,
WebhookResponseTracker::NoEffect,
- hyperswitch_masking::Secret::new(serde_json::Value::Null),
+ Secret::new(serde_json::Value::Null),
))
} else {
Err(error)
@@ -829,7 +775,7 @@ async fn network_token_incoming_webhooks_core<W: types::OutgoingWebhookType>(
state: &SessionState,
request_details: IncomingWebhookRequestDetails<'_>,
) -> errors::RouterResult<(
- services::ApplicationResponse<serde_json::Value>,
+ WebhookResponse<serde_json::Value>,
WebhookResponseTracker,
serde_json::Value,
common_utils::id_type::MerchantId,
@@ -891,7 +837,7 @@ async fn network_token_incoming_webhooks_core<W: types::OutgoingWebhookType>(
.await?;
Ok((
- services::ApplicationResponse::StatusOk,
+ WebhookResponse::StatusOk,
webhook_resp_tracker,
serialized_request,
merchant_id.clone(),
@@ -1853,7 +1799,7 @@ pub async fn get_or_update_dispute_object(
connector_created_at: dispute_details.created_at,
connector_updated_at: dispute_details.updated_at,
profile_id: Some(business_profile.get_id().to_owned()),
- evidence: hyperswitch_masking::Secret::new(serde_json::json!({})),
+ evidence: Secret::new(serde_json::json!({})),
merchant_connector_id: payment_attempt.merchant_connector_id.clone(),
dispute_amount: StringMinorUnitForConnector::convert_back(
&StringMinorUnitForConnector,
@@ -2911,7 +2857,7 @@ async fn update_connector_mandate_details(
.transpose()?;
let pm_update = diesel_models::PaymentMethodUpdate::ConnectorNetworkTransactionIdAndMandateDetailsUpdate {
- connector_mandate_details: connector_mandate_details_value.map(hyperswitch_masking::Secret::new),
+ connector_mandate_details: connector_mandate_details_value.map(Secret::new),
network_transaction_id: webhook_connector_network_transaction_id
.map(|webhook_network_transaction_id| webhook_network_transaction_id.get_id().clone()),
last_modified_by: platform.get_initiator().and_then(|initiator| initiator.to_created_by()).map(|last_modified_by| last_modified_by.to_string()),
@@ -3031,7 +2977,7 @@ pub async fn process_uas_incoming_webhook<'a>(
authentication_id,
results_request,
results_response,
- } => Ok(WebhookResponse {
+ } => Ok(UasWebhookResponse {
trans_status,
authentication_value,
eci,
@@ -3125,15 +3071,14 @@ pub async fn process_uas_incoming_webhook<'a>(
.get_webhook_resource_object(&uas_webhook_request)
.switch()
.attach_printable("Failed to extract UAS webhook resource object")?;
- let masked_log_payload = hyperswitch_masking::Secret::new(
- resource_object.masked_serialize().unwrap_or_else(|error| {
+ let masked_log_payload =
+ Secret::new(resource_object.masked_serialize().unwrap_or_else(|error| {
router_env::logger::warn!(
?error,
"Failed to mask-serialize UAS webhook resource object for logging"
);
serde_json::Value::Null
- }),
- );
+ }));
let ack_response = uas_connector
.get_webhook_api_response(
diff --git a/crates/router/src/core/webhooks/incoming_v2.rs b/crates/router/src/core/webhooks/incoming_v2.rs
index ac138364df..7d9cbbdc9a 100644
--- a/crates/router/src/core/webhooks/incoming_v2.rs
+++ b/crates/router/src/core/webhooks/incoming_v2.rs
@@ -1,18 +1,19 @@
-use std::{marker::PhantomData, str::FromStr, time::Instant};
+use std::{marker::PhantomData, str::FromStr};
-use actix_web::FromRequest;
use api_models::webhooks::{self, WebhookResponseTracker};
use common_utils::{
errors::ReportSwitchExt, events::ApiEventsType, types::keymanager::KeyManagerState,
};
use error_stack::ResultExt;
use hyperswitch_domain_models::{
+ api::{IncomingWebhookEventMetadata, WebhookResponse},
payments::{HeaderPayload, PaymentStatusData},
router_request_types::VerifyWebhookSourceRequestData,
router_response_types::{VerifyWebhookSourceResponseData, VerifyWebhookStatus},
};
use hyperswitch_interfaces::webhooks::{IncomingWebhookRequestDetails, WebhookResourceData};
-use router_env::{instrument, tracing, RequestId};
+use hyperswitch_masking::Secret;
+use router_env::{instrument, tracing};
use super::{types, utils, MERCHANT_ID};
#[cfg(feature = "revenue_recovery")]
@@ -32,16 +33,9 @@ use crate::{
},
},
db::StorageInterface,
- events::api_logs::ApiEvent,
logger,
- routes::{
- app::{ReqState, SessionStateInfo},
- lock_utils, SessionState,
- },
- services::{
- self, authentication as auth, connector_integration_interface::ConnectorEnum,
- ConnectorValidation,
- },
+ routes::{app::ReqState, lock_utils, SessionState},
+ services::{self, connector_integration_interface::ConnectorEnum, ConnectorValidation},
types::{
api::{self, ConnectorData, GetToken, IncomingWebhook},
domain,
@@ -52,7 +46,6 @@ use crate::{
#[allow(clippy::too_many_arguments)]
pub async fn incoming_webhooks_wrapper<W: types::OutgoingWebhookType>(
- flow: &impl router_env::types::FlowMetric,
state: SessionState,
req_state: ReqState,
req: &actix_web::HttpRequest,
@@ -66,8 +59,7 @@ pub async fn incoming_webhooks_wrapper<W: types::OutgoingWebhookType>(
.with_provider_merchant_id(platform.get_provider().get_provider_merchant_id())
.with_processor_merchant_id(platform.get_processor().get_processor_merchant_id());
- let start_instant = Instant::now();
- let (application_response, webhooks_response_tracker, serialized_req) =
+ let (webhook_response, webhooks_response_tracker, serialized_req) =
Box::pin(incoming_webhooks_core::<W>(
state.clone(),
req_state,
@@ -82,48 +74,24 @@ pub async fn incoming_webhooks_wrapper<W: types::OutgoingWebhookType>(
logger::info!(incoming_webhook_payload = ?serialized_req);
- let request_duration = Instant::now()
- .saturating_duration_since(start_instant)
- .as_millis();
-
- let request_id = RequestId::extract(req)
- .await
- .attach_printable("Unable to extract request id from request")
- .change_context(errors::ApiErrorResponse::InternalServerError)?;
- let auth_type = auth::AuthenticationType::WebhookAuth {
- merchant_id: platform.get_processor().get_account().get_id().clone(),
- };
- let status_code = 200;
- let api_event = ApiEventsType::Webhooks {
- connector: connector_id.clone(),
- payment_id: webhooks_response_tracker.get_payment_id(),
- refund_id: webhooks_response_tracker.get_refund_id(),
+ let metadata = IncomingWebhookEventMetadata {
+ event_type: ApiEventsType::Webhooks {
+ connector: connector_id.clone(),
+ payment_id: webhooks_response_tracker.get_payment_id(),
+ refund_id: webhooks_response_tracker.get_refund_id(),
+ },
+ serialized_request: Secret::new(serialized_req),
+ webhook_tracker_data: serde_json::to_value(&webhooks_response_tracker)
+ .inspect_err(
+ |err| logger::error!(error = ?err, "Could not convert webhook effect to string"),
+ )
+ .ok(),
};
- let response_value = serde_json::to_value(&webhooks_response_tracker)
- .change_context(errors::ApiErrorResponse::InternalServerError)
- .attach_printable("Could not convert webhook effect to string")?;
- let infra = state.infra_components.clone();
-
- let api_event = ApiEvent::new(
- state.tenant.tenant_id.clone(),
- Some(platform.get_processor().get_account().get_id().clone()),
- flow,
- &request_id,
- request_duration,
- status_code,
- serialized_req,
- Some(response_value),
- None,
- auth_type,
- None,
- api_event,
- req,
- req.method(),
- infra,
- );
- state.event_handler().log_event(&api_event);
- Ok(application_response)
+ Ok(services::ApplicationResponse::IncomingWebhookEvent {
+ response: Box::new(webhook_response),
+ metadata,
+ })
}
#[instrument(skip_all)]
@@ -138,7 +106,7 @@ async fn incoming_webhooks_core<W: types::OutgoingWebhookType>(
body: actix_web::web::Bytes,
_is_relay_webhook: bool,
) -> errors::RouterResult<(
- services::ApplicationResponse<serde_json::Value>,
+ WebhookResponse<serde_json::Value>,
WebhookResponseTracker,
serde_json::Value,
)> {
@@ -239,7 +207,7 @@ async fn incoming_webhooks_core<W: types::OutgoingWebhookType>(
// if it is a setup webhook event, return ok status
if event_type == webhooks::IncomingWebhookEvent::SetupWebhook {
return Ok((
- services::ApplicationResponse::StatusOk,
+ WebhookResponse::StatusOk,
WebhookResponseTracker::NoEffect,
serde_json::Value::default(),
));
diff --git a/crates/router/src/events/api_logs.rs b/crates/router/src/events/api_logs.rs
index 0906ce992f..618b635934 100644
--- a/crates/router/src/events/api_logs.rs
+++ b/crates/router/src/events/api_logs.rs
@@ -171,3 +171,37 @@ impl ApiEventMetric for PollId {
})
}
}
+
+#[cfg(feature = "v1")]
+#[derive(Debug, Clone, serde::Serialize)]
+pub struct WebhookRequestPayload {
+ pub connector: String,
+}
+
+#[cfg(feature = "v1")]
+impl ApiEventMetric for WebhookRequestPayload {
+ fn get_api_event_type(&self) -> Option<ApiEventsType> {
+ Some(ApiEventsType::Webhooks {
+ connector: self.connector.clone(),
+ payment_id: None,
+ refund_id: None,
+ })
+ }
+}
+
+#[cfg(feature = "v2")]
+#[derive(Debug, Clone, serde::Serialize)]
+pub struct WebhookRequestPayload {
+ pub connector: common_utils::id_type::MerchantConnectorAccountId,
+}
+
+#[cfg(feature = "v2")]
+impl ApiEventMetric for WebhookRequestPayload {
+ fn get_api_event_type(&self) -> Option<ApiEventsType> {
+ Some(ApiEventsType::Webhooks {
+ connector: self.connector.clone(),
+ payment_id: None,
+ refund_id: None,
+ })
+ }
+}
diff --git a/crates/router/src/routes/metrics/request.rs b/crates/router/src/routes/metrics/request.rs
index 4e329005d4..b3404812da 100644
--- a/crates/router/src/routes/metrics/request.rs
+++ b/crates/router/src/routes/metrics/request.rs
@@ -9,7 +9,8 @@ pub fn track_response_status_code<Q>(response: &ApplicationResponse<Q>) -> i64 {
| ApplicationResponse::GenericLinkForm(_)
| ApplicationResponse::PaymentLinkForm(_)
| ApplicationResponse::FileData(_)
- | ApplicationResponse::JsonWithHeaders(_) => 200,
+ | ApplicationResponse::JsonWithHeaders(_)
+ | ApplicationResponse::IncomingWebhookEvent { .. } => 200,
ApplicationResponse::JsonForRedirection(_) => 302,
}
}
diff --git a/crates/router/src/routes/recovery_webhooks.rs b/crates/router/src/routes/recovery_webhooks.rs
index 303083b3a8..071c5aa527 100644
--- a/crates/router/src/routes/recovery_webhooks.rs
+++ b/crates/router/src/routes/recovery_webhooks.rs
@@ -26,13 +26,12 @@ pub async fn recovery_receive_incoming_webhook<W: types::OutgoingWebhookType>(
let (merchant_id, profile_id, connector_id) = path.into_inner();
Box::pin(api::server_wrap(
- flow.clone(),
+ flow,
state,
&req,
(),
|state, auth, _, req_state| {
webhooks::incoming_webhooks_wrapper::<W>(
- &flow,
state.to_owned(),
req_state,
&req,
diff --git a/crates/router/src/routes/webhooks.rs b/crates/router/src/routes/webhooks.rs
index 8e60338e75..4195f9d995 100644
--- a/crates/router/src/routes/webhooks.rs
+++ b/crates/router/src/routes/webhooks.rs
@@ -7,6 +7,7 @@ use crate::{
api_locking,
webhooks::{self, types},
},
+ events::api_logs::WebhookRequestPayload,
services::{api, authentication as auth},
};
@@ -22,13 +23,14 @@ pub async fn receive_incoming_webhook<W: types::OutgoingWebhookType>(
let (merchant_id, connector_id_or_name) = path.into_inner();
Box::pin(api::server_wrap(
- flow.clone(),
+ flow,
state,
&req,
- (),
+ WebhookRequestPayload {
+ connector: connector_id_or_name.clone(),
+ },
|state, auth, _, req_state| {
webhooks::incoming_webhooks_wrapper::<W>(
- &flow,
state.to_owned(),
req_state,
&req,
@@ -60,13 +62,14 @@ pub async fn receive_incoming_relay_webhook<W: types::OutgoingWebhookType>(
let is_relay_webhook = true;
Box::pin(api::server_wrap(
- flow.clone(),
+ flow,
state,
&req,
- (),
+ WebhookRequestPayload {
+ connector: connector_id.get_string_repr().to_string(),
+ },
|state, auth, _, req_state| {
webhooks::incoming_webhooks_wrapper::<W>(
- &flow,
state.to_owned(),
req_state,
&req,
@@ -99,13 +102,14 @@ pub async fn receive_incoming_relay_webhook<W: types::OutgoingWebhookType>(
let is_relay_webhook = true;
Box::pin(api::server_wrap(
- flow.clone(),
+ flow,
state,
&req,
- (),
+ WebhookRequestPayload {
+ connector: connector_id.clone(),
+ },
|state, auth, _, req_state| {
webhooks::incoming_webhooks_wrapper::<W>(
- &flow,
state.to_owned(),
req_state,
&req,
@@ -141,13 +145,14 @@ pub async fn receive_incoming_webhook<W: types::OutgoingWebhookType>(
let (merchant_id, profile_id, connector_id) = path.into_inner();
Box::pin(api::server_wrap(
- flow.clone(),
+ flow,
state,
&req,
- (),
+ WebhookRequestPayload {
+ connector: connector_id.clone(),
+ },
|state, auth, _, req_state| {
webhooks::incoming_webhooks_wrapper::<W>(
- &flow,
state.to_owned(),
req_state,
&req,
@@ -178,13 +183,12 @@ pub async fn receive_network_token_requestor_incoming_webhook<W: types::Outgoing
let flow = Flow::IncomingNetworkTokenWebhookReceive;
Box::pin(api::server_wrap(
- flow.clone(),
+ flow,
state,
&req,
(),
|state, _: (), _, _| {
webhooks::network_token_incoming_webhooks_wrapper::<W>(
- &flow,
state.to_owned(),
&req,
body.clone(),
diff --git a/crates/router/src/services/api.rs b/crates/router/src/services/api.rs
index 178d84fa02..5366b5fe48 100644
--- a/crates/router/src/services/api.rs
+++ b/crates/router/src/services/api.rs
@@ -28,7 +28,7 @@ use hyperswitch_domain_models::router_data_v2::flow_common_types as common_types
pub use hyperswitch_domain_models::{
api::{
ApplicationResponse, GenericExpiredLinkData, GenericLinkFormData, GenericLinkStatusData,
- GenericLinks, PaymentLinkAction, RedirectionFormData,
+ GenericLinks, PaymentLinkAction, RedirectionFormData, WebhookResponse,
},
payment_method_data::PaymentMethodData,
router_response_types::RedirectForm,
@@ -190,7 +190,7 @@ where
let mut app_state = state.get_ref().clone();
let start_instant = Instant::now();
- let serialized_request = hyperswitch_masking::masked_serialize(&payload)
+ let mut serialized_request = hyperswitch_masking::masked_serialize(&payload)
.attach_printable("Failed to serialize json request")
.change_context(errors::ApiErrorResponse::InternalServerError.switch())?;
@@ -316,6 +316,24 @@ where
.conf
.proxy_status_mapping
.extract_connector_http_status_code(headers);
+ } else if let ApplicationResponse::IncomingWebhookEvent { response, metadata } = res {
+ serialized_request = metadata.serialized_request.peek().clone();
+
+ if let Some(tracker_data) = &metadata.webhook_tracker_data {
+ serialized_response = Some(tracker_data.clone());
+ }
+
+ if let WebhookResponse::JsonWithHeaders((_, headers)) = response.as_ref() {
+ if let Some((_, value)) = headers.iter().find(|(key, _)| key == X_HS_LATENCY) {
+ if let Ok(external_latency) = value.clone().into_inner().parse::<u128>() {
+ overhead_latency.replace(external_latency);
+ }
+ }
+ extracted_status_code = state
+ .conf
+ .proxy_status_mapping
+ .extract_connector_http_status_code(headers);
+ }
}
event_type = res.get_api_event_type().or(event_type);
@@ -432,6 +450,12 @@ where
)
.await
.map(|response| {
+ let response = match response {
+ ApplicationResponse::IncomingWebhookEvent {
+ response: inner, ..
+ } => ApplicationResponse::from(*inner),
+ other => other,
+ };
logger::info!(api_response =? response);
response
});
@@ -563,6 +587,7 @@ where
),
}
}
+ Ok(ApplicationResponse::IncomingWebhookEvent { .. }) => http_response_ok(),
Err(error) => log_and_return_error_response(error),
};
diff --git a/crates/router/src/workflows/outgoing_webhook_retry.rs b/crates/router/src/workflows/outgoing_webhook_retry.rs
index 07f9e9513a..a5cee17a6f 100644
--- a/crates/router/src/workflows/outgoing_webhook_retry.rs
+++ b/crates/router/src/workflows/outgoing_webhook_retry.rs
@@ -508,7 +508,8 @@ async fn get_outgoing_webhook_content_and_event_type(
| ApplicationResponse::Form(_)
| ApplicationResponse::GenericLinkForm(_)
| ApplicationResponse::PaymentLinkForm(_)
- | ApplicationResponse::FileData(_) => {
+ | ApplicationResponse::FileData(_)
+ | ApplicationResponse::IncomingWebhookEvent { .. } => {
Err(errors::ProcessTrackerError::ResourceFetchingFailed {
resource_name: tracking_data.primary_object_id.clone(),
})
@@ -568,7 +569,8 @@ async fn get_outgoing_webhook_content_and_event_type(
| ApplicationResponse::Form(_)
| ApplicationResponse::GenericLinkForm(_)
| ApplicationResponse::PaymentLinkForm(_)
- | ApplicationResponse::FileData(_) => {
+ | ApplicationResponse::FileData(_)
+ | ApplicationResponse::IncomingWebhookEvent { .. } => {
Err(errors::ProcessTrackerError::ResourceFetchingFailed {
resource_name: tracking_data.primary_object_id.clone(),
})
@@ -599,7 +601,8 @@ async fn get_outgoing_webhook_content_and_event_type(
| ApplicationResponse::Form(_)
| ApplicationResponse::GenericLinkForm(_)
| ApplicationResponse::PaymentLinkForm(_)
- | ApplicationResponse::FileData(_) => {
+ | ApplicationResponse::FileData(_)
+ | ApplicationResponse::IncomingWebhookEvent { .. } => {
Err(errors::ProcessTrackerError::ResourceFetchingFailed {
resource_name: tracking_data.primary_object_id.clone(),
})