refactor(payment_id): add payment id domain type (#5738)

Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
This commit is contained in:
Narayan Bhat
2024-09-02 09:21:33 +05:30
committed by GitHub
parent 4b0564e0e8
commit 7296cceba3
150 changed files with 880 additions and 803 deletions

View File

@ -334,7 +334,7 @@ impl UniqueConstraints for diesel_models::PaymentIntent {
vec![format!(
"pi_{}_{}",
self.merchant_id.get_string_repr(),
self.payment_id
self.payment_id.get_string_repr()
)]
}
fn table_name(&self) -> &str {
@ -347,7 +347,7 @@ impl UniqueConstraints for diesel_models::PaymentAttempt {
vec![format!(
"pa_{}_{}_{}",
self.merchant_id.get_string_repr(),
self.payment_id,
self.payment_id.get_string_repr(),
self.attempt_id
)]
}

View File

@ -15,7 +15,7 @@ use crate::DataModelExt;
impl PaymentAttemptInterface for MockDb {
async fn find_payment_attempt_by_payment_id_merchant_id_attempt_id(
&self,
_payment_id: &str,
_payment_id: &common_utils::id_type::PaymentId,
_merchant_id: &common_utils::id_type::MerchantId,
_attempt_id: &str,
_storage_scheme: storage_enums::MerchantStorageScheme,
@ -83,7 +83,7 @@ impl PaymentAttemptInterface for MockDb {
async fn find_attempts_by_merchant_id_payment_id(
&self,
_merchant_id: &common_utils::id_type::MerchantId,
_payment_id: &str,
_payment_id: &common_utils::id_type::PaymentId,
_storage_scheme: storage_enums::MerchantStorageScheme,
) -> CustomResult<Vec<PaymentAttempt>, StorageError> {
// [#172]: Implement function for `MockDb`
@ -192,7 +192,7 @@ impl PaymentAttemptInterface for MockDb {
async fn find_payment_attempt_by_connector_transaction_id_payment_id_merchant_id(
&self,
_connector_transaction_id: &str,
_payment_id: &str,
_payment_id: &common_utils::id_type::PaymentId,
_merchant_id: &common_utils::id_type::MerchantId,
_storage_scheme: storage_enums::MerchantStorageScheme,
) -> CustomResult<PaymentAttempt, StorageError> {
@ -204,7 +204,7 @@ impl PaymentAttemptInterface for MockDb {
#[allow(clippy::unwrap_used)]
async fn find_payment_attempt_last_successful_attempt_by_payment_id_merchant_id(
&self,
payment_id: &str,
payment_id: &common_utils::id_type::PaymentId,
merchant_id: &common_utils::id_type::MerchantId,
_storage_scheme: storage_enums::MerchantStorageScheme,
) -> CustomResult<PaymentAttempt, StorageError> {
@ -213,7 +213,7 @@ impl PaymentAttemptInterface for MockDb {
Ok(payment_attempts
.iter()
.find(|payment_attempt| {
payment_attempt.payment_id == payment_id
payment_attempt.payment_id == *payment_id
&& payment_attempt.merchant_id.eq(merchant_id)
})
.cloned()
@ -222,7 +222,7 @@ impl PaymentAttemptInterface for MockDb {
#[allow(clippy::unwrap_used)]
async fn find_payment_attempt_last_successful_or_partially_captured_attempt_by_payment_id_merchant_id(
&self,
payment_id: &str,
payment_id: &common_utils::id_type::PaymentId,
merchant_id: &common_utils::id_type::MerchantId,
_storage_scheme: storage_enums::MerchantStorageScheme,
) -> CustomResult<PaymentAttempt, StorageError> {
@ -231,7 +231,7 @@ impl PaymentAttemptInterface for MockDb {
Ok(payment_attempts
.iter()
.find(|payment_attempt| {
payment_attempt.payment_id == payment_id
payment_attempt.payment_id == *payment_id
&& payment_attempt.merchant_id.eq(merchant_id)
&& (payment_attempt.status == storage_enums::AttemptStatus::PartialCharged
|| payment_attempt.status == storage_enums::AttemptStatus::Charged)

View File

@ -125,7 +125,7 @@ impl PaymentIntentInterface for MockDb {
async fn find_payment_intent_by_payment_id_merchant_id(
&self,
_state: &KeyManagerState,
payment_id: &str,
payment_id: &common_utils::id_type::PaymentId,
merchant_id: &common_utils::id_type::MerchantId,
_key_store: &MerchantKeyStore,
_storage_scheme: storage_enums::MerchantStorageScheme,
@ -135,7 +135,7 @@ impl PaymentIntentInterface for MockDb {
Ok(payment_intents
.iter()
.find(|payment_intent| {
payment_intent.payment_id == payment_id
payment_intent.payment_id == *payment_id
&& payment_intent.merchant_id.eq(merchant_id)
})
.cloned()

View File

@ -79,7 +79,7 @@ impl<T: DatabaseStore> PaymentAttemptInterface for RouterStore<T> {
async fn find_payment_attempt_by_connector_transaction_id_payment_id_merchant_id(
&self,
connector_transaction_id: &str,
payment_id: &str,
payment_id: &common_utils::id_type::PaymentId,
merchant_id: &common_utils::id_type::MerchantId,
_storage_scheme: MerchantStorageScheme,
) -> CustomResult<PaymentAttempt, errors::StorageError> {
@ -101,7 +101,7 @@ impl<T: DatabaseStore> PaymentAttemptInterface for RouterStore<T> {
#[instrument(skip_all)]
async fn find_payment_attempt_last_successful_attempt_by_payment_id_merchant_id(
&self,
payment_id: &str,
payment_id: &common_utils::id_type::PaymentId,
merchant_id: &common_utils::id_type::MerchantId,
_storage_scheme: MerchantStorageScheme,
) -> CustomResult<PaymentAttempt, errors::StorageError> {
@ -122,7 +122,7 @@ impl<T: DatabaseStore> PaymentAttemptInterface for RouterStore<T> {
#[instrument(skip_all)]
async fn find_payment_attempt_last_successful_or_partially_captured_attempt_by_payment_id_merchant_id(
&self,
payment_id: &str,
payment_id: &common_utils::id_type::PaymentId,
merchant_id: &common_utils::id_type::MerchantId,
_storage_scheme: MerchantStorageScheme,
) -> CustomResult<PaymentAttempt, errors::StorageError> {
@ -164,7 +164,7 @@ impl<T: DatabaseStore> PaymentAttemptInterface for RouterStore<T> {
#[instrument(skip_all)]
async fn find_payment_attempt_by_payment_id_merchant_id_attempt_id(
&self,
payment_id: &str,
payment_id: &common_utils::id_type::PaymentId,
merchant_id: &common_utils::id_type::MerchantId,
attempt_id: &str,
_storage_scheme: MerchantStorageScheme,
@ -251,7 +251,7 @@ impl<T: DatabaseStore> PaymentAttemptInterface for RouterStore<T> {
async fn find_attempts_by_merchant_id_payment_id(
&self,
merchant_id: &common_utils::id_type::MerchantId,
payment_id: &str,
payment_id: &common_utils::id_type::PaymentId,
_storage_scheme: MerchantStorageScheme,
) -> CustomResult<Vec<PaymentAttempt>, errors::StorageError> {
let conn = pg_connection_read(self).await?;
@ -600,7 +600,7 @@ impl<T: DatabaseStore> PaymentAttemptInterface for KVRouterStore<T> {
async fn find_payment_attempt_by_connector_transaction_id_payment_id_merchant_id(
&self,
connector_transaction_id: &str,
payment_id: &str,
payment_id: &common_utils::id_type::PaymentId,
merchant_id: &common_utils::id_type::MerchantId,
storage_scheme: MerchantStorageScheme,
) -> error_stack::Result<PaymentAttempt, errors::StorageError> {
@ -654,7 +654,7 @@ impl<T: DatabaseStore> PaymentAttemptInterface for KVRouterStore<T> {
#[instrument(skip_all)]
async fn find_payment_attempt_last_successful_attempt_by_payment_id_merchant_id(
&self,
payment_id: &str,
payment_id: &common_utils::id_type::PaymentId,
merchant_id: &common_utils::id_type::MerchantId,
storage_scheme: MerchantStorageScheme,
) -> error_stack::Result<PaymentAttempt, errors::StorageError> {
@ -708,7 +708,7 @@ impl<T: DatabaseStore> PaymentAttemptInterface for KVRouterStore<T> {
#[instrument(skip_all)]
async fn find_payment_attempt_last_successful_or_partially_captured_attempt_by_payment_id_merchant_id(
&self,
payment_id: &str,
payment_id: &common_utils::id_type::PaymentId,
merchant_id: &common_utils::id_type::MerchantId,
storage_scheme: MerchantStorageScheme,
) -> error_stack::Result<PaymentAttempt, errors::StorageError> {
@ -829,7 +829,7 @@ impl<T: DatabaseStore> PaymentAttemptInterface for KVRouterStore<T> {
#[instrument(skip_all)]
async fn find_payment_attempt_by_payment_id_merchant_id_attempt_id(
&self,
payment_id: &str,
payment_id: &common_utils::id_type::PaymentId,
merchant_id: &common_utils::id_type::MerchantId,
attempt_id: &str,
storage_scheme: MerchantStorageScheme,
@ -1004,7 +1004,7 @@ impl<T: DatabaseStore> PaymentAttemptInterface for KVRouterStore<T> {
async fn find_attempts_by_merchant_id_payment_id(
&self,
merchant_id: &common_utils::id_type::MerchantId,
payment_id: &str,
payment_id: &common_utils::id_type::PaymentId,
storage_scheme: MerchantStorageScheme,
) -> error_stack::Result<Vec<PaymentAttempt>, errors::StorageError> {
let storage_scheme =

View File

@ -74,7 +74,7 @@ impl<T: DatabaseStore> PaymentIntentInterface for KVRouterStore<T> {
) -> error_stack::Result<PaymentIntent, StorageError> {
let merchant_id = payment_intent.merchant_id.clone();
let payment_id = payment_intent.payment_id.clone();
let field = format!("pi_{}", payment_intent.payment_id);
let field = payment_intent.payment_id.get_hash_key_for_kv_store();
let key = PartitionKey::MerchantIdPaymentId {
merchant_id: &merchant_id,
payment_id: &payment_id,
@ -153,7 +153,7 @@ impl<T: DatabaseStore> PaymentIntentInterface for KVRouterStore<T> {
merchant_id: &merchant_id,
payment_id: &payment_id,
};
let field = format!("pi_{}", this.payment_id);
let field = format!("pi_{}", this.payment_id.get_string_repr());
let storage_scheme = decide_storage_scheme::<_, DieselPaymentIntent>(
self,
storage_scheme,
@ -229,7 +229,7 @@ impl<T: DatabaseStore> PaymentIntentInterface for KVRouterStore<T> {
async fn find_payment_intent_by_payment_id_merchant_id(
&self,
state: &KeyManagerState,
payment_id: &str,
payment_id: &common_utils::id_type::PaymentId,
merchant_id: &common_utils::id_type::MerchantId,
merchant_key_store: &MerchantKeyStore,
storage_scheme: MerchantStorageScheme,
@ -253,7 +253,7 @@ impl<T: DatabaseStore> PaymentIntentInterface for KVRouterStore<T> {
merchant_id,
payment_id,
};
let field = format!("pi_{payment_id}");
let field = payment_id.get_hash_key_for_kv_store();
Box::pin(utils::try_redis_get_else_try_database_get(
async {
kv_wrapper::<DieselPaymentIntent, _, _>(
@ -463,7 +463,7 @@ impl<T: DatabaseStore> PaymentIntentInterface for crate::RouterStore<T> {
async fn find_payment_intent_by_payment_id_merchant_id(
&self,
state: &KeyManagerState,
payment_id: &str,
payment_id: &common_utils::id_type::PaymentId,
merchant_id: &common_utils::id_type::MerchantId,
merchant_key_store: &MerchantKeyStore,
_storage_scheme: MerchantStorageScheme,

View File

@ -25,7 +25,7 @@ pub trait KvStorePartition {
pub enum PartitionKey<'a> {
MerchantIdPaymentId {
merchant_id: &'a common_utils::id_type::MerchantId,
payment_id: &'a str,
payment_id: &'a common_utils::id_type::PaymentId,
},
CombinationKey {
combination: &'a str,
@ -64,8 +64,9 @@ impl<'a> std::fmt::Display for PartitionKey<'a> {
merchant_id,
payment_id,
} => f.write_str(&format!(
"mid_{}_pid_{payment_id}",
merchant_id.get_string_repr()
"mid_{}_pid_{}",
merchant_id.get_string_repr(),
payment_id.get_string_repr()
)),
PartitionKey::CombinationKey { combination } => f.write_str(combination),
PartitionKey::MerchantIdCustomerId {