mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-11-01 19:42:27 +08:00
chore(webhooks): ignore payment not found in webhooks (#1886)
This commit is contained in:
@ -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)]
|
||||
|
||||
@ -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),
|
||||
},
|
||||
}
|
||||
|
||||
@ -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_METER
|
||||
|
||||
@ -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")?
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user