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
refactor(router): make error_type generic in domain_models inorder to avoid conversion of errors in storage_impl (#7537)
Jagan80218d0f2713
diff --git a/crates/analytics/src/opensearch.rs b/crates/analytics/src/opensearch.rsindex f12198d005..726e38e5e1 100644--- a/crates/analytics/src/opensearch.rs+++ b/crates/analytics/src/opensearch.rs@@ -10,7 +10,6 @@ use common_utils::{types::TimeRange,};use error_stack::ResultExt;-use hyperswitch_domain_models::errors::{StorageError, StorageResult};use opensearch::{auth::Credentials,cert::CertificateValidation,@@ -24,7 +23,7 @@ use opensearch::{MsearchParts, OpenSearch, SearchParts,};use serde_json::{json, Map, Value};-use storage_impl::errors::ApplicationError;+use storage_impl::errors::{ApplicationError, StorageError, StorageResult};use time::PrimitiveDateTime;use super::{health_check::HealthCheck, query::QueryResult, types::QueryExecutionError};diff --git a/crates/hyperswitch_domain_models/src/errors.rs b/crates/hyperswitch_domain_models/src/errors.rsindex a611e2ba82..aa6480f2ad 100644--- a/crates/hyperswitch_domain_models/src/errors.rs+++ b/crates/hyperswitch_domain_models/src/errors.rs@@ -1,51 +1 @@pub mod api_error_response;-use diesel_models::errors::DatabaseError;--pub type StorageResult<T> = error_stack::Result<T, StorageError>;--#[derive(Debug, thiserror::Error)]-pub enum StorageError {- #[error("Initialization Error")]- InitializationError,- // TODO: deprecate this error type to use a domain error instead- #[error("DatabaseError: {0:?}")]- DatabaseError(error_stack::Report<DatabaseError>),- #[error("ValueNotFound: {0}")]- ValueNotFound(String),- #[error("DuplicateValue: {entity} already exists {key:?}")]- DuplicateValue {- entity: &'static str,- key: Option<String>,- },- #[error("Timed out while trying to connect to the database")]- DatabaseConnectionError,- #[error("KV error")]- KVError,- #[error("Serialization failure")]- SerializationFailed,- #[error("MockDb error")]- MockDbError,- #[error("Kafka error")]- KafkaError,- #[error("Customer with this id is Redacted")]- CustomerRedacted,- #[error("Deserialization failure")]- DeserializationFailed,- #[error("Error while encrypting data")]- EncryptionError,- #[error("Error while decrypting data from database")]- DecryptionError,- // TODO: deprecate this error type to use a domain error instead- #[error("RedisError: {0:?}")]- RedisError(String),-}--impl StorageError {- pub fn is_db_not_found(&self) -> bool {- match self {- Self::DatabaseError(err) => matches!(err.current_context(), DatabaseError::NotFound),- Self::ValueNotFound(_) => true,- _ => false,- }- }-}diff --git a/crates/hyperswitch_domain_models/src/payment_methods.rs b/crates/hyperswitch_domain_models/src/payment_methods.rsindex 66fc6214ea..955d01c94d 100644--- a/crates/hyperswitch_domain_models/src/payment_methods.rs+++ b/crates/hyperswitch_domain_models/src/payment_methods.rs@@ -25,7 +25,6 @@ use crate::{type_encryption::OptionalEncryptableJsonType,};use crate::{- errors,mandates::{self, CommonMandateReference},merchant_key_store::MerchantKeyStore,type_encryption::{crypto_operation, AsyncLift, CryptoOperation},@@ -699,6 +698,7 @@ impl super::behaviour::Conversion for PaymentMethodSession {#[async_trait::async_trait]pub trait PaymentMethodInterface {+ type Error;#[cfg(all(any(feature = "v1", feature = "v2"),not(feature = "payment_methods_v2")@@ -709,7 +709,7 @@ pub trait PaymentMethodInterface {key_store: &MerchantKeyStore,payment_method_id: &str,storage_scheme: MerchantStorageScheme,- ) -> CustomResult<PaymentMethod, errors::StorageError>;+ ) -> CustomResult<PaymentMethod, Self::Error>;#[cfg(all(feature = "v2", feature = "customer_v2"))]async fn find_payment_method(@@ -718,7 +718,7 @@ pub trait PaymentMethodInterface {key_store: &MerchantKeyStore,payment_method_id: &id_type::GlobalPaymentMethodId,storage_scheme: MerchantStorageScheme,- ) -> CustomResult<PaymentMethod, errors::StorageError>;+ ) -> CustomResult<PaymentMethod, Self::Error>;#[cfg(all(any(feature = "v1", feature = "v2"),@@ -730,7 +730,7 @@ pub trait PaymentMethodInterface {key_store: &MerchantKeyStore,locker_id: &str,storage_scheme: MerchantStorageScheme,- ) -> CustomResult<PaymentMethod, errors::StorageError>;+ ) -> CustomResult<PaymentMethod, Self::Error>;#[cfg(all(any(feature = "v1", feature = "v2"),@@ -743,7 +743,7 @@ pub trait PaymentMethodInterface {customer_id: &id_type::CustomerId,merchant_id: &id_type::MerchantId,limit: Option<i64>,- ) -> CustomResult<Vec<PaymentMethod>, errors::StorageError>;+ ) -> CustomResult<Vec<PaymentMethod>, Self::Error>;// Need to fix this once we start moving to v2 for payment method#[cfg(all(feature = "v2", feature = "customer_v2"))]@@ -753,7 +753,7 @@ pub trait PaymentMethodInterface {key_store: &MerchantKeyStore,id: &id_type::GlobalCustomerId,limit: Option<i64>,- ) -> CustomResult<Vec<PaymentMethod>, errors::StorageError>;+ ) -> CustomResult<Vec<PaymentMethod>, Self::Error>;#[cfg(all(any(feature = "v1", feature = "v2"),@@ -769,7 +769,7 @@ pub trait PaymentMethodInterface {status: common_enums::PaymentMethodStatus,limit: Option<i64>,storage_scheme: MerchantStorageScheme,- ) -> CustomResult<Vec<PaymentMethod>, errors::StorageError>;+ ) -> CustomResult<Vec<PaymentMethod>, Self::Error>;#[cfg(all(feature = "v2", feature = "customer_v2"))]#[allow(clippy::too_many_arguments)]@@ -782,7 +782,7 @@ pub trait PaymentMethodInterface {status: common_enums::PaymentMethodStatus,limit: Option<i64>,storage_scheme: MerchantStorageScheme,- ) -> CustomResult<Vec<PaymentMethod>, errors::StorageError>;+ ) -> CustomResult<Vec<PaymentMethod>, Self::Error>;#[cfg(all(any(feature = "v1", feature = "v2"),@@ -793,13 +793,13 @@ pub trait PaymentMethodInterface {customer_id: &id_type::CustomerId,merchant_id: &id_type::MerchantId,status: common_enums::PaymentMethodStatus,- ) -> CustomResult<i64, errors::StorageError>;+ ) -> CustomResult<i64, Self::Error>;async fn get_payment_method_count_by_merchant_id_status(&self,merchant_id: &id_type::MerchantId,status: common_enums::PaymentMethodStatus,- ) -> CustomResult<i64, errors::StorageError>;+ ) -> CustomResult<i64, Self::Error>;async fn insert_payment_method(&self,@@ -807,7 +807,7 @@ pub trait PaymentMethodInterface {key_store: &MerchantKeyStore,payment_method: PaymentMethod,storage_scheme: MerchantStorageScheme,- ) -> CustomResult<PaymentMethod, errors::StorageError>;+ ) -> CustomResult<PaymentMethod, Self::Error>;async fn update_payment_method(&self,@@ -816,7 +816,7 @@ pub trait PaymentMethodInterface {payment_method: PaymentMethod,payment_method_update: PaymentMethodUpdate,storage_scheme: MerchantStorageScheme,- ) -> CustomResult<PaymentMethod, errors::StorageError>;+ ) -> CustomResult<PaymentMethod, Self::Error>;#[cfg(all(feature = "v2", feature = "payment_methods_v2"))]async fn delete_payment_method(@@ -824,7 +824,7 @@ pub trait PaymentMethodInterface {state: &keymanager::KeyManagerState,key_store: &MerchantKeyStore,payment_method: PaymentMethod,- ) -> CustomResult<PaymentMethod, errors::StorageError>;+ ) -> CustomResult<PaymentMethod, Self::Error>;#[cfg(all(feature = "v2", feature = "payment_methods_v2"))]async fn find_payment_method_by_fingerprint_id(@@ -832,7 +832,7 @@ pub trait PaymentMethodInterface {state: &keymanager::KeyManagerState,key_store: &MerchantKeyStore,fingerprint_id: &str,- ) -> CustomResult<PaymentMethod, errors::StorageError>;+ ) -> CustomResult<PaymentMethod, Self::Error>;#[cfg(all(any(feature = "v1", feature = "v2"),@@ -844,7 +844,7 @@ pub trait PaymentMethodInterface {key_store: &MerchantKeyStore,merchant_id: &id_type::MerchantId,payment_method_id: &str,- ) -> CustomResult<PaymentMethod, errors::StorageError>;+ ) -> CustomResult<PaymentMethod, Self::Error>;}#[cfg(feature = "v2")]diff --git a/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs b/crates/hyperswitch_domain_models/src/payments/payment_attempt.rsindex 25f93107c6..76c020080a 100644--- a/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs+++ b/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs@@ -57,12 +57,13 @@ use crate::{#[async_trait::async_trait]pub trait PaymentAttemptInterface {+ type Error;#[cfg(feature = "v1")]async fn insert_payment_attempt(&self,payment_attempt: PaymentAttemptNew,storage_scheme: storage_enums::MerchantStorageScheme,- ) -> error_stack::Result<PaymentAttempt, errors::StorageError>;+ ) -> error_stack::Result<PaymentAttempt, Self::Error>;#[cfg(feature = "v2")]async fn insert_payment_attempt(@@ -71,7 +72,7 @@ pub trait PaymentAttemptInterface {merchant_key_store: &MerchantKeyStore,payment_attempt: PaymentAttempt,storage_scheme: storage_enums::MerchantStorageScheme,- ) -> error_stack::Result<PaymentAttempt, errors::StorageError>;+ ) -> error_stack::Result<PaymentAttempt, Self::Error>;#[cfg(feature = "v1")]async fn update_payment_attempt_with_attempt_id(@@ -79,7 +80,7 @@ pub trait PaymentAttemptInterface {this: PaymentAttempt,payment_attempt: PaymentAttemptUpdate,storage_scheme: storage_enums::MerchantStorageScheme,- ) -> error_stack::Result<PaymentAttempt, errors::StorageError>;+ ) -> error_stack::Result<PaymentAttempt, Self::Error>;#[cfg(feature = "v2")]async fn update_payment_attempt(@@ -89,7 +90,7 @@ pub trait PaymentAttemptInterface {this: PaymentAttempt,payment_attempt: PaymentAttemptUpdate,storage_scheme: storage_enums::MerchantStorageScheme,- ) -> error_stack::Result<PaymentAttempt, errors::StorageError>;+ ) -> error_stack::Result<PaymentAttempt, Self::Error>;#[cfg(feature = "v1")]async fn find_payment_attempt_by_connector_transaction_id_payment_id_merchant_id(@@ -98,7 +99,7 @@ pub trait PaymentAttemptInterface {payment_id: &id_type::PaymentId,merchant_id: &id_type::MerchantId,storage_scheme: storage_enums::MerchantStorageScheme,- ) -> error_stack::Result<PaymentAttempt, errors::StorageError>;+ ) -> error_stack::Result<PaymentAttempt, Self::Error>;#[cfg(feature = "v1")]async fn find_payment_attempt_last_successful_attempt_by_payment_id_merchant_id(@@ -106,7 +107,7 @@ pub trait PaymentAttemptInterface {payment_id: &id_type::PaymentId,merchant_id: &id_type::MerchantId,storage_scheme: storage_enums::MerchantStorageScheme,- ) -> error_stack::Result<PaymentAttempt, errors::StorageError>;+ ) -> error_stack::Result<PaymentAttempt, Self::Error>;#[cfg(feature = "v1")]async fn find_payment_attempt_last_successful_or_partially_captured_attempt_by_payment_id_merchant_id(@@ -114,7 +115,7 @@ pub trait PaymentAttemptInterface {payment_id: &id_type::PaymentId,merchant_id: &id_type::MerchantId,storage_scheme: storage_enums::MerchantStorageScheme,- ) -> error_stack::Result<PaymentAttempt, errors::StorageError>;+ ) -> error_stack::Result<PaymentAttempt, Self::Error>;#[cfg(feature = "v1")]async fn find_payment_attempt_by_merchant_id_connector_txn_id(@@ -122,7 +123,7 @@ pub trait PaymentAttemptInterface {merchant_id: &id_type::MerchantId,connector_txn_id: &str,storage_scheme: storage_enums::MerchantStorageScheme,- ) -> error_stack::Result<PaymentAttempt, errors::StorageError>;+ ) -> error_stack::Result<PaymentAttempt, Self::Error>;#[cfg(feature = "v2")]async fn find_payment_attempt_by_profile_id_connector_transaction_id(@@ -132,7 +133,7 @@ pub trait PaymentAttemptInterface {profile_id: &id_type::ProfileId,connector_transaction_id: &str,_storage_scheme: storage_enums::MerchantStorageScheme,- ) -> CustomResult<PaymentAttempt, errors::StorageError>;+ ) -> CustomResult<PaymentAttempt, Self::Error>;#[cfg(feature = "v1")]async fn find_payment_attempt_by_payment_id_merchant_id_attempt_id(@@ -141,7 +142,7 @@ pub trait PaymentAttemptInterface {merchant_id: &id_type::MerchantId,attempt_id: &str,storage_scheme: storage_enums::MerchantStorageScheme,- ) -> error_stack::Result<PaymentAttempt, errors::StorageError>;+ ) -> error_stack::Result<PaymentAttempt, Self::Error>;#[cfg(feature = "v1")]async fn find_payment_attempt_by_attempt_id_merchant_id(@@ -149,7 +150,7 @@ pub trait PaymentAttemptInterface {attempt_id: &str,merchant_id: &id_type::MerchantId,storage_scheme: storage_enums::MerchantStorageScheme,- ) -> error_stack::Result<PaymentAttempt, errors::StorageError>;+ ) -> error_stack::Result<PaymentAttempt, Self::Error>;#[cfg(feature = "v2")]async fn find_payment_attempt_by_id(@@ -158,7 +159,7 @@ pub trait PaymentAttemptInterface {merchant_key_store: &MerchantKeyStore,attempt_id: &id_type::GlobalAttemptId,storage_scheme: storage_enums::MerchantStorageScheme,- ) -> error_stack::Result<PaymentAttempt, errors::StorageError>;+ ) -> error_stack::Result<PaymentAttempt, Self::Error>;#[cfg(feature = "v2")]async fn find_payment_attempts_by_payment_intent_id(@@ -167,7 +168,7 @@ pub trait PaymentAttemptInterface {payment_id: &id_type::GlobalPaymentId,merchant_key_store: &MerchantKeyStore,storage_scheme: common_enums::MerchantStorageScheme,- ) -> error_stack::Result<Vec<PaymentAttempt>, errors::StorageError>;+ ) -> error_stack::Result<Vec<PaymentAttempt>, Self::Error>;#[cfg(feature = "v1")]async fn find_payment_attempt_by_preprocessing_id_merchant_id(@@ -175,7 +176,7 @@ pub trait PaymentAttemptInterface {preprocessing_id: &str,merchant_id: &id_type::MerchantId,storage_scheme: storage_enums::MerchantStorageScheme,- ) -> error_stack::Result<PaymentAttempt, errors::StorageError>;+ ) -> error_stack::Result<PaymentAttempt, Self::Error>;#[cfg(feature = "v1")]async fn find_attempts_by_merchant_id_payment_id(@@ -183,7 +184,7 @@ pub trait PaymentAttemptInterface {merchant_id: &id_type::MerchantId,payment_id: &id_type::PaymentId,storage_scheme: storage_enums::MerchantStorageScheme,- ) -> error_stack::Result<Vec<PaymentAttempt>, errors::StorageError>;+ ) -> error_stack::Result<Vec<PaymentAttempt>, Self::Error>;#[cfg(all(feature = "v1", feature = "olap"))]async fn get_filters_for_payments(@@ -191,7 +192,7 @@ pub trait PaymentAttemptInterface {pi: &[PaymentIntent],merchant_id: &id_type::MerchantId,storage_scheme: storage_enums::MerchantStorageScheme,- ) -> error_stack::Result<PaymentListFilters, errors::StorageError>;+ ) -> error_stack::Result<PaymentListFilters, Self::Error>;#[cfg(all(feature = "v1", feature = "olap"))]#[allow(clippy::too_many_arguments)]@@ -207,7 +208,7 @@ pub trait PaymentAttemptInterface {card_network: Option<Vec<storage_enums::CardNetwork>>,card_discovery: Option<Vec<storage_enums::CardDiscovery>>,storage_scheme: storage_enums::MerchantStorageScheme,- ) -> error_stack::Result<i64, errors::StorageError>;+ ) -> error_stack::Result<i64, Self::Error>;#[cfg(all(feature = "v2", feature = "olap"))]#[allow(clippy::too_many_arguments)]@@ -222,7 +223,7 @@ pub trait PaymentAttemptInterface {merchant_connector_id: Option<id_type::MerchantConnectorAccountId>,card_network: Option<storage_enums::CardNetwork>,storage_scheme: storage_enums::MerchantStorageScheme,- ) -> error_stack::Result<i64, errors::StorageError>;+ ) -> error_stack::Result<i64, Self::Error>;}#[derive(Clone, Debug, Eq, PartialEq, serde::Serialize)]diff --git a/crates/hyperswitch_domain_models/src/payments/payment_intent.rs b/crates/hyperswitch_domain_models/src/payments/payment_intent.rsindex 380523bbeb..54f6799c47 100644--- a/crates/hyperswitch_domain_models/src/payments/payment_intent.rs+++ b/crates/hyperswitch_domain_models/src/payments/payment_intent.rs@@ -37,6 +37,7 @@ use crate::{#[async_trait::async_trait]pub trait PaymentIntentInterface {+ type Error;async fn update_payment_intent(&self,state: &KeyManagerState,@@ -44,7 +45,7 @@ pub trait PaymentIntentInterface {payment_intent: PaymentIntentUpdate,merchant_key_store: &MerchantKeyStore,storage_scheme: common_enums::MerchantStorageScheme,- ) -> error_stack::Result<PaymentIntent, errors::StorageError>;+ ) -> error_stack::Result<PaymentIntent, Self::Error>;async fn insert_payment_intent(&self,@@ -52,7 +53,7 @@ pub trait PaymentIntentInterface {new: PaymentIntent,merchant_key_store: &MerchantKeyStore,storage_scheme: common_enums::MerchantStorageScheme,- ) -> error_stack::Result<PaymentIntent, errors::StorageError>;+ ) -> error_stack::Result<PaymentIntent, Self::Error>;#[cfg(feature = "v1")]async fn find_payment_intent_by_payment_id_merchant_id(@@ -62,7 +63,7 @@ pub trait PaymentIntentInterface {merchant_id: &id_type::MerchantId,merchant_key_store: &MerchantKeyStore,storage_scheme: common_enums::MerchantStorageScheme,- ) -> error_stack::Result<PaymentIntent, errors::StorageError>;+ ) -> error_stack::Result<PaymentIntent, Self::Error>;#[cfg(feature = "v2")]async fn find_payment_intent_by_merchant_reference_id_profile_id(&self,@@ -71,7 +72,7 @@ pub trait PaymentIntentInterface {profile_id: &id_type::ProfileId,merchant_key_store: &MerchantKeyStore,storage_scheme: &common_enums::MerchantStorageScheme,- ) -> error_stack::Result<PaymentIntent, errors::StorageError>;+ ) -> error_stack::Result<PaymentIntent, Self::Error>;#[cfg(feature = "v2")]async fn find_payment_intent_by_id(@@ -80,7 +81,7 @@ pub trait PaymentIntentInterface {id: &id_type::GlobalPaymentId,merchant_key_store: &MerchantKeyStore,storage_scheme: common_enums::MerchantStorageScheme,- ) -> error_stack::Result<PaymentIntent, errors::StorageError>;+ ) -> error_stack::Result<PaymentIntent, Self::Error>;#[cfg(all(feature = "v1", feature = "olap"))]async fn filter_payment_intent_by_constraints(@@ -90,7 +91,7 @@ pub trait PaymentIntentInterface {filters: &PaymentIntentFetchConstraints,merchant_key_store: &MerchantKeyStore,storage_scheme: common_enums::MerchantStorageScheme,- ) -> error_stack::Result<Vec<PaymentIntent>, errors::StorageError>;+ ) -> error_stack::Result<Vec<PaymentIntent>, Self::Error>;#[cfg(all(feature = "v1", feature = "olap"))]async fn filter_payment_intents_by_time_range_constraints(@@ -100,7 +101,7 @@ pub trait PaymentIntentInterface {time_range: &common_utils::types::TimeRange,merchant_key_store: &MerchantKeyStore,storage_scheme: common_enums::MerchantStorageScheme,- ) -> error_stack::Result<Vec<PaymentIntent>, errors::StorageError>;+ ) -> error_stack::Result<Vec<PaymentIntent>, Self::Error>;#[cfg(feature = "olap")]async fn get_intent_status_with_count(@@ -108,7 +109,7 @@ pub trait PaymentIntentInterface {merchant_id: &id_type::MerchantId,profile_id_list: Option<Vec<id_type::ProfileId>>,constraints: &common_utils::types::TimeRange,- ) -> error_stack::Result<Vec<(common_enums::IntentStatus, i64)>, errors::StorageError>;+ ) -> error_stack::Result<Vec<(common_enums::IntentStatus, i64)>, Self::Error>;#[cfg(all(feature = "v1", feature = "olap"))]async fn get_filtered_payment_intents_attempt(@@ -118,7 +119,7 @@ pub trait PaymentIntentInterface {constraints: &PaymentIntentFetchConstraints,merchant_key_store: &MerchantKeyStore,storage_scheme: common_enums::MerchantStorageScheme,- ) -> error_stack::Result<Vec<(PaymentIntent, PaymentAttempt)>, errors::StorageError>;+ ) -> error_stack::Result<Vec<(PaymentIntent, PaymentAttempt)>, Self::Error>;#[cfg(all(feature = "v2", feature = "olap"))]async fn get_filtered_payment_intents_attempt(@@ -133,7 +134,7 @@ pub trait PaymentIntentInterface {PaymentIntent,Option<super::payment_attempt::PaymentAttempt>,)>,- errors::StorageError,+ Self::Error,>;#[cfg(all(feature = "v2", feature = "olap"))]@@ -142,7 +143,7 @@ pub trait PaymentIntentInterface {merchant_id: &id_type::MerchantId,constraints: &PaymentIntentFetchConstraints,storage_scheme: common_enums::MerchantStorageScheme,- ) -> error_stack::Result<Vec<Option<String>>, errors::StorageError>;+ ) -> error_stack::Result<Vec<Option<String>>, Self::Error>;#[cfg(all(feature = "v1", feature = "olap"))]async fn get_filtered_active_attempt_ids_for_total_count(@@ -150,7 +151,7 @@ pub trait PaymentIntentInterface {merchant_id: &id_type::MerchantId,constraints: &PaymentIntentFetchConstraints,storage_scheme: common_enums::MerchantStorageScheme,- ) -> error_stack::Result<Vec<String>, errors::StorageError>;+ ) -> error_stack::Result<Vec<String>, Self::Error>;}#[derive(Clone, Debug, PartialEq, router_derive::DebugAsDisplay, Serialize, Deserialize)]diff --git a/crates/hyperswitch_domain_models/src/payouts/payout_attempt.rs b/crates/hyperswitch_domain_models/src/payouts/payout_attempt.rsindex 22629fede7..dcb61bddc9 100644--- a/crates/hyperswitch_domain_models/src/payouts/payout_attempt.rs+++ b/crates/hyperswitch_domain_models/src/payouts/payout_attempt.rs@@ -9,16 +9,16 @@ use storage_enums::MerchantStorageScheme;use time::PrimitiveDateTime;use super::payouts::Payouts;-use crate::errors;#[async_trait::async_trait]pub trait PayoutAttemptInterface {+ type Error;async fn insert_payout_attempt(&self,_payout_attempt: PayoutAttemptNew,_payouts: &Payouts,_storage_scheme: MerchantStorageScheme,- ) -> error_stack::Result<PayoutAttempt, errors::StorageError>;+ ) -> error_stack::Result<PayoutAttempt, Self::Error>;async fn update_payout_attempt(&self,@@ -26,28 +26,28 @@ pub trait PayoutAttemptInterface {_payout_attempt_update: PayoutAttemptUpdate,_payouts: &Payouts,_storage_scheme: MerchantStorageScheme,- ) -> error_stack::Result<PayoutAttempt, errors::StorageError>;+ ) -> error_stack::Result<PayoutAttempt, Self::Error>;async fn find_payout_attempt_by_merchant_id_payout_attempt_id(&self,_merchant_id: &id_type::MerchantId,_payout_attempt_id: &str,_storage_scheme: MerchantStorageScheme,- ) -> error_stack::Result<PayoutAttempt, errors::StorageError>;+ ) -> error_stack::Result<PayoutAttempt, Self::Error>;async fn find_payout_attempt_by_merchant_id_connector_payout_id(&self,_merchant_id: &id_type::MerchantId,_connector_payout_id: &str,_storage_scheme: MerchantStorageScheme,- ) -> error_stack::Result<PayoutAttempt, errors::StorageError>;+ ) -> error_stack::Result<PayoutAttempt, Self::Error>;async fn get_filters_for_payouts(&self,_payout: &[Payouts],_merchant_id: &id_type::MerchantId,_storage_scheme: MerchantStorageScheme,- ) -> error_stack::Result<PayoutListFilters, errors::StorageError>;+ ) -> error_stack::Result<PayoutListFilters, Self::Error>;}#[derive(Clone, Debug, Eq, PartialEq)]diff --git a/crates/hyperswitch_domain_models/src/payouts/payouts.rs b/crates/hyperswitch_domain_models/src/payouts/payouts.rsindex eb43089e44..7c34b3c26d 100644--- a/crates/hyperswitch_domain_models/src/payouts/payouts.rs+++ b/crates/hyperswitch_domain_models/src/payouts/payouts.rs@@ -7,22 +7,22 @@ use time::PrimitiveDateTime;use super::payout_attempt::PayoutAttempt;#[cfg(feature = "olap")]use super::PayoutFetchConstraints;-use crate::errors;#[async_trait::async_trait]pub trait PayoutsInterface {+ type Error;async fn insert_payout(&self,_payout: PayoutsNew,_storage_scheme: MerchantStorageScheme,- ) -> error_stack::Result<Payouts, errors::StorageError>;+ ) -> error_stack::Result<Payouts, Self::Error>;async fn find_payout_by_merchant_id_payout_id(&self,_merchant_id: &id_type::MerchantId,_payout_id: &str,_storage_scheme: MerchantStorageScheme,- ) -> error_stack::Result<Payouts, errors::StorageError>;+ ) -> error_stack::Result<Payouts, Self::Error>;async fn update_payout(&self,@@ -30,14 +30,14 @@ pub trait PayoutsInterface {_payout: PayoutsUpdate,_payout_attempt: &PayoutAttempt,_storage_scheme: MerchantStorageScheme,- ) -> error_stack::Result<Payouts, errors::StorageError>;+ ) -> error_stack::Result<Payouts, Self::Error>;async fn find_optional_payout_by_merchant_id_payout_id(&self,_merchant_id: &id_type::MerchantId,_payout_id: &str,_storage_scheme: MerchantStorageScheme,- ) -> error_stack::Result<Option<Payouts>, errors::StorageError>;+ ) -> error_stack::Result<Option<Payouts>, Self::Error>;#[cfg(feature = "olap")]async fn filter_payouts_by_constraints(@@ -45,7 +45,7 @@ pub trait PayoutsInterface {_merchant_id: &id_type::MerchantId,_filters: &PayoutFetchConstraints,_storage_scheme: MerchantStorageScheme,- ) -> error_stack::Result<Vec<Payouts>, errors::StorageError>;+ ) -> error_stack::Result<Vec<Payouts>, Self::Error>;#[cfg(feature = "olap")]async fn filter_payouts_and_attempts(@@ -60,7 +60,7 @@ pub trait PayoutsInterface {Option<diesel_models::Customer>,Option<diesel_models::Address>,)>,- errors::StorageError,+ Self::Error,>;#[cfg(feature = "olap")]@@ -69,7 +69,7 @@ pub trait PayoutsInterface {_merchant_id: &id_type::MerchantId,_time_range: &common_utils::types::TimeRange,_storage_scheme: MerchantStorageScheme,- ) -> error_stack::Result<Vec<Payouts>, errors::StorageError>;+ ) -> error_stack::Result<Vec<Payouts>, Self::Error>;#[cfg(feature = "olap")]#[allow(clippy::too_many_arguments)]@@ -81,14 +81,14 @@ pub trait PayoutsInterface {_currency: Option<Vec<storage_enums::Currency>>,_status: Option<Vec<storage_enums::PayoutStatus>>,_payout_method: Option<Vec<storage_enums::PayoutType>>,- ) -> error_stack::Result<i64, errors::StorageError>;+ ) -> error_stack::Result<i64, Self::Error>;#[cfg(feature = "olap")]async fn filter_active_payout_ids_by_constraints(&self,_merchant_id: &id_type::MerchantId,_constraints: &PayoutFetchConstraints,- ) -> error_stack::Result<Vec<String>, errors::StorageError>;+ ) -> error_stack::Result<Vec<String>, Self::Error>;}#[derive(Clone, Debug, Eq, PartialEq)]diff --git a/crates/payment_methods/src/state.rs b/crates/payment_methods/src/state.rsindex 97bb7bb75b..7f75266017 100644--- a/crates/payment_methods/src/state.rs+++ b/crates/payment_methods/src/state.rs@@ -9,16 +9,16 @@ use common_utils::types::keymanager::KeyManagerState;not(feature = "payment_methods_v2")))]use hyperswitch_domain_models::{- errors, merchant_account::MerchantAccount, payment_methods::PaymentMethod,+ merchant_account::MerchantAccount, payment_methods::PaymentMethod,};use hyperswitch_domain_models::{merchant_key_store::MerchantKeyStore, payment_methods::PaymentMethodInterface,};-use storage_impl::{kv_router_store::KVRouterStore, DatabaseStore, MockDb, RouterStore};+use storage_impl::{errors, kv_router_store::KVRouterStore, DatabaseStore, MockDb, RouterStore};#[async_trait::async_trait]pub trait PaymentMethodsStorageInterface:- Send + Sync + dyn_clone::DynClone + PaymentMethodInterface + 'static+ Send + Sync + dyn_clone::DynClone + PaymentMethodInterface<Error = errors::StorageError> + 'static{}dyn_clone::clone_trait_object!(PaymentMethodsStorageInterface);diff --git a/crates/router/src/core/errors.rs b/crates/router/src/core/errors.rsindex 5e1ef76056..d90b9fb743 100644--- a/crates/router/src/core/errors.rs+++ b/crates/router/src/core/errors.rs@@ -10,9 +10,8 @@ use std::fmt::Display;use actix_web::{body::BoxBody, ResponseError};pub use common_utils::errors::{CustomResult, ParsingError, ValidationError};use diesel_models::errors as storage_errors;-pub use hyperswitch_domain_models::errors::{- api_error_response::{ApiErrorResponse, ErrorType, NotImplementedMessage},- StorageError as DataStorageError,+pub use hyperswitch_domain_models::errors::api_error_response::{+ ApiErrorResponse, ErrorType, NotImplementedMessage,};pub use hyperswitch_interfaces::errors::ConnectorError;pub use redis_interface::errors::RedisError;diff --git a/crates/router/src/core/errors/user/sample_data.rs b/crates/router/src/core/errors/user/sample_data.rsindex 3e72e49d31..5aa0da7fb2 100644--- a/crates/router/src/core/errors/user/sample_data.rs+++ b/crates/router/src/core/errors/user/sample_data.rs@@ -1,6 +1,6 @@use api_models::errors::types::{ApiError, ApiErrorResponse};use common_utils::errors::{CustomResult, ErrorSwitch, ErrorSwitchFrom};-use hyperswitch_domain_models::errors::StorageError;+use storage_impl::errors::StorageError;pub type SampleDataResult<T> = CustomResult<T, SampleDataError>;diff --git a/crates/router/src/core/errors/utils.rs b/crates/router/src/core/errors/utils.rsindex 391d808847..093e0a72d1 100644--- a/crates/router/src/core/errors/utils.rs+++ b/crates/router/src/core/errors/utils.rs@@ -42,7 +42,7 @@ impl<T> StorageErrorExt<T, errors::CustomersErrorResponse>}impl<T> StorageErrorExt<T, errors::ApiErrorResponse>- for error_stack::Result<T, hyperswitch_domain_models::errors::StorageError>+ for error_stack::Result<T, errors::StorageError>{#[track_caller]fn to_not_found_response(@@ -51,10 +51,8 @@ impl<T> StorageErrorExt<T, errors::ApiErrorResponse>) -> error_stack::Result<T, errors::ApiErrorResponse> {self.map_err(|err| {let new_err = match err.current_context() {- hyperswitch_domain_models::errors::StorageError::ValueNotFound(_) => {- not_found_response- }- hyperswitch_domain_models::errors::StorageError::CustomerRedacted => {+ errors::StorageError::ValueNotFound(_) => not_found_response,+ errors::StorageError::CustomerRedacted => {errors::ApiErrorResponse::CustomerRedacted}_ => errors::ApiErrorResponse::InternalServerError,@@ -70,9 +68,7 @@ impl<T> StorageErrorExt<T, errors::ApiErrorResponse>) -> error_stack::Result<T, errors::ApiErrorResponse> {self.map_err(|err| {let new_err = match err.current_context() {- hyperswitch_domain_models::errors::StorageError::DuplicateValue { .. } => {- duplicate_response- }+ errors::StorageError::DuplicateValue { .. } => duplicate_response,_ => errors::ApiErrorResponse::InternalServerError,};err.change_context(new_err)@@ -80,42 +76,6 @@ impl<T> StorageErrorExt<T, errors::ApiErrorResponse>}}-impl<T> StorageErrorExt<T, errors::ApiErrorResponse>- for error_stack::Result<T, errors::StorageError>-{- #[track_caller]- fn to_not_found_response(- self,- not_found_response: errors::ApiErrorResponse,- ) -> error_stack::Result<T, errors::ApiErrorResponse> {- self.map_err(|err| {- if err.current_context().is_db_not_found() {- return err.change_context(not_found_response);- };- match err.current_context() {- errors::StorageError::CustomerRedacted => {- err.change_context(errors::ApiErrorResponse::CustomerRedacted)- }- _ => err.change_context(errors::ApiErrorResponse::InternalServerError),- }- })- }-- #[track_caller]- fn to_duplicate_response(- self,- duplicate_response: errors::ApiErrorResponse,- ) -> error_stack::Result<T, errors::ApiErrorResponse> {- self.map_err(|err| {- if err.current_context().is_db_unique_violation() {- err.change_context(duplicate_response)- } else {- err.change_context(errors::ApiErrorResponse::InternalServerError)- }- })- }-}-pub trait ConnectorErrorExt<T> {#[track_caller]fn to_refund_failed_response(self) -> error_stack::Result<T, errors::ApiErrorResponse>;diff --git a/crates/router/src/core/payment_methods/tokenize/payment_method_executor.rs b/crates/router/src/core/payment_methods/tokenize/payment_method_executor.rsindex c9e2618744..2249434b10 100644--- a/crates/router/src/core/payment_methods/tokenize/payment_method_executor.rs+++ b/crates/router/src/core/payment_methods/tokenize/payment_method_executor.rs@@ -282,7 +282,7 @@ impl CardNetworkTokenizeExecutor<'_, domain::TokenizePaymentMethodRequest> {).await.map_err(|err| match err.current_context() {- errors::DataStorageError::DatabaseError(err)+ errors::StorageError::DatabaseError(err)if matches!(err.current_context(),diesel_models::errors::DatabaseError::NotFound@@ -292,7 +292,7 @@ impl CardNetworkTokenizeExecutor<'_, domain::TokenizePaymentMethodRequest> {message: "Invalid payment_method_id".into(),})}- errors::DataStorageError::ValueNotFound(_) => {+ errors::StorageError::ValueNotFound(_) => {report!(errors::ApiErrorResponse::InvalidRequestData {message: "Invalid payment_method_id".to_string(),})diff --git a/crates/router/src/core/payments.rs b/crates/router/src/core/payments.rsindex 52e6397919..1ca9793649 100644--- a/crates/router/src/core/payments.rs+++ b/crates/router/src/core/payments.rs@@ -5584,7 +5584,6 @@ pub async fn list_payments(key_store: domain::MerchantKeyStore,constraints: api::PaymentListConstraints,) -> RouterResponse<api::PaymentListResponse> {- use hyperswitch_domain_models::errors::StorageError;helpers::validate_payment_list_request(&constraints)?;let merchant_id = merchant.get_id();let db = state.store.as_ref();@@ -5612,7 +5611,10 @@ pub async fn list_payments({Ok(pa) => Some(Ok((pi, pa))),Err(error) => {- if matches!(error.current_context(), StorageError::ValueNotFound(_)) {+ if matches!(+ error.current_context(),+ errors::StorageError::ValueNotFound(_)+ ) {logger::warn!(?error,"payment_attempts missing for payment_id : {:?}",diff --git a/crates/router/src/core/payments/helpers.rs b/crates/router/src/core/payments/helpers.rsindex 82c9eca97c..d8e6819089 100644--- a/crates/router/src/core/payments/helpers.rs+++ b/crates/router/src/core/payments/helpers.rs@@ -3130,7 +3130,7 @@ pub(super) async fn filter_by_constraints(merchant_id: &id_type::MerchantId,key_store: &domain::MerchantKeyStore,storage_scheme: storage_enums::MerchantStorageScheme,-) -> CustomResult<Vec<PaymentIntent>, errors::DataStorageError> {+) -> CustomResult<Vec<PaymentIntent>, errors::StorageError> {let db = &*state.store;let result = db.filter_payment_intent_by_constraints(diff --git a/crates/router/src/core/payments/operations/payment_status.rs b/crates/router/src/core/payments/operations/payment_status.rsindex 098362cee3..5b5155bbe3 100644--- a/crates/router/src/core/payments/operations/payment_status.rs+++ b/crates/router/src/core/payments/operations/payment_status.rs@@ -665,7 +665,7 @@ pub async fn get_payment_intent_payment_attempt(.await?;}}- error_stack::Result::<_, errors::DataStorageError>::Ok((pi, pa))+ error_stack::Result::<_, errors::StorageError>::Ok((pi, pa))};get_pi_pa()diff --git a/crates/router/src/core/payouts/helpers.rs b/crates/router/src/core/payouts/helpers.rsindex 332137b6a1..45bd954190 100644--- a/crates/router/src/core/payouts/helpers.rs+++ b/crates/router/src/core/payouts/helpers.rs@@ -1136,7 +1136,7 @@ pub(super) async fn filter_by_constraints(constraints: &api::PayoutListConstraints,merchant_id: &id_type::MerchantId,storage_scheme: storage::enums::MerchantStorageScheme,-) -> CustomResult<Vec<storage::Payouts>, errors::DataStorageError> {+) -> CustomResult<Vec<storage::Payouts>, errors::StorageError> {let result = db.filter_payouts_by_constraints(merchant_id, &constraints.clone().into(), storage_scheme).await?;diff --git a/crates/router/src/core/payouts/validator.rs b/crates/router/src/core/payouts/validator.rsindex 3d7d457635..0bda83c988 100644--- a/crates/router/src/core/payouts/validator.rs+++ b/crates/router/src/core/payouts/validator.rs@@ -6,7 +6,6 @@ use common_utils::errors::CustomResult;use common_utils::validation::validate_domain_against_allowed_domains;use diesel_models::generic_link::PayoutLink;use error_stack::{report, ResultExt};-pub use hyperswitch_domain_models::errors::StorageError;use hyperswitch_domain_models::payment_methods::PaymentMethod;use router_env::{instrument, tracing, which as router_env_which, Env};use url::Url;@@ -24,6 +23,7 @@ use crate::{utils as core_utils,},db::StorageInterface,+ errors::StorageError,routes::SessionState,types::{api::payouts, domain, storage},utils,diff --git a/crates/router/src/db.rs b/crates/router/src/db.rsindex 48d48e380b..84f5c34a82 100644--- a/crates/router/src/db.rs+++ b/crates/router/src/db.rs@@ -109,15 +109,15 @@ pub trait StorageInterface:+ merchant_account::MerchantAccountInterface+ merchant_connector_account::ConnectorAccessToken+ merchant_connector_account::MerchantConnectorAccountInterface- + PaymentAttemptInterface- + PaymentIntentInterface- + PaymentMethodInterface+ + PaymentAttemptInterface<Error = StorageError>+ + PaymentIntentInterface<Error = StorageError>+ + PaymentMethodInterface<Error = StorageError>+ blocklist::BlocklistInterface+ blocklist_fingerprint::BlocklistFingerprintInterface+ dynamic_routing_stats::DynamicRoutingStatsInterface+ scheduler::SchedulerInterface- + PayoutAttemptInterface- + PayoutsInterface+ + PayoutAttemptInterface<Error = StorageError>+ + PayoutsInterface<Error = StorageError>+ refund::RefundInterface+ reverse_lookup::ReverseLookupInterface+ cards_info::CardsInfoInterfacediff --git a/crates/router/src/db/kafka_store.rs b/crates/router/src/db/kafka_store.rsindex d06d13a312..08805f6851 100644--- a/crates/router/src/db/kafka_store.rs+++ b/crates/router/src/db/kafka_store.rs@@ -1433,12 +1433,13 @@ impl QueueInterface for KafkaStore {#[async_trait::async_trait]impl PaymentAttemptInterface for KafkaStore {+ type Error = errors::StorageError;#[cfg(feature = "v1")]async fn insert_payment_attempt(&self,payment_attempt: storage::PaymentAttemptNew,storage_scheme: MerchantStorageScheme,- ) -> CustomResult<storage::PaymentAttempt, errors::DataStorageError> {+ ) -> CustomResult<storage::PaymentAttempt, errors::StorageError> {let attempt = self.diesel_store.insert_payment_attempt(payment_attempt, storage_scheme)@@ -1462,7 +1463,7 @@ impl PaymentAttemptInterface for KafkaStore {merchant_key_store: &domain::MerchantKeyStore,payment_attempt: storage::PaymentAttempt,storage_scheme: MerchantStorageScheme,- ) -> CustomResult<storage::PaymentAttempt, errors::DataStorageError> {+ ) -> CustomResult<storage::PaymentAttempt, errors::StorageError> {let attempt = self.diesel_store.insert_payment_attempt(@@ -1490,7 +1491,7 @@ impl PaymentAttemptInterface for KafkaStore {this: storage::PaymentAttempt,payment_attempt: storage::PaymentAttemptUpdate,storage_scheme: MerchantStorageScheme,- ) -> CustomResult<storage::PaymentAttempt, errors::DataStorageError> {+ ) -> CustomResult<storage::PaymentAttempt, errors::StorageError> {let attempt = self.diesel_store.update_payment_attempt_with_attempt_id(this.clone(), payment_attempt, storage_scheme)@@ -1515,7 +1516,7 @@ impl PaymentAttemptInterface for KafkaStore {this: storage::PaymentAttempt,payment_attempt: storage::PaymentAttemptUpdate,storage_scheme: MerchantStorageScheme,- ) -> CustomResult<storage::PaymentAttempt, errors::DataStorageError> {+ ) -> CustomResult<storage::PaymentAttempt, errors::StorageError> {let attempt = self.diesel_store.update_payment_attempt(@@ -1545,7 +1546,7 @@ impl PaymentAttemptInterface for KafkaStore {payment_id: &id_type::PaymentId,merchant_id: &id_type::MerchantId,storage_scheme: MerchantStorageScheme,- ) -> CustomResult<storage::PaymentAttempt, errors::DataStorageError> {+ ) -> CustomResult<storage::PaymentAttempt, errors::StorageError> {self.diesel_store.find_payment_attempt_by_connector_transaction_id_payment_id_merchant_id(connector_transaction_id,@@ -1562,7 +1563,7 @@ impl PaymentAttemptInterface for KafkaStore {merchant_id: &id_type::MerchantId,connector_txn_id: &str,storage_scheme: MerchantStorageScheme,- ) -> CustomResult<storage::PaymentAttempt, errors::DataStorageError> {+ ) -> CustomResult<storage::PaymentAttempt, errors::StorageError> {self.diesel_store.find_payment_attempt_by_merchant_id_connector_txn_id(merchant_id,@@ -1580,7 +1581,7 @@ impl PaymentAttemptInterface for KafkaStore {profile_id: &id_type::ProfileId,connector_transaction_id: &str,storage_scheme: MerchantStorageScheme,- ) -> CustomResult<storage::PaymentAttempt, errors::DataStorageError> {+ ) -> CustomResult<storage::PaymentAttempt, errors::StorageError> {self.diesel_store.find_payment_attempt_by_profile_id_connector_transaction_id(key_manager_state,@@ -1599,7 +1600,7 @@ impl PaymentAttemptInterface for KafkaStore {merchant_id: &id_type::MerchantId,attempt_id: &str,storage_scheme: MerchantStorageScheme,- ) -> CustomResult<storage::PaymentAttempt, errors::DataStorageError> {+ ) -> CustomResult<storage::PaymentAttempt, errors::StorageError> {self.diesel_store.find_payment_attempt_by_payment_id_merchant_id_attempt_id(payment_id,@@ -1616,7 +1617,7 @@ impl PaymentAttemptInterface for KafkaStore {attempt_id: &str,merchant_id: &id_type::MerchantId,storage_scheme: MerchantStorageScheme,- ) -> CustomResult<storage::PaymentAttempt, errors::DataStorageError> {+ ) -> CustomResult<storage::PaymentAttempt, errors::StorageError> {self.diesel_store.find_payment_attempt_by_attempt_id_merchant_id(attempt_id, merchant_id, storage_scheme).await@@ -1629,7 +1630,7 @@ impl PaymentAttemptInterface for KafkaStore {merchant_key_store: &domain::MerchantKeyStore,attempt_id: &id_type::GlobalAttemptId,storage_scheme: MerchantStorageScheme,- ) -> error_stack::Result<storage::PaymentAttempt, errors::DataStorageError> {+ ) -> error_stack::Result<storage::PaymentAttempt, errors::StorageError> {self.diesel_store.find_payment_attempt_by_id(key_manager_state,@@ -1647,7 +1648,7 @@ impl PaymentAttemptInterface for KafkaStore {payment_id: &id_type::GlobalPaymentId,merchant_key_store: &domain::MerchantKeyStore,storage_scheme: MerchantStorageScheme,- ) -> error_stack::Result<Vec<storage::PaymentAttempt>, errors::DataStorageError> {+ ) -> error_stack::Result<Vec<storage::PaymentAttempt>, errors::StorageError> {self.diesel_store.find_payment_attempts_by_payment_intent_id(key_manager_state,@@ -1664,7 +1665,7 @@ impl PaymentAttemptInterface for KafkaStore {payment_id: &id_type::PaymentId,merchant_id: &id_type::MerchantId,storage_scheme: MerchantStorageScheme,- ) -> CustomResult<storage::PaymentAttempt, errors::DataStorageError> {+ ) -> CustomResult<storage::PaymentAttempt, errors::StorageError> {self.diesel_store.find_payment_attempt_last_successful_attempt_by_payment_id_merchant_id(payment_id,@@ -1680,7 +1681,7 @@ impl PaymentAttemptInterface for KafkaStore {payment_id: &id_type::PaymentId,merchant_id: &id_type::MerchantId,storage_scheme: MerchantStorageScheme,- ) -> CustomResult<storage::PaymentAttempt, errors::DataStorageError> {+ ) -> CustomResult<storage::PaymentAttempt, errors::StorageError> {self.diesel_store.find_payment_attempt_last_successful_or_partially_captured_attempt_by_payment_id_merchant_id(payment_id,@@ -1696,7 +1697,7 @@ impl PaymentAttemptInterface for KafkaStore {preprocessing_id: &str,merchant_id: &id_type::MerchantId,storage_scheme: MerchantStorageScheme,- ) -> CustomResult<storage::PaymentAttempt, errors::DataStorageError> {+ ) -> CustomResult<storage::PaymentAttempt, errors::StorageError> {self.diesel_store.find_payment_attempt_by_preprocessing_id_merchant_id(preprocessing_id,@@ -1714,7 +1715,7 @@ impl PaymentAttemptInterface for KafkaStore {storage_scheme: MerchantStorageScheme,) -> CustomResult<hyperswitch_domain_models::payments::payment_attempt::PaymentListFilters,- errors::DataStorageError,+ errors::StorageError,> {self.diesel_store.get_filters_for_payments(pi, merchant_id, storage_scheme)@@ -1734,7 +1735,7 @@ impl PaymentAttemptInterface for KafkaStore {card_network: Option<Vec<common_enums::CardNetwork>>,card_discovery: Option<Vec<common_enums::CardDiscovery>>,storage_scheme: MerchantStorageScheme,- ) -> CustomResult<i64, errors::DataStorageError> {+ ) -> CustomResult<i64, errors::StorageError> {self.diesel_store.get_total_count_of_filtered_payment_attempts(merchant_id,@@ -1763,7 +1764,7 @@ impl PaymentAttemptInterface for KafkaStore {merchant_connector_id: Option<id_type::MerchantConnectorAccountId>,card_network: Option<common_enums::CardNetwork>,storage_scheme: MerchantStorageScheme,- ) -> CustomResult<i64, errors::DataStorageError> {+ ) -> CustomResult<i64, errors::StorageError> {self.diesel_store.get_total_count_of_filtered_payment_attempts(merchant_id,@@ -1785,7 +1786,7 @@ impl PaymentAttemptInterface for KafkaStore {merchant_id: &id_type::MerchantId,payment_id: &id_type::PaymentId,storage_scheme: MerchantStorageScheme,- ) -> CustomResult<Vec<storage::PaymentAttempt>, errors::DataStorageError> {+ ) -> CustomResult<Vec<storage::PaymentAttempt>, errors::StorageError> {self.diesel_store.find_attempts_by_merchant_id_payment_id(merchant_id, payment_id, storage_scheme).await@@ -1794,6 +1795,7 @@ impl PaymentAttemptInterface for KafkaStore {#[async_trait::async_trait]impl PaymentIntentInterface for KafkaStore {+ type Error = errors::StorageError;async fn update_payment_intent(&self,state: &KeyManagerState,@@ -1801,7 +1803,7 @@ impl PaymentIntentInterface for KafkaStore {payment_intent: storage::PaymentIntentUpdate,key_store: &domain::MerchantKeyStore,storage_scheme: MerchantStorageScheme,- ) -> CustomResult<storage::PaymentIntent, errors::DataStorageError> {+ ) -> CustomResult<storage::PaymentIntent, errors::StorageError> {let intent = self.diesel_store.update_payment_intent(@@ -1830,7 +1832,7 @@ impl PaymentIntentInterface for KafkaStore {new: storage::PaymentIntent,key_store: &domain::MerchantKeyStore,storage_scheme: MerchantStorageScheme,- ) -> CustomResult<storage::PaymentIntent, errors::DataStorageError> {+ ) -> CustomResult<storage::PaymentIntent, errors::StorageError> {logger::debug!("Inserting PaymentIntent Via KafkaStore");let intent = self.diesel_store@@ -1856,7 +1858,7 @@ impl PaymentIntentInterface for KafkaStore {merchant_id: &id_type::MerchantId,key_store: &domain::MerchantKeyStore,storage_scheme: MerchantStorageScheme,- ) -> CustomResult<storage::PaymentIntent, errors::DataStorageError> {+ ) -> CustomResult<storage::PaymentIntent, errors::StorageError> {self.diesel_store.find_payment_intent_by_payment_id_merchant_id(state,@@ -1875,7 +1877,7 @@ impl PaymentIntentInterface for KafkaStore {payment_id: &id_type::GlobalPaymentId,key_store: &domain::MerchantKeyStore,storage_scheme: MerchantStorageScheme,- ) -> CustomResult<storage::PaymentIntent, errors::DataStorageError> {+ ) -> CustomResult<storage::PaymentIntent, errors::StorageError> {self.diesel_store.find_payment_intent_by_id(state, payment_id, key_store, storage_scheme).await@@ -1889,7 +1891,7 @@ impl PaymentIntentInterface for KafkaStore {filters: &hyperswitch_domain_models::payments::payment_intent::PaymentIntentFetchConstraints,key_store: &domain::MerchantKeyStore,storage_scheme: MerchantStorageScheme,- ) -> CustomResult<Vec<storage::PaymentIntent>, errors::DataStorageError> {+ ) -> CustomResult<Vec<storage::PaymentIntent>, errors::StorageError> {self.diesel_store.filter_payment_intent_by_constraints(state,@@ -1909,7 +1911,7 @@ impl PaymentIntentInterface for KafkaStore {time_range: &common_utils::types::TimeRange,key_store: &domain::MerchantKeyStore,storage_scheme: MerchantStorageScheme,- ) -> CustomResult<Vec<storage::PaymentIntent>, errors::DataStorageError> {+ ) -> CustomResult<Vec<storage::PaymentIntent>, errors::StorageError> {self.diesel_store.filter_payment_intents_by_time_range_constraints(state,@@ -1926,7 +1928,7 @@ impl PaymentIntentInterface for KafkaStore {merchant_id: &id_type::MerchantId,profile_id_list: Option<Vec<id_type::ProfileId>>,time_range: &common_utils::types::TimeRange,- ) -> error_stack::Result<Vec<(common_enums::IntentStatus, i64)>, errors::DataStorageError> {+ ) -> error_stack::Result<Vec<(common_enums::IntentStatus, i64)>, errors::StorageError> {self.diesel_store.get_intent_status_with_count(merchant_id, profile_id_list, time_range).await@@ -1945,7 +1947,7 @@ impl PaymentIntentInterface for KafkaStore {hyperswitch_domain_models::payments::PaymentIntent,hyperswitch_domain_models::payments::payment_attempt::PaymentAttempt,)>,- errors::DataStorageError,+ errors::StorageError,> {self.diesel_store.get_filtered_payment_intents_attempt(@@ -1971,7 +1973,7 @@ impl PaymentIntentInterface for KafkaStore {hyperswitch_domain_models::payments::PaymentIntent,Option<hyperswitch_domain_models::payments::payment_attempt::PaymentAttempt>,)>,- errors::DataStorageError,+ errors::StorageError,> {self.diesel_store.get_filtered_payment_intents_attempt(@@ -1990,7 +1992,7 @@ impl PaymentIntentInterface for KafkaStore {merchant_id: &id_type::MerchantId,constraints: &hyperswitch_domain_models::payments::payment_intent::PaymentIntentFetchConstraints,storage_scheme: MerchantStorageScheme,- ) -> CustomResult<Vec<String>, errors::DataStorageError> {+ ) -> CustomResult<Vec<String>, errors::StorageError> {self.diesel_store.get_filtered_active_attempt_ids_for_total_count(merchant_id,@@ -2008,10 +2010,8 @@ impl PaymentIntentInterface for KafkaStore {profile_id: &id_type::ProfileId,merchant_key_store: &domain::MerchantKeyStore,storage_scheme: &MerchantStorageScheme,- ) -> error_stack::Result<- hyperswitch_domain_models::payments::PaymentIntent,- errors::DataStorageError,- > {+ ) -> error_stack::Result<hyperswitch_domain_models::payments::PaymentIntent, errors::StorageError>+ {self.diesel_store.find_payment_intent_by_merchant_reference_id_profile_id(state,@@ -2028,7 +2028,7 @@ impl PaymentIntentInterface for KafkaStore {merchant_id: &id_type::MerchantId,constraints: &hyperswitch_domain_models::payments::payment_intent::PaymentIntentFetchConstraints,storage_scheme: MerchantStorageScheme,- ) -> CustomResult<Vec<Option<String>>, errors::DataStorageError> {+ ) -> CustomResult<Vec<Option<String>>, errors::StorageError> {self.diesel_store.get_filtered_active_attempt_ids_for_total_count(merchant_id,@@ -2041,6 +2041,7 @@ impl PaymentIntentInterface for KafkaStore {#[async_trait::async_trait]impl PaymentMethodInterface for KafkaStore {+ type Error = errors::StorageError;#[cfg(all(any(feature = "v2", feature = "v1"),not(feature = "payment_methods_v2")@@ -2051,7 +2052,7 @@ impl PaymentMethodInterface for KafkaStore {key_store: &domain::MerchantKeyStore,payment_method_id: &str,storage_scheme: MerchantStorageScheme,- ) -> CustomResult<domain::PaymentMethod, errors::DataStorageError> {+ ) -> CustomResult<domain::PaymentMethod, errors::StorageError> {self.diesel_store.find_payment_method(state, key_store, payment_method_id, storage_scheme).await@@ -2064,7 +2065,7 @@ impl PaymentMethodInterface for KafkaStore {key_store: &domain::MerchantKeyStore,payment_method_id: &id_type::GlobalPaymentMethodId,storage_scheme: MerchantStorageScheme,- ) -> CustomResult<domain::PaymentMethod, errors::DataStorageError> {+ ) -> CustomResult<domain::PaymentMethod, errors::StorageError> {self.diesel_store.find_payment_method(state, key_store, payment_method_id, storage_scheme).await@@ -2081,7 +2082,7 @@ impl PaymentMethodInterface for KafkaStore {customer_id: &id_type::CustomerId,merchant_id: &id_type::MerchantId,limit: Option<i64>,- ) -> CustomResult<Vec<domain::PaymentMethod>, errors::DataStorageError> {+ ) -> CustomResult<Vec<domain::PaymentMethod>, errors::StorageError> {self.diesel_store.find_payment_method_by_customer_id_merchant_id_list(state,@@ -2100,7 +2101,7 @@ impl PaymentMethodInterface for KafkaStore {key_store: &domain::MerchantKeyStore,id: &id_type::GlobalCustomerId,limit: Option<i64>,- ) -> CustomResult<Vec<domain::PaymentMethod>, errors::DataStorageError> {+ ) -> CustomResult<Vec<domain::PaymentMethod>, errors::StorageError> {self.diesel_store.find_payment_method_list_by_global_customer_id(state, key_store, id, limit).await@@ -2119,7 +2120,7 @@ impl PaymentMethodInterface for KafkaStore {status: common_enums::PaymentMethodStatus,limit: Option<i64>,storage_scheme: MerchantStorageScheme,- ) -> CustomResult<Vec<domain::PaymentMethod>, errors::DataStorageError> {+ ) -> CustomResult<Vec<domain::PaymentMethod>, errors::StorageError> {self.diesel_store.find_payment_method_by_customer_id_merchant_id_status(state,@@ -2143,7 +2144,7 @@ impl PaymentMethodInterface for KafkaStore {status: common_enums::PaymentMethodStatus,limit: Option<i64>,storage_scheme: MerchantStorageScheme,- ) -> CustomResult<Vec<domain::PaymentMethod>, errors::DataStorageError> {+ ) -> CustomResult<Vec<domain::PaymentMethod>, errors::StorageError> {self.diesel_store.find_payment_method_by_global_customer_id_merchant_id_status(state,@@ -2166,7 +2167,7 @@ impl PaymentMethodInterface for KafkaStore {customer_id: &id_type::CustomerId,merchant_id: &id_type::MerchantId,status: common_enums::PaymentMethodStatus,- ) -> CustomResult<i64, errors::DataStorageError> {+ ) -> CustomResult<i64, errors::StorageError> {self.diesel_store.get_payment_method_count_by_customer_id_merchant_id_status(customer_id,@@ -2180,7 +2181,7 @@ impl PaymentMethodInterface for KafkaStore {&self,merchant_id: &id_type::MerchantId,status: common_enums::PaymentMethodStatus,- ) -> CustomResult<i64, errors::DataStorageError> {+ ) -> CustomResult<i64, errors::StorageError> {self.diesel_store.get_payment_method_count_by_merchant_id_status(merchant_id, status).await@@ -2196,7 +2197,7 @@ impl PaymentMethodInterface for KafkaStore {key_store: &domain::MerchantKeyStore,locker_id: &str,storage_scheme: MerchantStorageScheme,- ) -> CustomResult<domain::PaymentMethod, errors::DataStorageError> {+ ) -> CustomResult<domain::PaymentMethod, errors::StorageError> {self.diesel_store.find_payment_method_by_locker_id(state, key_store, locker_id, storage_scheme).await@@ -2208,7 +2209,7 @@ impl PaymentMethodInterface for KafkaStore {key_store: &domain::MerchantKeyStore,m: domain::PaymentMethod,storage_scheme: MerchantStorageScheme,- ) -> CustomResult<domain::PaymentMethod, errors::DataStorageError> {+ ) -> CustomResult<domain::PaymentMethod, errors::StorageError> {self.diesel_store.insert_payment_method(state, key_store, m, storage_scheme).await@@ -2221,7 +2222,7 @@ impl PaymentMethodInterface for KafkaStore {payment_method: domain::PaymentMethod,payment_method_update: storage::PaymentMethodUpdate,storage_scheme: MerchantStorageScheme,- ) -> CustomResult<domain::PaymentMethod, errors::DataStorageError> {+ ) -> CustomResult<domain::PaymentMethod, errors::StorageError> {self.diesel_store.update_payment_method(state,@@ -2243,7 +2244,7 @@ impl PaymentMethodInterface for KafkaStore {key_store: &domain::MerchantKeyStore,merchant_id: &id_type::MerchantId,payment_method_id: &str,- ) -> CustomResult<domain::PaymentMethod, errors::DataStorageError> {+ ) -> CustomResult<domain::PaymentMethod, errors::StorageError> {self.diesel_store.delete_payment_method_by_merchant_id_payment_method_id(state,@@ -2260,7 +2261,7 @@ impl PaymentMethodInterface for KafkaStore {state: &KeyManagerState,key_store: &domain::MerchantKeyStore,payment_method: domain::PaymentMethod,- ) -> CustomResult<domain::PaymentMethod, errors::DataStorageError> {+ ) -> CustomResult<domain::PaymentMethod, errors::StorageError> {self.diesel_store.delete_payment_method(state, key_store, payment_method).await@@ -2272,7 +2273,7 @@ impl PaymentMethodInterface for KafkaStore {state: &KeyManagerState,key_store: &domain::MerchantKeyStore,fingerprint_id: &str,- ) -> CustomResult<domain::PaymentMethod, errors::DataStorageError> {+ ) -> CustomResult<domain::PaymentMethod, errors::StorageError> {self.diesel_store.find_payment_method_by_fingerprint_id(state, key_store, fingerprint_id).await@@ -2285,12 +2286,13 @@ impl PayoutAttemptInterface for KafkaStore {}#[cfg(feature = "payouts")]#[async_trait::async_trait]impl PayoutAttemptInterface for KafkaStore {+ type Error = errors::StorageError;async fn find_payout_attempt_by_merchant_id_payout_attempt_id(&self,merchant_id: &id_type::MerchantId,payout_attempt_id: &str,storage_scheme: MerchantStorageScheme,- ) -> CustomResult<storage::PayoutAttempt, errors::DataStorageError> {+ ) -> CustomResult<storage::PayoutAttempt, errors::StorageError> {self.diesel_store.find_payout_attempt_by_merchant_id_payout_attempt_id(merchant_id,@@ -2305,7 +2307,7 @@ impl PayoutAttemptInterface for KafkaStore {merchant_id: &id_type::MerchantId,connector_payout_id: &str,storage_scheme: MerchantStorageScheme,- ) -> CustomResult<storage::PayoutAttempt, errors::DataStorageError> {+ ) -> CustomResult<storage::PayoutAttempt, errors::StorageError> {self.diesel_store.find_payout_attempt_by_merchant_id_connector_payout_id(merchant_id,@@ -2321,7 +2323,7 @@ impl PayoutAttemptInterface for KafkaStore {payout_attempt_update: storage::PayoutAttemptUpdate,payouts: &storage::Payouts,storage_scheme: MerchantStorageScheme,- ) -> CustomResult<storage::PayoutAttempt, errors::DataStorageError> {+ ) -> CustomResult<storage::PayoutAttempt, errors::StorageError> {let updated_payout_attempt = self.diesel_store.update_payout_attempt(this, payout_attempt_update, payouts, storage_scheme)@@ -2346,7 +2348,7 @@ impl PayoutAttemptInterface for KafkaStore {payout_attempt: storage::PayoutAttemptNew,payouts: &storage::Payouts,storage_scheme: MerchantStorageScheme,- ) -> CustomResult<storage::PayoutAttempt, errors::DataStorageError> {+ ) -> CustomResult<storage::PayoutAttempt, errors::StorageError> {let payout_attempt_new = self.diesel_store.insert_payout_attempt(payout_attempt, payouts, storage_scheme)@@ -2373,7 +2375,7 @@ impl PayoutAttemptInterface for KafkaStore {storage_scheme: MerchantStorageScheme,) -> CustomResult<hyperswitch_domain_models::payouts::payout_attempt::PayoutListFilters,- errors::DataStorageError,+ errors::StorageError,> {self.diesel_store.get_filters_for_payouts(payouts, merchant_id, storage_scheme)@@ -2387,12 +2389,13 @@ impl PayoutsInterface for KafkaStore {}#[cfg(feature = "payouts")]#[async_trait::async_trait]impl PayoutsInterface for KafkaStore {+ type Error = errors::StorageError;async fn find_payout_by_merchant_id_payout_id(&self,merchant_id: &id_type::MerchantId,payout_id: &str,storage_scheme: MerchantStorageScheme,- ) -> CustomResult<storage::Payouts, errors::DataStorageError> {+ ) -> CustomResult<storage::Payouts, errors::StorageError> {self.diesel_store.find_payout_by_merchant_id_payout_id(merchant_id, payout_id, storage_scheme).await@@ -2404,7 +2407,7 @@ impl PayoutsInterface for KafkaStore {payout_update: storage::PayoutsUpdate,payout_attempt: &storage::PayoutAttempt,storage_scheme: MerchantStorageScheme,- ) -> CustomResult<storage::Payouts, errors::DataStorageError> {+ ) -> CustomResult<storage::Payouts, errors::StorageError> {let payout = self.diesel_store.update_payout(this, payout_update, payout_attempt, storage_scheme)@@ -2427,7 +2430,7 @@ impl PayoutsInterface for KafkaStore {&self,payout: storage::PayoutsNew,storage_scheme: MerchantStorageScheme,- ) -> CustomResult<storage::Payouts, errors::DataStorageError> {+ ) -> CustomResult<storage::Payouts, errors::StorageError> {self.diesel_store.insert_payout(payout, storage_scheme).await@@ -2438,7 +2441,7 @@ impl PayoutsInterface for KafkaStore {merchant_id: &id_type::MerchantId,payout_id: &str,storage_scheme: MerchantStorageScheme,- ) -> CustomResult<Option<storage::Payouts>, errors::DataStorageError> {+ ) -> CustomResult<Option<storage::Payouts>, errors::StorageError> {self.diesel_store.find_optional_payout_by_merchant_id_payout_id(merchant_id, payout_id, storage_scheme).await@@ -2450,7 +2453,7 @@ impl PayoutsInterface for KafkaStore {merchant_id: &id_type::MerchantId,filters: &hyperswitch_domain_models::payouts::PayoutFetchConstraints,storage_scheme: MerchantStorageScheme,- ) -> CustomResult<Vec<storage::Payouts>, errors::DataStorageError> {+ ) -> CustomResult<Vec<storage::Payouts>, errors::StorageError> {self.diesel_store.filter_payouts_by_constraints(merchant_id, filters, storage_scheme).await@@ -2469,7 +2472,7 @@ impl PayoutsInterface for KafkaStore {Option<diesel_models::Customer>,Option<diesel_models::Address>,)>,- errors::DataStorageError,+ errors::StorageError,> {self.diesel_store.filter_payouts_and_attempts(merchant_id, filters, storage_scheme)@@ -2482,7 +2485,7 @@ impl PayoutsInterface for KafkaStore {merchant_id: &id_type::MerchantId,time_range: &common_utils::types::TimeRange,storage_scheme: MerchantStorageScheme,- ) -> CustomResult<Vec<storage::Payouts>, errors::DataStorageError> {+ ) -> CustomResult<Vec<storage::Payouts>, errors::StorageError> {self.diesel_store.filter_payouts_by_time_range_constraints(merchant_id, time_range, storage_scheme).await@@ -2497,7 +2500,7 @@ impl PayoutsInterface for KafkaStore {currency: Option<Vec<enums::Currency>>,status: Option<Vec<enums::PayoutStatus>>,payout_method: Option<Vec<enums::PayoutType>>,- ) -> CustomResult<i64, errors::DataStorageError> {+ ) -> CustomResult<i64, errors::StorageError> {self.diesel_store.get_total_count_of_filtered_payouts(merchant_id,@@ -2515,7 +2518,7 @@ impl PayoutsInterface for KafkaStore {&self,merchant_id: &id_type::MerchantId,constraints: &hyperswitch_domain_models::payouts::PayoutFetchConstraints,- ) -> CustomResult<Vec<String>, errors::DataStorageError> {+ ) -> CustomResult<Vec<String>, errors::StorageError> {self.diesel_store.filter_active_payout_ids_by_constraints(merchant_id, constraints).await@@ -3463,7 +3466,7 @@ impl BatchSampleDataInterface for KafkaStore {key_store: &hyperswitch_domain_models::merchant_key_store::MerchantKeyStore,) -> CustomResult<Vec<hyperswitch_domain_models::payments::PaymentIntent>,- hyperswitch_domain_models::errors::StorageError,+ storage_impl::errors::StorageError,> {let payment_intents_list = self.diesel_store@@ -3485,7 +3488,7 @@ impl BatchSampleDataInterface for KafkaStore {batch: Vec<diesel_models::user::sample_data::PaymentAttemptBatchNew>,) -> CustomResult<Vec<hyperswitch_domain_models::payments::payment_attempt::PaymentAttempt>,- hyperswitch_domain_models::errors::StorageError,+ storage_impl::errors::StorageError,> {let payment_attempts_list = self.diesel_store@@ -3505,8 +3508,7 @@ impl BatchSampleDataInterface for KafkaStore {async fn insert_refunds_batch_for_sample_data(&self,batch: Vec<diesel_models::RefundNew>,- ) -> CustomResult<Vec<diesel_models::Refund>, hyperswitch_domain_models::errors::StorageError>- {+ ) -> CustomResult<Vec<diesel_models::Refund>, storage_impl::errors::StorageError> {let refunds_list = self.diesel_store.insert_refunds_batch_for_sample_data(batch)@@ -3525,8 +3527,7 @@ impl BatchSampleDataInterface for KafkaStore {async fn insert_disputes_batch_for_sample_data(&self,batch: Vec<diesel_models::DisputeNew>,- ) -> CustomResult<Vec<diesel_models::Dispute>, hyperswitch_domain_models::errors::StorageError>- {+ ) -> CustomResult<Vec<diesel_models::Dispute>, storage_impl::errors::StorageError> {let disputes_list = self.diesel_store.insert_disputes_batch_for_sample_data(batch)@@ -3549,7 +3550,7 @@ impl BatchSampleDataInterface for KafkaStore {key_store: &hyperswitch_domain_models::merchant_key_store::MerchantKeyStore,) -> CustomResult<Vec<hyperswitch_domain_models::payments::PaymentIntent>,- hyperswitch_domain_models::errors::StorageError,+ storage_impl::errors::StorageError,> {let payment_intents_list = self.diesel_store@@ -3571,7 +3572,7 @@ impl BatchSampleDataInterface for KafkaStore {merchant_id: &id_type::MerchantId,) -> CustomResult<Vec<hyperswitch_domain_models::payments::payment_attempt::PaymentAttempt>,- hyperswitch_domain_models::errors::StorageError,+ storage_impl::errors::StorageError,> {let payment_attempts_list = self.diesel_store@@ -3592,8 +3593,7 @@ impl BatchSampleDataInterface for KafkaStore {async fn delete_refunds_for_sample_data(&self,merchant_id: &id_type::MerchantId,- ) -> CustomResult<Vec<diesel_models::Refund>, hyperswitch_domain_models::errors::StorageError>- {+ ) -> CustomResult<Vec<diesel_models::Refund>, storage_impl::errors::StorageError> {let refunds_list = self.diesel_store.delete_refunds_for_sample_data(merchant_id)@@ -3613,8 +3613,7 @@ impl BatchSampleDataInterface for KafkaStore {async fn delete_disputes_for_sample_data(&self,merchant_id: &id_type::MerchantId,- ) -> CustomResult<Vec<diesel_models::Dispute>, hyperswitch_domain_models::errors::StorageError>- {+ ) -> CustomResult<Vec<diesel_models::Dispute>, storage_impl::errors::StorageError> {let disputes_list = self.diesel_store.delete_disputes_for_sample_data(merchant_id)diff --git a/crates/router/src/db/user/sample_data.rs b/crates/router/src/db/user/sample_data.rsindex 37007b13f2..5a7b09028b 100644--- a/crates/router/src/db/user/sample_data.rs+++ b/crates/router/src/db/user/sample_data.rs@@ -11,11 +11,10 @@ use error_stack::{Report, ResultExt};use futures::{future::try_join_all, FutureExt};use hyperswitch_domain_models::{behaviour::Conversion,- errors::StorageError,merchant_key_store::MerchantKeyStore,payments::{payment_attempt::PaymentAttempt, PaymentIntent},};-use storage_impl::DataModelExt;+use storage_impl::{errors::StorageError, DataModelExt};use crate::{connection::pg_connection_write, core::errors::CustomResult, services::Store};diff --git a/crates/router/src/events.rs b/crates/router/src/events.rsindex e9a1a17638..19aa2cbfaa 100644--- a/crates/router/src/events.rs+++ b/crates/router/src/events.rs@@ -2,11 +2,13 @@ use std::collections::HashMap;use error_stack::ResultExt;use events::{EventsError, Message, MessagingInterface};-use hyperswitch_domain_models::errors::{StorageError, StorageResult};use masking::ErasedMaskSerialize;use router_env::logger;use serde::{Deserialize, Serialize};-use storage_impl::{config::TenantConfig, errors::ApplicationError};+use storage_impl::{+ config::TenantConfig,+ errors::{ApplicationError, StorageError, StorageResult},+};use time::PrimitiveDateTime;use crate::{diff --git a/crates/router/src/services.rs b/crates/router/src/services.rsindex 39d825114b..7b363d6346 100644--- a/crates/router/src/services.rs+++ b/crates/router/src/services.rs@@ -19,14 +19,13 @@ pub mod openidconnect;use std::sync::Arc;use error_stack::ResultExt;-use hyperswitch_domain_models::errors::StorageResult;pub use hyperswitch_interfaces::connector_integration_v2::{BoxedConnectorIntegrationV2, ConnectorIntegrationAnyV2, ConnectorIntegrationV2,};use masking::{ExposeInterface, StrongSecret};#[cfg(feature = "kv_store")]use storage_impl::kv_router_store::KVRouterStore;-use storage_impl::{config::TenantConfig, redis::RedisStore, RouterStore};+use storage_impl::{config::TenantConfig, errors::StorageResult, redis::RedisStore, RouterStore};use tokio::sync::oneshot;pub use self::{api::*, encryption::*};diff --git a/crates/storage_impl/src/database/store.rs b/crates/storage_impl/src/database/store.rsindex 547be83e3a..6761ec7678 100644--- a/crates/storage_impl/src/database/store.rs+++ b/crates/storage_impl/src/database/store.rs@@ -3,9 +3,11 @@ use bb8::CustomizeConnection;use common_utils::DbConnectionParams;use diesel::PgConnection;use error_stack::ResultExt;-use hyperswitch_domain_models::errors::{StorageError, StorageResult};-use crate::config::{Database, TenantConfig};+use crate::{+ config::{Database, TenantConfig},+ errors::{StorageError, StorageResult},+};pub type PgPool = bb8::Pool<async_bb8_diesel::ConnectionManager<PgConnection>>;pub type PgPooledConn = async_bb8_diesel::Connection<PgConnection>;diff --git a/crates/storage_impl/src/errors.rs b/crates/storage_impl/src/errors.rsindex 657e9b000a..cb0fb0ae1b 100644--- a/crates/storage_impl/src/errors.rs+++ b/crates/storage_impl/src/errors.rs@@ -1,12 +1,13 @@pub use common_enums::{ApiClientError, ApplicationError, ApplicationResult};-use common_utils::errors::ErrorSwitch;-use hyperswitch_domain_models::errors::StorageError as DataStorageError;pub use redis_interface::errors::RedisError;use crate::store::errors::DatabaseError;+pub type StorageResult<T> = error_stack::Result<T, StorageError>;#[derive(Debug, thiserror::Error)]pub enum StorageError {+ #[error("Initialization Error")]+ InitializationError,#[error("DatabaseError: {0:?}")]DatabaseError(error_stack::Report<DatabaseError>),#[error("ValueNotFound: {0}")]@@ -38,56 +39,6 @@ pub enum StorageError {RedisError(error_stack::Report<RedisError>),}-impl ErrorSwitch<DataStorageError> for StorageError {- fn switch(&self) -> DataStorageError {- self.into()- }-}--#[allow(clippy::from_over_into)]-impl Into<DataStorageError> for &StorageError {- fn into(self) -> DataStorageError {- match self {- StorageError::DatabaseError(i) => match i.current_context() {- DatabaseError::DatabaseConnectionError => DataStorageError::DatabaseConnectionError,- // TODO: Update this error type to encompass & propagate the missing type (instead of generic `db value not found`)- DatabaseError::NotFound => {- DataStorageError::ValueNotFound(String::from("db value not found"))- }- // TODO: Update this error type to encompass & propagate the duplicate type (instead of generic `db value not found`)- DatabaseError::UniqueViolation => DataStorageError::DuplicateValue {- entity: "db entity",- key: None,- },- err => DataStorageError::DatabaseError(error_stack::report!(*err)),- },- StorageError::ValueNotFound(i) => DataStorageError::ValueNotFound(i.clone()),- StorageError::DuplicateValue { entity, key } => DataStorageError::DuplicateValue {- entity,- key: key.clone(),- },- StorageError::DatabaseConnectionError => DataStorageError::DatabaseConnectionError,- StorageError::KVError => DataStorageError::KVError,- StorageError::SerializationFailed => DataStorageError::SerializationFailed,- StorageError::MockDbError => DataStorageError::MockDbError,- StorageError::KafkaError => DataStorageError::KafkaError,- StorageError::CustomerRedacted => DataStorageError::CustomerRedacted,- StorageError::DeserializationFailed => DataStorageError::DeserializationFailed,- StorageError::EncryptionError => DataStorageError::EncryptionError,- StorageError::DecryptionError => DataStorageError::DecryptionError,- StorageError::RedisError(i) => match i.current_context() {- // TODO: Update this error type to encompass & propagate the missing type (instead of generic `redis value not found`)- RedisError::NotFound => {- DataStorageError::ValueNotFound("redis value not found".to_string())- }- RedisError::JsonSerializationFailed => DataStorageError::SerializationFailed,- RedisError::JsonDeserializationFailed => DataStorageError::DeserializationFailed,- i => DataStorageError::RedisError(format!("{:?}", i)),- },- }- }-}-impl From<error_stack::Report<RedisError>> for StorageError {fn from(err: error_stack::Report<RedisError>) -> Self {Self::RedisError(err)@@ -128,22 +79,22 @@ impl StorageError {pub trait RedisErrorExt {#[track_caller]- fn to_redis_failed_response(self, key: &str) -> error_stack::Report<DataStorageError>;+ fn to_redis_failed_response(self, key: &str) -> error_stack::Report<StorageError>;}impl RedisErrorExt for error_stack::Report<RedisError> {- fn to_redis_failed_response(self, key: &str) -> error_stack::Report<DataStorageError> {+ fn to_redis_failed_response(self, key: &str) -> error_stack::Report<StorageError> {match self.current_context() {- RedisError::NotFound => self.change_context(DataStorageError::ValueNotFound(format!(+ RedisError::NotFound => self.change_context(StorageError::ValueNotFound(format!("Data does not exist for key {key}",))),RedisError::SetNxFailed | RedisError::SetAddMembersFailed => {- self.change_context(DataStorageError::DuplicateValue {+ self.change_context(StorageError::DuplicateValue {entity: "redis",key: Some(key.to_string()),})}- _ => self.change_context(DataStorageError::KVError),+ _ => self.change_context(StorageError::KVError),}}}diff --git a/crates/storage_impl/src/kv_router_store.rs b/crates/storage_impl/src/kv_router_store.rsindex 0a7e46e3de..5118d902d9 100644--- a/crates/storage_impl/src/kv_router_store.rs+++ b/crates/storage_impl/src/kv_router_store.rs@@ -6,7 +6,6 @@ use diesel_models::{errors::DatabaseError, kv};use error_stack::ResultExt;use hyperswitch_domain_models::{behaviour::{Conversion, ReverseConversion},- errors::{self, StorageResult},merchant_key_store::MerchantKeyStore,};#[cfg(not(feature = "payouts"))]@@ -22,7 +21,7 @@ use crate::{config::TenantConfig,database::store::PgPool,diesel_error_to_data_error,- errors::RedisErrorExt,+ errors::{self, RedisErrorExt, StorageResult},lookup::ReverseLookupInterface,metrics,redis::kv_store::{@@ -65,6 +64,41 @@ pub struct FilterResourceParams<'a> {pub limit: Option<i64>,}+pub enum FindResourceBy<'a> {+ Id(String, PartitionKey<'a>),+ LookupId(String),+}++pub trait DomainType: Debug + Sync + Conversion {}+impl<T: Debug + Sync + Conversion> DomainType for T {}++/// Storage model with all required capabilities for KV operations+pub trait StorageModel<D: Conversion>:+ de::DeserializeOwned+ + serde::Serialize+ + Debug+ + KvStorePartition+ + UniqueConstraints+ + Sync+ + Send+ + ReverseConversion<D>+{+}++impl<T, D> StorageModel<D> for T+where+ T: de::DeserializeOwned+ + serde::Serialize+ + Debug+ + KvStorePartition+ + UniqueConstraints+ + Sync+ + Send+ + ReverseConversion<D>,+ D: DomainType,+{+}+#[async_trait::async_trait]impl<T> DatabaseStore for KVRouterStore<T>where@@ -175,17 +209,11 @@ impl<T: DatabaseStore> KVRouterStore<T> {key_store: &MerchantKeyStore,storage_scheme: MerchantStorageScheme,find_resource_db_fut: R,- lookup_id: String,+ find_by: FindResourceBy<'_>,) -> error_stack::Result<D, errors::StorageError>where- D: Debug + Sync + Conversion,- M: de::DeserializeOwned- + serde::Serialize- + Debug- + KvStorePartition- + UniqueConstraints- + Sync- + ReverseConversion<D>,+ D: DomainType,+ M: StorageModel<D>,R: futures::Future<Output = error_stack::Result<M, DatabaseError>> + Send,{let database_call = || async {@@ -204,19 +232,26 @@ impl<T: DatabaseStore> KVRouterStore<T> {match storage_scheme {MerchantStorageScheme::PostgresOnly => database_call().await,MerchantStorageScheme::RedisKv => {- let lookup = fallback_reverse_lookup_not_found!(- self.get_lookup_by_lookup_id(&lookup_id, storage_scheme)- .await,- database_call().await- );-- let key = PartitionKey::CombinationKey {- combination: &lookup.pk_id,+ let (field, key) = match find_by {+ FindResourceBy::Id(field, key) => (field, key),+ FindResourceBy::LookupId(lookup_id) => {+ let lookup = fallback_reverse_lookup_not_found!(+ self.get_lookup_by_lookup_id(&lookup_id, storage_scheme)+ .await,+ database_call().await+ );+ (+ lookup.clone().sk_id,+ PartitionKey::CombinationKey {+ combination: &lookup.clone().pk_id,+ },+ )+ }};Box::pin(try_redis_get_else_try_database_get(async {- Box::pin(kv_wrapper(self, KvOperation::<M>::HGet(&lookup.sk_id), key))+ Box::pin(kv_wrapper(self, KvOperation::<M>::HGet(&field), key)).await?.try_into_hget()},@@ -237,6 +272,80 @@ impl<T: DatabaseStore> KVRouterStore<T> {.change_context(errors::StorageError::DecryptionError)}+ pub async fn find_optional_resource_by_id<D, R, M>(+ &self,+ state: &KeyManagerState,+ key_store: &MerchantKeyStore,+ storage_scheme: MerchantStorageScheme,+ find_resource_db_fut: R,+ find_by: FindResourceBy<'_>,+ ) -> error_stack::Result<Option<D>, errors::StorageError>+ where+ D: DomainType,+ M: StorageModel<D>,+ R: futures::Future<Output = error_stack::Result<Option<M>, DatabaseError>> + Send,+ {+ let database_call = || async {+ find_resource_db_fut.await.map_err(|error| {+ let new_err = diesel_error_to_data_error(*error.current_context());+ error.change_context(new_err)+ })+ };+ let storage_scheme = Box::pin(decide_storage_scheme::<T, M>(+ self,+ storage_scheme,+ Op::Find,+ ))+ .await;+ let res = || async {+ match storage_scheme {+ MerchantStorageScheme::PostgresOnly => database_call().await,+ MerchantStorageScheme::RedisKv => {+ let (field, key) = match find_by {+ FindResourceBy::Id(field, key) => (field, key),+ FindResourceBy::LookupId(lookup_id) => {+ let lookup = fallback_reverse_lookup_not_found!(+ self.get_lookup_by_lookup_id(&lookup_id, storage_scheme)+ .await,+ database_call().await+ );+ (+ lookup.clone().sk_id,+ PartitionKey::CombinationKey {+ combination: &lookup.clone().pk_id,+ },+ )+ }+ };++ Box::pin(try_redis_get_else_try_database_get(+ async {+ Box::pin(kv_wrapper(self, KvOperation::<M>::HGet(&field), key))+ .await?+ .try_into_hget()+ .map(Some)+ },+ database_call,+ ))+ .await+ }+ }+ };+ match res().await? {+ Some(resource) => Ok(Some(+ resource+ .convert(+ state,+ key_store.key.get_inner(),+ key_store.merchant_id.clone().into(),+ )+ .await+ .change_context(errors::StorageError::DecryptionError)?,+ )),+ None => Ok(None),+ }+ }+pub async fn insert_resource<D, R, M>(&self,state: &KeyManagerState,@@ -254,13 +363,7 @@ impl<T: DatabaseStore> KVRouterStore<T> {) -> error_stack::Result<D, errors::StorageError>whereD: Debug + Sync + Conversion,- M: de::DeserializeOwned- + serde::Serialize- + Debug- + KvStorePartition- + UniqueConstraints- + Sync- + ReverseConversion<D>,+ M: StorageModel<D>,R: futures::Future<Output = error_stack::Result<M, DatabaseError>> + Send,{let storage_scheme = Box::pin(decide_storage_scheme::<_, M>(@@ -336,13 +439,7 @@ impl<T: DatabaseStore> KVRouterStore<T> {) -> error_stack::Result<D, errors::StorageError>whereD: Debug + Sync + Conversion,- M: de::DeserializeOwned- + serde::Serialize- + Debug- + KvStorePartition- + UniqueConstraints- + Sync- + ReverseConversion<D>,+ M: StorageModel<D>,R: futures::Future<Output = error_stack::Result<M, DatabaseError>> + Send,{match operation {@@ -408,13 +505,7 @@ impl<T: DatabaseStore> KVRouterStore<T> {) -> error_stack::Result<Vec<D>, errors::StorageError>whereD: Debug + Sync + Conversion,- M: de::DeserializeOwned- + serde::Serialize- + Debug- + KvStorePartition- + UniqueConstraints- + Sync- + ReverseConversion<D>,+ M: StorageModel<D>,R: futures::Future<Output = error_stack::Result<Vec<M>, DatabaseError>> + Send,{let db_call = || async {diff --git a/crates/storage_impl/src/lib.rs b/crates/storage_impl/src/lib.rsindex 13b4671e86..072722c24a 100644--- a/crates/storage_impl/src/lib.rs+++ b/crates/storage_impl/src/lib.rs@@ -4,7 +4,6 @@ use diesel_models as store;use error_stack::ResultExt;use hyperswitch_domain_models::{behaviour::{Conversion, ReverseConversion},- errors::{StorageError, StorageResult},merchant_key_store::MerchantKeyStore,};use masking::StrongSecret;@@ -37,9 +36,9 @@ use hyperswitch_domain_models::{PayoutAttemptInterface, PayoutsInterface};pub use mock_db::MockDb;use redis_interface::{errors::RedisError, RedisConnectionPool, SaddReply};-pub use crate::database::store::DatabaseStore;#[cfg(not(feature = "payouts"))]pub use crate::database::store::Store;+pub use crate::{database::store::DatabaseStore, errors::StorageError};#[derive(Debug, Clone)]pub struct RouterStore<T: DatabaseStore> {@@ -65,7 +64,7 @@ whereconfig: Self::Config,tenant_config: &dyn config::TenantConfig,test_transaction: bool,- ) -> StorageResult<Self> {+ ) -> error_stack::Result<Self, StorageError> {let (db_conf, cache_conf, encryption_key, cache_error_signal, inmemory_cache_stream) =config;if test_transaction {@@ -113,7 +112,7 @@ impl<T: DatabaseStore> RouterStore<T> {encryption_key: StrongSecret<Vec<u8>>,cache_store: Arc<RedisStore>,inmemory_cache_stream: &str,- ) -> StorageResult<Self> {+ ) -> error_stack::Result<Self, StorageError> {let db_store = T::new(db_conf, tenant_config, false).await?;let redis_conn = cache_store.redis_conn.clone();let cache_store = Arc::new(RedisStore {@@ -140,7 +139,7 @@ impl<T: DatabaseStore> RouterStore<T> {pub async fn cache_store(cache_conf: &redis_interface::RedisSettings,cache_error_signal: tokio::sync::oneshot::Sender<()>,- ) -> StorageResult<Arc<RedisStore>> {+ ) -> error_stack::Result<Arc<RedisStore>, StorageError> {let cache_store = RedisStore::new(cache_conf).await.change_context(StorageError::InitializationError)@@ -225,7 +224,7 @@ impl<T: DatabaseStore> RouterStore<T> {tenant_config: &dyn config::TenantConfig,cache_conf: &redis_interface::RedisSettings,encryption_key: StrongSecret<Vec<u8>>,- ) -> StorageResult<Self> {+ ) -> error_stack::Result<Self, StorageError> {// TODO: create an error enum and return proper error herelet db_store = T::new(db_conf, tenant_config, true).await?;let cache_store = RedisStore::new(cache_conf)diff --git a/crates/storage_impl/src/lookup.rs b/crates/storage_impl/src/lookup.rsindex 2ea9cfd5c8..63bb5ab5c8 100644--- a/crates/storage_impl/src/lookup.rs+++ b/crates/storage_impl/src/lookup.rs@@ -6,12 +6,11 @@ use diesel_models::{},};use error_stack::ResultExt;-use hyperswitch_domain_models::errors;use redis_interface::SetnxReply;use crate::{diesel_error_to_data_error,- errors::RedisErrorExt,+ errors::{self, RedisErrorExt},kv_router_store::KVRouterStore,redis::kv_store::{decide_storage_scheme, kv_wrapper, KvOperation, Op, PartitionKey},utils::{self, try_redis_get_else_try_database_get},diff --git a/crates/storage_impl/src/mock_db.rs b/crates/storage_impl/src/mock_db.rsindex 90d246da15..f086c76295 100644--- a/crates/storage_impl/src/mock_db.rs+++ b/crates/storage_impl/src/mock_db.rs@@ -6,13 +6,12 @@ use error_stack::ResultExt;use futures::lock::{Mutex, MutexGuard};use hyperswitch_domain_models::{behaviour::{Conversion, ReverseConversion},- errors::StorageError,merchant_key_store::MerchantKeyStore,payments::{payment_attempt::PaymentAttempt, PaymentIntent},};use redis_interface::RedisSettings;-use crate::redis::RedisStore;+use crate::{errors::StorageError, redis::RedisStore};pub mod payment_attempt;pub mod payment_intent;diff --git a/crates/storage_impl/src/mock_db/payment_attempt.rs b/crates/storage_impl/src/mock_db/payment_attempt.rsindex 2a637a77e2..06f98bb26b 100644--- a/crates/storage_impl/src/mock_db/payment_attempt.rs+++ b/crates/storage_impl/src/mock_db/payment_attempt.rs@@ -6,17 +6,18 @@ use diesel_models::enums as storage_enums;use hyperswitch_domain_models::merchant_key_store::MerchantKeyStore;#[cfg(feature = "v1")]use hyperswitch_domain_models::payments::payment_attempt::PaymentAttemptNew;-use hyperswitch_domain_models::{- errors::StorageError,- payments::payment_attempt::{PaymentAttempt, PaymentAttemptInterface, PaymentAttemptUpdate},+use hyperswitch_domain_models::payments::payment_attempt::{+ PaymentAttempt, PaymentAttemptInterface, PaymentAttemptUpdate,};use super::MockDb;+use crate::errors::StorageError;#[cfg(feature = "v1")]use crate::DataModelExt;#[async_trait::async_trait]impl PaymentAttemptInterface for MockDb {+ type Error = StorageError;#[cfg(feature = "v1")]async fn find_payment_attempt_by_payment_id_merchant_id_attempt_id(&self,diff --git a/crates/storage_impl/src/mock_db/payment_intent.rs b/crates/storage_impl/src/mock_db/payment_intent.rsindex 3c90ecbdc7..cbdf2b3b0c 100644--- a/crates/storage_impl/src/mock_db/payment_intent.rs+++ b/crates/storage_impl/src/mock_db/payment_intent.rs@@ -3,7 +3,6 @@ use diesel_models::enums as storage_enums;use error_stack::ResultExt;use hyperswitch_domain_models::{behaviour::Conversion,- errors::StorageError,merchant_key_store::MerchantKeyStore,payments::{payment_intent::{PaymentIntentInterface, PaymentIntentUpdate},@@ -12,9 +11,11 @@ use hyperswitch_domain_models::{};use super::MockDb;+use crate::errors::StorageError;#[async_trait::async_trait]impl PaymentIntentInterface for MockDb {+ type Error = StorageError;#[cfg(all(feature = "v1", feature = "olap"))]async fn filter_payment_intent_by_constraints(&self,diff --git a/crates/storage_impl/src/mock_db/payout_attempt.rs b/crates/storage_impl/src/mock_db/payout_attempt.rsindex efdd2cf631..1fd2058e95 100644--- a/crates/storage_impl/src/mock_db/payout_attempt.rs+++ b/crates/storage_impl/src/mock_db/payout_attempt.rs@@ -1,19 +1,18 @@use common_utils::errors::CustomResult;use diesel_models::enums as storage_enums;-use hyperswitch_domain_models::{- errors::StorageError,- payouts::{- payout_attempt::{- PayoutAttempt, PayoutAttemptInterface, PayoutAttemptNew, PayoutAttemptUpdate,- },- payouts::Payouts,+use hyperswitch_domain_models::payouts::{+ payout_attempt::{+ PayoutAttempt, PayoutAttemptInterface, PayoutAttemptNew, PayoutAttemptUpdate,},+ payouts::Payouts,};use super::MockDb;+use crate::errors::StorageError;#[async_trait::async_trait]impl PayoutAttemptInterface for MockDb {+ type Error = StorageError;async fn update_payout_attempt(&self,_this: &PayoutAttempt,diff --git a/crates/storage_impl/src/mock_db/payouts.rs b/crates/storage_impl/src/mock_db/payouts.rsindex c72a08a182..ecba8f88df 100644--- a/crates/storage_impl/src/mock_db/payouts.rs+++ b/crates/storage_impl/src/mock_db/payouts.rs@@ -1,17 +1,15 @@use common_utils::errors::CustomResult;use diesel_models::enums as storage_enums;-use hyperswitch_domain_models::{- errors::StorageError,- payouts::{- payout_attempt::PayoutAttempt,- payouts::{Payouts, PayoutsInterface, PayoutsNew, PayoutsUpdate},- },+use hyperswitch_domain_models::payouts::{+ payout_attempt::PayoutAttempt,+ payouts::{Payouts, PayoutsInterface, PayoutsNew, PayoutsUpdate},};-use super::MockDb;+use crate::{errors::StorageError, MockDb};#[async_trait::async_trait]impl PayoutsInterface for MockDb {+ type Error = StorageError;async fn find_payout_by_merchant_id_payout_id(&self,_merchant_id: &common_utils::id_type::MerchantId,diff --git a/crates/storage_impl/src/payment_method.rs b/crates/storage_impl/src/payment_method.rsindex 4d52ad9d8d..da0fa80a07 100644--- a/crates/storage_impl/src/payment_method.rs+++ b/crates/storage_impl/src/payment_method.rs@@ -13,7 +13,6 @@ use diesel_models::{use error_stack::ResultExt;use hyperswitch_domain_models::{behaviour::{Conversion, ReverseConversion},- errors,merchant_key_store::MerchantKeyStore,payment_methods::{PaymentMethod as DomainPaymentMethod, PaymentMethodInterface},};@@ -21,9 +20,10 @@ use router_env::{instrument, tracing};use super::MockDb;use crate::{- diesel_error_to_data_error,+ diesel_error_to_data_error, errors,kv_router_store::{- FilterResourceParams, InsertResourceParams, KVRouterStore, UpdateResourceParams,+ FilterResourceParams, FindResourceBy, InsertResourceParams, KVRouterStore,+ UpdateResourceParams,},redis::kv_store::{Op, PartitionKey},utils::{pg_connection_read, pg_connection_write},@@ -32,6 +32,7 @@ use crate::{#[async_trait::async_trait]impl<T: DatabaseStore> PaymentMethodInterface for KVRouterStore<T> {+ type Error = errors::StorageError;#[cfg(all(any(feature = "v1", feature = "v2"),not(feature = "payment_methods_v2")@@ -50,7 +51,7 @@ impl<T: DatabaseStore> PaymentMethodInterface for KVRouterStore<T> {key_store,storage_scheme,PaymentMethod::find_by_payment_method_id(&conn, payment_method_id),- format!("payment_method_{}", payment_method_id),+ FindResourceBy::LookupId(format!("payment_method_{}", payment_method_id)),).await}@@ -70,7 +71,10 @@ impl<T: DatabaseStore> PaymentMethodInterface for KVRouterStore<T> {key_store,storage_scheme,PaymentMethod::find_by_id(&conn, payment_method_id),- format!("payment_method_{}", payment_method_id.get_string_repr()),+ FindResourceBy::LookupId(format!(+ "payment_method_{}",+ payment_method_id.get_string_repr()+ )),).await}@@ -93,7 +97,7 @@ impl<T: DatabaseStore> PaymentMethodInterface for KVRouterStore<T> {key_store,storage_scheme,PaymentMethod::find_by_locker_id(&conn, locker_id),- format!("payment_method_locker_{}", locker_id),+ FindResourceBy::LookupId(format!("payment_method_locker_{}", locker_id)),).await}@@ -423,6 +427,7 @@ impl<T: DatabaseStore> PaymentMethodInterface for KVRouterStore<T> {#[async_trait::async_trait]impl<T: DatabaseStore> PaymentMethodInterface for RouterStore<T> {+ type Error = errors::StorageError;#[instrument(skip_all)]#[cfg(all(any(feature = "v1", feature = "v2"),@@ -751,6 +756,7 @@ impl<T: DatabaseStore> PaymentMethodInterface for RouterStore<T> {#[async_trait::async_trait]impl PaymentMethodInterface for MockDb {+ type Error = errors::StorageError;#[cfg(all(any(feature = "v1", feature = "v2"),not(feature = "payment_methods_v2")diff --git a/crates/storage_impl/src/payments/payment_attempt.rs b/crates/storage_impl/src/payments/payment_attempt.rsindex aaa709e7fa..0156270484 100644--- a/crates/storage_impl/src/payments/payment_attempt.rs+++ b/crates/storage_impl/src/payments/payment_attempt.rs@@ -25,7 +25,6 @@ use hyperswitch_domain_models::{merchant_key_store::MerchantKeyStore,};use hyperswitch_domain_models::{- errors,mandates::{MandateAmountData, MandateDataType, MandateDetails},payments::payment_attempt::{PaymentAttempt, PaymentAttemptInterface, PaymentAttemptUpdate},};@@ -38,7 +37,7 @@ use router_env::{instrument, tracing};use crate::{diesel_error_to_data_error,- errors::RedisErrorExt,+ errors::{self, RedisErrorExt},kv_router_store::KVRouterStore,lookup::ReverseLookupInterface,redis::kv_store::{decide_storage_scheme, kv_wrapper, KvOperation, Op, PartitionKey},@@ -48,6 +47,7 @@ use crate::{#[async_trait::async_trait]impl<T: DatabaseStore> PaymentAttemptInterface for RouterStore<T> {+ type Error = errors::StorageError;#[cfg(feature = "v1")]#[instrument(skip_all)]async fn insert_payment_attempt(@@ -550,6 +550,7 @@ impl<T: DatabaseStore> PaymentAttemptInterface for RouterStore<T> {#[async_trait::async_trait]impl<T: DatabaseStore> PaymentAttemptInterface for KVRouterStore<T> {+ type Error = errors::StorageError;#[cfg(feature = "v1")]#[instrument(skip_all)]async fn insert_payment_attempt(diff --git a/crates/storage_impl/src/payments/payment_intent.rs b/crates/storage_impl/src/payments/payment_intent.rsindex 054326fe6a..166e455e6f 100644--- a/crates/storage_impl/src/payments/payment_intent.rs+++ b/crates/storage_impl/src/payments/payment_intent.rs@@ -2,8 +2,6 @@use api_models::payments::{AmountFilter, Order, SortBy, SortOn};#[cfg(feature = "olap")]use async_bb8_diesel::{AsyncConnection, AsyncRunQueryDsl};-#[cfg(feature = "olap")]-use common_utils::errors::ReportSwitchExt;use common_utils::{ext_traits::{AsyncExt, Encode},types::keymanager::KeyManagerState,@@ -34,7 +32,6 @@ use hyperswitch_domain_models::payments::{};use hyperswitch_domain_models::{behaviour::Conversion,- errors::StorageError,merchant_key_store::MerchantKeyStore,payments::{payment_intent::{PaymentIntentInterface, PaymentIntentUpdate},@@ -50,7 +47,7 @@ use router_env::{instrument, tracing};use crate::connection;use crate::{diesel_error_to_data_error,- errors::RedisErrorExt,+ errors::{RedisErrorExt, StorageError},kv_router_store::KVRouterStore,redis::kv_store::{decide_storage_scheme, kv_wrapper, KvOperation, Op, PartitionKey},utils::{self, pg_connection_read, pg_connection_write},@@ -59,6 +56,7 @@ use crate::{#[async_trait::async_trait]impl<T: DatabaseStore> PaymentIntentInterface for KVRouterStore<T> {+ type Error = StorageError;#[cfg(feature = "v1")]async fn insert_payment_intent(&self,@@ -528,6 +526,7 @@ impl<T: DatabaseStore> PaymentIntentInterface for KVRouterStore<T> {#[async_trait::async_trait]impl<T: DatabaseStore> PaymentIntentInterface for crate::RouterStore<T> {+ type Error = StorageError;#[instrument(skip_all)]async fn insert_payment_intent(&self,@@ -730,10 +729,9 @@ impl<T: DatabaseStore> PaymentIntentInterface for crate::RouterStore<T> {merchant_key_store: &MerchantKeyStore,storage_scheme: MerchantStorageScheme,) -> error_stack::Result<Vec<PaymentIntent>, StorageError> {- use common_utils::errors::ReportSwitchExt;use futures::{future::try_join_all, FutureExt};- let conn = connection::pg_connection_read(self).await.switch()?;+ let conn = connection::pg_connection_read(self).await?;let conn = async_bb8_diesel::Connection::as_async_conn(&conn);//[#350]: Replace this with Boxable Expression and pass it into generic filter@@ -876,7 +874,7 @@ impl<T: DatabaseStore> PaymentIntentInterface for crate::RouterStore<T> {profile_id_list: Option<Vec<common_utils::id_type::ProfileId>>,time_range: &common_utils::types::TimeRange,) -> error_stack::Result<Vec<(common_enums::IntentStatus, i64)>, StorageError> {- let conn = connection::pg_connection_read(self).await.switch()?;+ let conn = connection::pg_connection_read(self).await?;let conn = async_bb8_diesel::Connection::as_async_conn(&conn);let mut query = <DieselPaymentIntent as HasTable>::table()@@ -926,7 +924,7 @@ impl<T: DatabaseStore> PaymentIntentInterface for crate::RouterStore<T> {use crate::DataModelExt;- let conn = connection::pg_connection_read(self).await.switch()?;+ let conn = connection::pg_connection_read(self).await?;let conn = async_bb8_diesel::Connection::as_async_conn(&conn);let mut query = DieselPaymentIntent::table().filter(pi_dsl::merchant_id.eq(merchant_id.to_owned()))@@ -1140,7 +1138,7 @@ impl<T: DatabaseStore> PaymentIntentInterface for crate::RouterStore<T> {use crate::DataModelExt;- let conn = connection::pg_connection_read(self).await.switch()?;+ let conn = connection::pg_connection_read(self).await?;let conn = async_bb8_diesel::Connection::as_async_conn(&conn);let mut query = DieselPaymentIntent::table().filter(pi_dsl::merchant_id.eq(merchant_id.to_owned()))@@ -1343,7 +1341,7 @@ impl<T: DatabaseStore> PaymentIntentInterface for crate::RouterStore<T> {constraints: &PaymentIntentFetchConstraints,_storage_scheme: MerchantStorageScheme,) -> error_stack::Result<Vec<Option<String>>, StorageError> {- let conn = connection::pg_connection_read(self).await.switch()?;+ let conn = connection::pg_connection_read(self).await?;let conn = async_bb8_diesel::Connection::as_async_conn(&conn);let mut query = DieselPaymentIntent::table().select(pi_dsl::active_attempt_id)@@ -1430,7 +1428,7 @@ impl<T: DatabaseStore> PaymentIntentInterface for crate::RouterStore<T> {constraints: &PaymentIntentFetchConstraints,_storage_scheme: MerchantStorageScheme,) -> error_stack::Result<Vec<String>, StorageError> {- let conn = connection::pg_connection_read(self).await.switch()?;+ let conn = connection::pg_connection_read(self).await?;let conn = async_bb8_diesel::Connection::as_async_conn(&conn);let mut query = DieselPaymentIntent::table().select(pi_dsl::active_attempt_id)diff --git a/crates/storage_impl/src/payouts/payout_attempt.rs b/crates/storage_impl/src/payouts/payout_attempt.rsindex a56b3cd2c5..e1706fad12 100644--- a/crates/storage_impl/src/payouts/payout_attempt.rs+++ b/crates/storage_impl/src/payouts/payout_attempt.rs@@ -13,21 +13,18 @@ use diesel_models::{ReverseLookupNew,};use error_stack::ResultExt;-use hyperswitch_domain_models::{- errors,- payouts::{- payout_attempt::{- PayoutAttempt, PayoutAttemptInterface, PayoutAttemptNew, PayoutAttemptUpdate,- PayoutListFilters,- },- payouts::Payouts,+use hyperswitch_domain_models::payouts::{+ payout_attempt::{+ PayoutAttempt, PayoutAttemptInterface, PayoutAttemptNew, PayoutAttemptUpdate,+ PayoutListFilters,},+ payouts::Payouts,};use redis_interface::HsetnxReply;use router_env::{instrument, logger, tracing};use crate::{- diesel_error_to_data_error,+ diesel_error_to_data_error, errors,errors::RedisErrorExt,kv_router_store::KVRouterStore,lookup::ReverseLookupInterface,@@ -38,6 +35,7 @@ use crate::{#[async_trait::async_trait]impl<T: DatabaseStore> PayoutAttemptInterface for KVRouterStore<T> {+ type Error = errors::StorageError;#[instrument(skip_all)]async fn insert_payout_attempt(&self,@@ -384,6 +382,7 @@ impl<T: DatabaseStore> PayoutAttemptInterface for KVRouterStore<T> {#[async_trait::async_trait]impl<T: DatabaseStore> PayoutAttemptInterface for crate::RouterStore<T> {+ type Error = errors::StorageError;#[instrument(skip_all)]async fn insert_payout_attempt(&self,diff --git a/crates/storage_impl/src/payouts/payouts.rs b/crates/storage_impl/src/payouts/payouts.rsindex 25e7dd95f6..2beead240e 100644--- a/crates/storage_impl/src/payouts/payouts.rs+++ b/crates/storage_impl/src/payouts/payouts.rs@@ -2,8 +2,6 @@use api_models::enums::PayoutConnectors;#[cfg(feature = "olap")]use async_bb8_diesel::{AsyncConnection, AsyncRunQueryDsl};-#[cfg(feature = "olap")]-use common_utils::errors::ReportSwitchExt;use common_utils::ext_traits::Encode;#[cfg(all(feature = "olap",@@ -43,12 +41,9 @@ use diesel_models::{use error_stack::ResultExt;#[cfg(feature = "olap")]use hyperswitch_domain_models::payouts::PayoutFetchConstraints;-use hyperswitch_domain_models::{- errors::StorageError,- payouts::{- payout_attempt::PayoutAttempt,- payouts::{Payouts, PayoutsInterface, PayoutsNew, PayoutsUpdate},- },+use hyperswitch_domain_models::payouts::{+ payout_attempt::PayoutAttempt,+ payouts::{Payouts, PayoutsInterface, PayoutsNew, PayoutsUpdate},};use redis_interface::HsetnxReply;#[cfg(feature = "olap")]@@ -68,7 +63,7 @@ use crate::store::schema::{};use crate::{diesel_error_to_data_error,- errors::RedisErrorExt,+ errors::{RedisErrorExt, StorageError},kv_router_store::KVRouterStore,redis::kv_store::{decide_storage_scheme, kv_wrapper, KvOperation, Op, PartitionKey},utils::{self, pg_connection_read, pg_connection_write},@@ -77,6 +72,7 @@ use crate::{#[async_trait::async_trait]impl<T: DatabaseStore> PayoutsInterface for KVRouterStore<T> {+ type Error = StorageError;#[instrument(skip_all)]async fn insert_payout(&self,@@ -413,6 +409,7 @@ impl<T: DatabaseStore> PayoutsInterface for KVRouterStore<T> {#[async_trait::async_trait]impl<T: DatabaseStore> PayoutsInterface for crate::RouterStore<T> {+ type Error = StorageError;#[instrument(skip_all)]async fn insert_payout(&self,@@ -492,7 +489,7 @@ impl<T: DatabaseStore> PayoutsInterface for crate::RouterStore<T> {filters: &PayoutFetchConstraints,storage_scheme: MerchantStorageScheme,) -> error_stack::Result<Vec<Payouts>, StorageError> {- let conn = connection::pg_connection_read(self).await.switch()?;+ let conn = connection::pg_connection_read(self).await?;let conn = async_bb8_diesel::Connection::as_async_conn(&conn);//[#350]: Replace this with Boxable Expression and pass it into generic filter@@ -606,9 +603,7 @@ impl<T: DatabaseStore> PayoutsInterface for crate::RouterStore<T> {)>,StorageError,> {- use common_utils::errors::ReportSwitchExt;-- let conn = connection::pg_connection_read(self).await.switch()?;+ let conn = connection::pg_connection_read(self).await?;let conn = async_bb8_diesel::Connection::as_async_conn(&conn);let mut query = DieselPayouts::table().inner_join(@@ -831,7 +826,7 @@ impl<T: DatabaseStore> PayoutsInterface for crate::RouterStore<T> {merchant_id: &common_utils::id_type::MerchantId,constraints: &PayoutFetchConstraints,) -> error_stack::Result<Vec<String>, StorageError> {- let conn = connection::pg_connection_read(self).await.switch()?;+ let conn = connection::pg_connection_read(self).await?;let conn = async_bb8_diesel::Connection::as_async_conn(&conn);let mut query = DieselPayouts::table().inner_join(diff --git a/crates/storage_impl/src/utils.rs b/crates/storage_impl/src/utils.rsindex a5fb19a93d..9cfc683a3b 100644--- a/crates/storage_impl/src/utils.rs+++ b/crates/storage_impl/src/utils.rs@@ -1,9 +1,11 @@use bb8::PooledConnection;use diesel::PgConnection;use error_stack::ResultExt;-use hyperswitch_domain_models::errors::StorageError;-use crate::{errors::RedisErrorExt, metrics, DatabaseStore};+use crate::{+ errors::{RedisErrorExt, StorageError},+ metrics, DatabaseStore,+};pub async fn pg_connection_read<T: DatabaseStore>(store: &T,