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
chore(webhooks): ignore payment not found in webhooks (#1886)
Nishant Joshi29f068b20581
diff --git a/crates/router/src/configs/settings.rs b/crates/router/src/configs/settings.rsindex 29134fbfda..bda540af20 100644--- a/crates/router/src/configs/settings.rs+++ b/crates/router/src/configs/settings.rs@@ -581,6 +581,14 @@ pub struct DrainerSettings {#[serde(default)]pub struct WebhooksSettings {pub outgoing_enabled: bool,+ pub ignore_error: WebhookIgnoreErrorSettings,+}++#[derive(Debug, Clone, Deserialize, Default)]+#[serde(default)]+pub struct WebhookIgnoreErrorSettings {+ pub event_type: Option<bool>,+ pub payment_not_found: Option<bool>,}#[derive(Debug, Deserialize, Clone)]diff --git a/crates/router/src/core/errors/utils.rs b/crates/router/src/core/errors/utils.rsindex f5ff829b48..ea11498768 100644--- a/crates/router/src/core/errors/utils.rs+++ b/crates/router/src/core/errors/utils.rs@@ -63,6 +63,7 @@ pub trait ConnectorErrorExt<T> {#[track_caller]fn allow_webhook_event_type_not_found(self,+ enabled: bool,) -> error_stack::Result<Option<T>, errors::ConnectorError>;}@@ -240,11 +241,14 @@ impl<T> ConnectorErrorExt<T> for error_stack::Result<T, errors::ConnectorError>})}- fn allow_webhook_event_type_not_found(self) -> CustomResult<Option<T>, errors::ConnectorError> {+ fn allow_webhook_event_type_not_found(+ self,+ enabled: bool,+ ) -> CustomResult<Option<T>, errors::ConnectorError> {match self {Ok(event_type) => Ok(Some(event_type)),Err(error) => match error.current_context() {- errors::ConnectorError::WebhookEventTypeNotFound => Ok(None),+ errors::ConnectorError::WebhookEventTypeNotFound if enabled => Ok(None),_ => Err(error),},}diff --git a/crates/router/src/core/metrics.rs b/crates/router/src/core/metrics.rsindex e26683b338..eb8a5be8d4 100644--- a/crates/router/src/core/metrics.rs+++ b/crates/router/src/core/metrics.rs@@ -39,6 +39,7 @@ counter_metric!(WEBHOOK_SOURCE_VERIFIED_COUNT, GLOBAL_METER);counter_metric!(WEBHOOK_OUTGOING_COUNT, GLOBAL_METER);counter_metric!(WEBHOOK_OUTGOING_RECEIVED_COUNT, GLOBAL_METER);counter_metric!(WEBHOOK_OUTGOING_NOT_RECEIVED_COUNT, GLOBAL_METER);+counter_metric!(WEBHOOK_PAYMENT_NOT_FOUND, GLOBAL_METER);counter_metric!(WEBHOOK_EVENT_TYPE_IDENTIFICATION_FAILURE_COUNT,GLOBAL_METERdiff --git a/crates/router/src/core/webhooks.rs b/crates/router/src/core/webhooks.rsindex b25c7179a2..4c554b2bbb 100644--- a/crates/router/src/core/webhooks.rs+++ b/crates/router/src/core/webhooks.rs@@ -14,7 +14,7 @@ use crate::{payments, refunds,},logger,- routes::AppState,+ routes::{metrics::request::add_attributes, AppState},services,types::{self as router_types, api, domain,@@ -42,7 +42,7 @@ pub async fn payments_incoming_webhook_flow<W: types::OutgoingWebhookType>(};let payments_response = match webhook_details.object_reference_id {api_models::webhooks::ObjectReferenceId::PaymentId(id) => {- payments::payments_core::<api::PSync, api::PaymentsResponse, _, _, _>(+ let response = payments::payments_core::<api::PSync, api::PaymentsResponse, _, _, _>(&state,merchant_account.clone(),key_store,@@ -60,7 +60,30 @@ pub async fn payments_incoming_webhook_flow<W: types::OutgoingWebhookType>(services::AuthFlow::Merchant,consume_or_trigger_flow,)- .await?+ .await;++ match response {+ Ok(value) => value,+ Err(err)+ if matches!(+ err.current_context(),+ &errors::ApiErrorResponse::PaymentNotFound+ ) && state+ .conf+ .webhooks+ .ignore_error+ .payment_not_found+ .unwrap_or(true) =>+ {+ metrics::WEBHOOK_PAYMENT_NOT_FOUND.add(+ &metrics::CONTEXT,+ 1,+ &[add_attributes("merchant_id", merchant_account.merchant_id)],+ );+ return Ok(());+ }+ error @ Err(_) => error?,+ }}_ => Err(errors::ApiErrorResponse::WebhookProcessingFailure).into_report()@@ -685,7 +708,9 @@ pub async fn webhooks_core<W: types::OutgoingWebhookType>(let event_type = match connector.get_webhook_event_type(&request_details)- .allow_webhook_event_type_not_found()+ .allow_webhook_event_type_not_found(+ state.conf.webhooks.ignore_error.event_type.unwrap_or(true),+ ).switch().attach_printable("Could not find event type in incoming webhook body")?{