refactor(merchant_id): create domain type for merchant_id (#5408)

Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
Co-authored-by: Sanchith Hegde <22217505+SanchithHegde@users.noreply.github.com>
This commit is contained in:
Narayan Bhat
2024-07-24 19:18:25 +05:30
committed by GitHub
parent e18ea7a7ba
commit 7068fbfbe2
406 changed files with 3168 additions and 2633 deletions

View File

@ -80,7 +80,7 @@ impl<T: DatabaseStore> PaymentAttemptInterface for RouterStore<T> {
&self,
connector_transaction_id: &str,
payment_id: &str,
merchant_id: &str,
merchant_id: &common_utils::id_type::MerchantId,
_storage_scheme: MerchantStorageScheme,
) -> CustomResult<PaymentAttempt, errors::StorageError> {
let conn = pg_connection_read(self).await?;
@ -102,7 +102,7 @@ impl<T: DatabaseStore> PaymentAttemptInterface for RouterStore<T> {
async fn find_payment_attempt_last_successful_attempt_by_payment_id_merchant_id(
&self,
payment_id: &str,
merchant_id: &str,
merchant_id: &common_utils::id_type::MerchantId,
_storage_scheme: MerchantStorageScheme,
) -> CustomResult<PaymentAttempt, errors::StorageError> {
let conn = pg_connection_read(self).await?;
@ -123,7 +123,7 @@ impl<T: DatabaseStore> PaymentAttemptInterface for RouterStore<T> {
async fn find_payment_attempt_last_successful_or_partially_captured_attempt_by_payment_id_merchant_id(
&self,
payment_id: &str,
merchant_id: &str,
merchant_id: &common_utils::id_type::MerchantId,
_storage_scheme: MerchantStorageScheme,
) -> CustomResult<PaymentAttempt, errors::StorageError> {
let conn = pg_connection_read(self).await?;
@ -143,7 +143,7 @@ impl<T: DatabaseStore> PaymentAttemptInterface for RouterStore<T> {
#[instrument(skip_all)]
async fn find_payment_attempt_by_merchant_id_connector_txn_id(
&self,
merchant_id: &str,
merchant_id: &common_utils::id_type::MerchantId,
connector_txn_id: &str,
_storage_scheme: MerchantStorageScheme,
) -> CustomResult<PaymentAttempt, errors::StorageError> {
@ -165,7 +165,7 @@ impl<T: DatabaseStore> PaymentAttemptInterface for RouterStore<T> {
async fn find_payment_attempt_by_payment_id_merchant_id_attempt_id(
&self,
payment_id: &str,
merchant_id: &str,
merchant_id: &common_utils::id_type::MerchantId,
attempt_id: &str,
_storage_scheme: MerchantStorageScheme,
) -> CustomResult<PaymentAttempt, errors::StorageError> {
@ -189,7 +189,7 @@ impl<T: DatabaseStore> PaymentAttemptInterface for RouterStore<T> {
async fn get_filters_for_payments(
&self,
pi: &[PaymentIntent],
merchant_id: &str,
merchant_id: &common_utils::id_type::MerchantId,
_storage_scheme: MerchantStorageScheme,
) -> CustomResult<PaymentListFilters, errors::StorageError> {
let conn = pg_connection_read(self).await?;
@ -229,7 +229,7 @@ impl<T: DatabaseStore> PaymentAttemptInterface for RouterStore<T> {
async fn find_payment_attempt_by_preprocessing_id_merchant_id(
&self,
preprocessing_id: &str,
merchant_id: &str,
merchant_id: &common_utils::id_type::MerchantId,
_storage_scheme: MerchantStorageScheme,
) -> CustomResult<PaymentAttempt, errors::StorageError> {
let conn = pg_connection_read(self).await?;
@ -250,7 +250,7 @@ impl<T: DatabaseStore> PaymentAttemptInterface for RouterStore<T> {
#[instrument(skip_all)]
async fn find_attempts_by_merchant_id_payment_id(
&self,
merchant_id: &str,
merchant_id: &common_utils::id_type::MerchantId,
payment_id: &str,
_storage_scheme: MerchantStorageScheme,
) -> CustomResult<Vec<PaymentAttempt>, errors::StorageError> {
@ -272,7 +272,7 @@ impl<T: DatabaseStore> PaymentAttemptInterface for RouterStore<T> {
async fn find_payment_attempt_by_attempt_id_merchant_id(
&self,
attempt_id: &str,
merchant_id: &str,
merchant_id: &common_utils::id_type::MerchantId,
_storage_scheme: MerchantStorageScheme,
) -> CustomResult<PaymentAttempt, errors::StorageError> {
let conn = pg_connection_read(self).await?;
@ -289,7 +289,7 @@ impl<T: DatabaseStore> PaymentAttemptInterface for RouterStore<T> {
#[instrument(skip_all)]
async fn get_total_count_of_filtered_payment_attempts(
&self,
merchant_id: &str,
merchant_id: &common_utils::id_type::MerchantId,
active_attempt_ids: &[String],
connector: Option<Vec<Connector>>,
payment_method: Option<Vec<PaymentMethod>>,
@ -435,7 +435,8 @@ impl<T: DatabaseStore> PaymentAttemptInterface for KVRouterStore<T> {
let reverse_lookup = ReverseLookupNew {
lookup_id: format!(
"pa_{}_{}",
&created_attempt.merchant_id, &created_attempt.attempt_id,
created_attempt.merchant_id.get_string_repr(),
&created_attempt.attempt_id,
),
pk_id: key_str.clone(),
sk_id: field.clone(),
@ -527,7 +528,7 @@ impl<T: DatabaseStore> PaymentAttemptInterface for KVRouterStore<T> {
add_connector_txn_id_to_reverse_lookup(
self,
key_str.as_str(),
this.merchant_id.as_str(),
&this.merchant_id,
updated_attempt.attempt_id.as_str(),
connector_transaction_id.as_str(),
storage_scheme,
@ -539,7 +540,7 @@ impl<T: DatabaseStore> PaymentAttemptInterface for KVRouterStore<T> {
add_connector_txn_id_to_reverse_lookup(
self,
key_str.as_str(),
this.merchant_id.as_str(),
&this.merchant_id,
updated_attempt.attempt_id.as_str(),
connector_transaction_id.as_str(),
storage_scheme,
@ -555,7 +556,7 @@ impl<T: DatabaseStore> PaymentAttemptInterface for KVRouterStore<T> {
add_preprocessing_id_to_reverse_lookup(
self,
key_str.as_str(),
this.merchant_id.as_str(),
&this.merchant_id,
updated_attempt.attempt_id.as_str(),
preprocessing_id.as_str(),
storage_scheme,
@ -567,7 +568,7 @@ impl<T: DatabaseStore> PaymentAttemptInterface for KVRouterStore<T> {
add_preprocessing_id_to_reverse_lookup(
self,
key_str.as_str(),
this.merchant_id.as_str(),
&this.merchant_id,
updated_attempt.attempt_id.as_str(),
preprocessing_id.as_str(),
storage_scheme,
@ -598,7 +599,7 @@ impl<T: DatabaseStore> PaymentAttemptInterface for KVRouterStore<T> {
&self,
connector_transaction_id: &str,
payment_id: &str,
merchant_id: &str,
merchant_id: &common_utils::id_type::MerchantId,
storage_scheme: MerchantStorageScheme,
) -> error_stack::Result<PaymentAttempt, errors::StorageError> {
let storage_scheme =
@ -616,7 +617,10 @@ impl<T: DatabaseStore> PaymentAttemptInterface for KVRouterStore<T> {
}
MerchantStorageScheme::RedisKv => {
// We assume that PaymentAttempt <=> PaymentIntent is a one-to-one relation for now
let lookup_id = format!("pa_conn_trans_{merchant_id}_{connector_transaction_id}");
let lookup_id = format!(
"pa_conn_trans_{}_{connector_transaction_id}",
merchant_id.get_string_repr()
);
let lookup = fallback_reverse_lookup_not_found!(
self.get_lookup_by_lookup_id(&lookup_id, storage_scheme)
.await,
@ -649,7 +653,7 @@ impl<T: DatabaseStore> PaymentAttemptInterface for KVRouterStore<T> {
async fn find_payment_attempt_last_successful_attempt_by_payment_id_merchant_id(
&self,
payment_id: &str,
merchant_id: &str,
merchant_id: &common_utils::id_type::MerchantId,
storage_scheme: MerchantStorageScheme,
) -> error_stack::Result<PaymentAttempt, errors::StorageError> {
let database_call = || {
@ -703,7 +707,7 @@ impl<T: DatabaseStore> PaymentAttemptInterface for KVRouterStore<T> {
async fn find_payment_attempt_last_successful_or_partially_captured_attempt_by_payment_id_merchant_id(
&self,
payment_id: &str,
merchant_id: &str,
merchant_id: &common_utils::id_type::MerchantId,
storage_scheme: MerchantStorageScheme,
) -> error_stack::Result<PaymentAttempt, errors::StorageError> {
let database_call = || {
@ -759,7 +763,7 @@ impl<T: DatabaseStore> PaymentAttemptInterface for KVRouterStore<T> {
#[instrument(skip_all)]
async fn find_payment_attempt_by_merchant_id_connector_txn_id(
&self,
merchant_id: &str,
merchant_id: &common_utils::id_type::MerchantId,
connector_txn_id: &str,
storage_scheme: MerchantStorageScheme,
) -> error_stack::Result<PaymentAttempt, errors::StorageError> {
@ -776,7 +780,10 @@ impl<T: DatabaseStore> PaymentAttemptInterface for KVRouterStore<T> {
.await
}
MerchantStorageScheme::RedisKv => {
let lookup_id = format!("pa_conn_trans_{merchant_id}_{connector_txn_id}");
let lookup_id = format!(
"pa_conn_trans_{}_{connector_txn_id}",
merchant_id.get_string_repr()
);
let lookup = fallback_reverse_lookup_not_found!(
self.get_lookup_by_lookup_id(&lookup_id, storage_scheme)
.await,
@ -821,7 +828,7 @@ impl<T: DatabaseStore> PaymentAttemptInterface for KVRouterStore<T> {
async fn find_payment_attempt_by_payment_id_merchant_id_attempt_id(
&self,
payment_id: &str,
merchant_id: &str,
merchant_id: &common_utils::id_type::MerchantId,
attempt_id: &str,
storage_scheme: MerchantStorageScheme,
) -> error_stack::Result<PaymentAttempt, errors::StorageError> {
@ -870,7 +877,7 @@ impl<T: DatabaseStore> PaymentAttemptInterface for KVRouterStore<T> {
async fn find_payment_attempt_by_attempt_id_merchant_id(
&self,
attempt_id: &str,
merchant_id: &str,
merchant_id: &common_utils::id_type::MerchantId,
storage_scheme: MerchantStorageScheme,
) -> error_stack::Result<PaymentAttempt, errors::StorageError> {
let storage_scheme =
@ -886,7 +893,7 @@ impl<T: DatabaseStore> PaymentAttemptInterface for KVRouterStore<T> {
.await
}
MerchantStorageScheme::RedisKv => {
let lookup_id = format!("pa_{merchant_id}_{attempt_id}");
let lookup_id = format!("pa_{}_{attempt_id}", merchant_id.get_string_repr());
let lookup = fallback_reverse_lookup_not_found!(
self.get_lookup_by_lookup_id(&lookup_id, storage_scheme)
.await,
@ -931,7 +938,7 @@ impl<T: DatabaseStore> PaymentAttemptInterface for KVRouterStore<T> {
async fn find_payment_attempt_by_preprocessing_id_merchant_id(
&self,
preprocessing_id: &str,
merchant_id: &str,
merchant_id: &common_utils::id_type::MerchantId,
storage_scheme: MerchantStorageScheme,
) -> error_stack::Result<PaymentAttempt, errors::StorageError> {
let storage_scheme =
@ -947,7 +954,10 @@ impl<T: DatabaseStore> PaymentAttemptInterface for KVRouterStore<T> {
.await
}
MerchantStorageScheme::RedisKv => {
let lookup_id = format!("pa_preprocessing_{merchant_id}_{preprocessing_id}");
let lookup_id = format!(
"pa_preprocessing_{}_{preprocessing_id}",
merchant_id.get_string_repr()
);
let lookup = fallback_reverse_lookup_not_found!(
self.get_lookup_by_lookup_id(&lookup_id, storage_scheme)
.await,
@ -991,7 +1001,7 @@ impl<T: DatabaseStore> PaymentAttemptInterface for KVRouterStore<T> {
#[instrument(skip_all)]
async fn find_attempts_by_merchant_id_payment_id(
&self,
merchant_id: &str,
merchant_id: &common_utils::id_type::MerchantId,
payment_id: &str,
storage_scheme: MerchantStorageScheme,
) -> error_stack::Result<Vec<PaymentAttempt>, errors::StorageError> {
@ -1037,7 +1047,7 @@ impl<T: DatabaseStore> PaymentAttemptInterface for KVRouterStore<T> {
async fn get_filters_for_payments(
&self,
pi: &[PaymentIntent],
merchant_id: &str,
merchant_id: &common_utils::id_type::MerchantId,
storage_scheme: MerchantStorageScheme,
) -> error_stack::Result<PaymentListFilters, errors::StorageError> {
self.router_store
@ -1048,7 +1058,7 @@ impl<T: DatabaseStore> PaymentAttemptInterface for KVRouterStore<T> {
#[instrument(skip_all)]
async fn get_total_count_of_filtered_payment_attempts(
&self,
merchant_id: &str,
merchant_id: &common_utils::id_type::MerchantId,
active_attempt_ids: &[String],
connector: Option<Vec<Connector>>,
payment_method: Option<Vec<PaymentMethod>>,
@ -2276,14 +2286,18 @@ impl DataModelExt for PaymentAttemptUpdate {
async fn add_connector_txn_id_to_reverse_lookup<T: DatabaseStore>(
store: &KVRouterStore<T>,
key: &str,
merchant_id: &str,
merchant_id: &common_utils::id_type::MerchantId,
updated_attempt_attempt_id: &str,
connector_transaction_id: &str,
storage_scheme: MerchantStorageScheme,
) -> CustomResult<ReverseLookup, errors::StorageError> {
let field = format!("pa_{}", updated_attempt_attempt_id);
let reverse_lookup_new = ReverseLookupNew {
lookup_id: format!("pa_conn_trans_{}_{}", merchant_id, connector_transaction_id),
lookup_id: format!(
"pa_conn_trans_{}_{}",
merchant_id.get_string_repr(),
connector_transaction_id
),
pk_id: key.to_owned(),
sk_id: field.clone(),
source: "payment_attempt".to_string(),
@ -2299,14 +2313,18 @@ async fn add_connector_txn_id_to_reverse_lookup<T: DatabaseStore>(
async fn add_preprocessing_id_to_reverse_lookup<T: DatabaseStore>(
store: &KVRouterStore<T>,
key: &str,
merchant_id: &str,
merchant_id: &common_utils::id_type::MerchantId,
updated_attempt_attempt_id: &str,
preprocessing_id: &str,
storage_scheme: MerchantStorageScheme,
) -> CustomResult<ReverseLookup, errors::StorageError> {
let field = format!("pa_{}", updated_attempt_attempt_id);
let reverse_lookup_new = ReverseLookupNew {
lookup_id: format!("pa_preprocessing_{}_{}", merchant_id, preprocessing_id),
lookup_id: format!(
"pa_preprocessing_{}_{}",
merchant_id.get_string_repr(),
preprocessing_id
),
pk_id: key.to_owned(),
sk_id: field.clone(),
source: "payment_attempt".to_string(),

View File

@ -215,7 +215,7 @@ impl<T: DatabaseStore> PaymentIntentInterface for KVRouterStore<T> {
state,
diesel_intent,
merchant_key_store.key.get_inner(),
merchant_id,
merchant_id.into(),
)
.await
.change_context(StorageError::DecryptionError)?;
@ -230,7 +230,7 @@ impl<T: DatabaseStore> PaymentIntentInterface for KVRouterStore<T> {
&self,
state: &KeyManagerState,
payment_id: &str,
merchant_id: &str,
merchant_id: &common_utils::id_type::MerchantId,
merchant_key_store: &MerchantKeyStore,
storage_scheme: MerchantStorageScheme,
) -> error_stack::Result<PaymentIntent, StorageError> {
@ -274,7 +274,7 @@ impl<T: DatabaseStore> PaymentIntentInterface for KVRouterStore<T> {
state,
diesel_payment_intent,
merchant_key_store.key.get_inner(),
merchant_id.to_string(),
merchant_id.to_owned().into(),
)
.await
.change_context(StorageError::DecryptionError)
@ -291,7 +291,7 @@ impl<T: DatabaseStore> PaymentIntentInterface for KVRouterStore<T> {
let pa = DieselPaymentAttempt::find_by_merchant_id_attempt_id(
&conn,
payment.merchant_id.as_str(),
&payment.merchant_id,
attempt_id.as_str(),
)
.await
@ -311,7 +311,7 @@ impl<T: DatabaseStore> PaymentIntentInterface for KVRouterStore<T> {
async fn filter_payment_intent_by_constraints(
&self,
state: &KeyManagerState,
merchant_id: &str,
merchant_id: &common_utils::id_type::MerchantId,
filters: &PaymentIntentFetchConstraints,
merchant_key_store: &MerchantKeyStore,
storage_scheme: MerchantStorageScheme,
@ -331,7 +331,7 @@ impl<T: DatabaseStore> PaymentIntentInterface for KVRouterStore<T> {
async fn filter_payment_intents_by_time_range_constraints(
&self,
state: &KeyManagerState,
merchant_id: &str,
merchant_id: &common_utils::id_type::MerchantId,
time_range: &api_models::payments::TimeRange,
merchant_key_store: &MerchantKeyStore,
storage_scheme: MerchantStorageScheme,
@ -351,7 +351,7 @@ impl<T: DatabaseStore> PaymentIntentInterface for KVRouterStore<T> {
async fn get_filtered_payment_intents_attempt(
&self,
state: &KeyManagerState,
merchant_id: &str,
merchant_id: &common_utils::id_type::MerchantId,
filters: &PaymentIntentFetchConstraints,
merchant_key_store: &MerchantKeyStore,
storage_scheme: MerchantStorageScheme,
@ -370,7 +370,7 @@ impl<T: DatabaseStore> PaymentIntentInterface for KVRouterStore<T> {
#[cfg(feature = "olap")]
async fn get_filtered_active_attempt_ids_for_total_count(
&self,
merchant_id: &str,
merchant_id: &common_utils::id_type::MerchantId,
constraints: &PaymentIntentFetchConstraints,
storage_scheme: MerchantStorageScheme,
) -> error_stack::Result<Vec<String>, StorageError> {
@ -410,7 +410,7 @@ impl<T: DatabaseStore> PaymentIntentInterface for crate::RouterStore<T> {
state,
diesel_payment_intent,
merchant_key_store.key.get_inner(),
merchant_key_store.merchant_id.clone(),
merchant_key_store.merchant_id.clone().into(),
)
.await
.change_context(StorageError::DecryptionError)
@ -443,7 +443,7 @@ impl<T: DatabaseStore> PaymentIntentInterface for crate::RouterStore<T> {
state,
diesel_payment_intent,
merchant_key_store.key.get_inner(),
merchant_key_store.merchant_id.clone(),
merchant_key_store.merchant_id.clone().into(),
)
.await
.change_context(StorageError::DecryptionError)
@ -454,7 +454,7 @@ impl<T: DatabaseStore> PaymentIntentInterface for crate::RouterStore<T> {
&self,
state: &KeyManagerState,
payment_id: &str,
merchant_id: &str,
merchant_id: &common_utils::id_type::MerchantId,
merchant_key_store: &MerchantKeyStore,
_storage_scheme: MerchantStorageScheme,
) -> error_stack::Result<PaymentIntent, StorageError> {
@ -471,7 +471,7 @@ impl<T: DatabaseStore> PaymentIntentInterface for crate::RouterStore<T> {
state,
diesel_payment_intent,
merchant_key_store.key.get_inner(),
merchant_key_store.merchant_id.clone(),
merchant_key_store.merchant_id.clone().into(),
)
.await
.change_context(StorageError::DecryptionError)
@ -491,7 +491,7 @@ impl<T: DatabaseStore> PaymentIntentInterface for crate::RouterStore<T> {
let pa = DieselPaymentAttempt::find_by_merchant_id_attempt_id(
&conn,
payment.merchant_id.as_str(),
&payment.merchant_id,
attempt_id.as_str(),
)
.await
@ -512,7 +512,7 @@ impl<T: DatabaseStore> PaymentIntentInterface for crate::RouterStore<T> {
async fn filter_payment_intent_by_constraints(
&self,
state: &KeyManagerState,
merchant_id: &str,
merchant_id: &common_utils::id_type::MerchantId,
filters: &PaymentIntentFetchConstraints,
merchant_key_store: &MerchantKeyStore,
storage_scheme: MerchantStorageScheme,
@ -619,7 +619,7 @@ impl<T: DatabaseStore> PaymentIntentInterface for crate::RouterStore<T> {
state,
diesel_payment_intent,
merchant_key_store.key.get_inner(),
merchant_key_store.merchant_id.clone(),
merchant_key_store.merchant_id.clone().into(),
)
}))
.map(|join_result| join_result.change_context(StorageError::DecryptionError))
@ -638,7 +638,7 @@ impl<T: DatabaseStore> PaymentIntentInterface for crate::RouterStore<T> {
async fn filter_payment_intents_by_time_range_constraints(
&self,
state: &KeyManagerState,
merchant_id: &str,
merchant_id: &common_utils::id_type::MerchantId,
time_range: &api_models::payments::TimeRange,
merchant_key_store: &MerchantKeyStore,
storage_scheme: MerchantStorageScheme,
@ -660,7 +660,7 @@ impl<T: DatabaseStore> PaymentIntentInterface for crate::RouterStore<T> {
async fn get_filtered_payment_intents_attempt(
&self,
state: &KeyManagerState,
merchant_id: &str,
merchant_id: &common_utils::id_type::MerchantId,
constraints: &PaymentIntentFetchConstraints,
merchant_key_store: &MerchantKeyStore,
storage_scheme: MerchantStorageScheme,
@ -811,7 +811,7 @@ impl<T: DatabaseStore> PaymentIntentInterface for crate::RouterStore<T> {
state,
pi,
merchant_key_store.key.get_inner(),
merchant_id.to_string(),
merchant_id.to_owned().into(),
)
.map(|payment_intent| {
payment_intent.map(|payment_intent| {
@ -834,7 +834,7 @@ impl<T: DatabaseStore> PaymentIntentInterface for crate::RouterStore<T> {
#[instrument(skip_all)]
async fn get_filtered_active_attempt_ids_for_total_count(
&self,
merchant_id: &str,
merchant_id: &common_utils::id_type::MerchantId,
constraints: &PaymentIntentFetchConstraints,
_storage_scheme: MerchantStorageScheme,
) -> error_stack::Result<Vec<String>, StorageError> {