From f2b88350a6cbe2708976564c532bcb9e47f54d68 Mon Sep 17 00:00:00 2001 From: ItsMeShashank Date: Fri, 6 Jan 2023 14:02:39 +0530 Subject: [PATCH] feat(router): add payment failed webhook event (#305) --- crates/api_models/src/webhooks.rs | 2 ++ crates/common_utils/src/pii.rs | 2 +- crates/router/src/connector/stripe.rs | 1 + crates/router/src/core/payments/helpers.rs | 7 ++++--- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/crates/api_models/src/webhooks.rs b/crates/api_models/src/webhooks.rs index ddc4ffa13a..eb116eba31 100644 --- a/crates/api_models/src/webhooks.rs +++ b/crates/api_models/src/webhooks.rs @@ -7,6 +7,7 @@ use crate::{enums as api_enums, payments}; #[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)] #[serde(rename_all = "snake_case")] pub enum IncomingWebhookEvent { + PaymentIntentFailure, PaymentIntentSuccess, } @@ -19,6 +20,7 @@ pub enum WebhookFlow { impl From for WebhookFlow { fn from(evt: IncomingWebhookEvent) -> Self { match evt { + IncomingWebhookEvent::PaymentIntentFailure => Self::Payment, IncomingWebhookEvent::PaymentIntentSuccess => Self::Payment, } } diff --git a/crates/common_utils/src/pii.rs b/crates/common_utils/src/pii.rs index e0a0204c02..8ad1a7419b 100644 --- a/crates/common_utils/src/pii.rs +++ b/crates/common_utils/src/pii.rs @@ -17,7 +17,7 @@ where fn fmt(val: &T, f: &mut fmt::Formatter<'_>) -> fmt::Result { let val_str: &str = val.as_ref(); - if val_str.len() < 15 && val_str.len() > 19 { + if val_str.len() < 15 || val_str.len() > 19 { return WithType::fmt(val, f); } diff --git a/crates/router/src/connector/stripe.rs b/crates/router/src/connector/stripe.rs index 86847a4469..57e3643616 100644 --- a/crates/router/src/connector/stripe.rs +++ b/crates/router/src/connector/stripe.rs @@ -935,6 +935,7 @@ impl api::IncomingWebhook for Stripe { .change_context(errors::ConnectorError::WebhookEventTypeNotFound)?; Ok(match details.event_type.as_str() { + "payment_intent.payment_failed" => api::IncomingWebhookEvent::PaymentIntentFailure, "payment_intent.succeeded" => api::IncomingWebhookEvent::PaymentIntentSuccess, _ => Err(errors::ConnectorError::WebhookEventTypeNotFound).into_report()?, }) diff --git a/crates/router/src/core/payments/helpers.rs b/crates/router/src/core/payments/helpers.rs index 9adbaa6b46..eab26a8553 100644 --- a/crates/router/src/core/payments/helpers.rs +++ b/crates/router/src/core/payments/helpers.rs @@ -31,7 +31,7 @@ use crate::{ utils::{ self, crypto::{self, SignMessage}, - OptionExt, ValueExt, + OptionExt, }, }; @@ -658,8 +658,9 @@ pub async fn get_connector_default( .parse_value("CustomRoutingRulesVec") .change_context(errors::ConnectorError::RoutingRulesParsingError) .change_context(errors::ApiErrorResponse::InternalServerError)?; - let custom_routing_rules: api::CustomRoutingRules = vec_val[0] - .clone() + let custom_routing_rules: api::CustomRoutingRules = vec_val + .first() + .cloned() .parse_value("CustomRoutingRules") .change_context(errors::ConnectorError::RoutingRulesParsingError) .change_context(errors::ApiErrorResponse::InternalServerError)?;