From eff280f2fbaba392a61d6f55fb251de106273a41 Mon Sep 17 00:00:00 2001 From: Narayan Bhat <48803246+Narayanbhat166@users.noreply.github.com> Date: Tue, 12 Sep 2023 20:12:42 +0530 Subject: [PATCH] fix(webhooks): fix database queries in webhook (#2139) --- crates/router/src/types/api/webhooks.rs | 2 +- crates/router/src/utils.rs | 25 ++++++++++++------- .../src/payments/payment_attempt.rs | 2 +- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/crates/router/src/types/api/webhooks.rs b/crates/router/src/types/api/webhooks.rs index d849f1f82e..a765f8adc7 100644 --- a/crates/router/src/types/api/webhooks.rs +++ b/crates/router/src/types/api/webhooks.rs @@ -103,7 +103,7 @@ pub trait IncomingWebhook: ConnectorCommon + Sync { let merchant_connector_account_result = db .find_merchant_connector_account_by_profile_id_connector_name( &profile_id, - &merchant_account.merchant_id, + connector_name, key_store, ) .await; diff --git a/crates/router/src/utils.rs b/crates/router/src/utils.rs index 4ac092125a..b9e4504a99 100644 --- a/crates/router/src/utils.rs +++ b/crates/router/src/utils.rs @@ -27,7 +27,10 @@ use uuid::Uuid; pub use self::ext_traits::{OptionExt, ValidateCall}; use crate::{ consts, - core::errors::{self, CustomResult, RouterResult, StorageErrorExt}, + core::{ + errors::{self, CustomResult, RouterResult, StorageErrorExt}, + utils, + }, db::StorageInterface, logger, routes::metrics, @@ -305,14 +308,18 @@ pub async fn get_profile_id_using_object_reference_id( .await? } }; - let profile_id = payment_intent - .profile_id - .ok_or(errors::ApiErrorResponse::MissingRequiredField { - field_name: "business_profile", - }) - .into_report() - .change_context(errors::ApiErrorResponse::InternalServerError) - .attach_printable("profile_id is not set in payment_intent")?; + + let profile_id = utils::get_profile_id_from_business_details( + payment_intent.business_country, + payment_intent.business_label.as_ref(), + merchant_account, + payment_intent.profile_id.as_ref(), + db, + ) + .await + .change_context(errors::ApiErrorResponse::InternalServerError) + .attach_printable("profile_id is not set in payment_intent")?; + Ok(profile_id) } } diff --git a/crates/storage_impl/src/payments/payment_attempt.rs b/crates/storage_impl/src/payments/payment_attempt.rs index 332dc3f8dc..7b64cd012f 100644 --- a/crates/storage_impl/src/payments/payment_attempt.rs +++ b/crates/storage_impl/src/payments/payment_attempt.rs @@ -226,8 +226,8 @@ impl PaymentAttemptInterface for RouterStore { async fn find_payment_attempt_by_attempt_id_merchant_id( &self, - merchant_id: &str, attempt_id: &str, + merchant_id: &str, _storage_scheme: MerchantStorageScheme, ) -> CustomResult { let conn = pg_connection_read(self).await?;