Skip to content

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

fix(router): fix refunds and payment_attempts kv flow (#2362)

Sai Harsha Vardhanef0df7195d9a
diff --git a/crates/router/src/db/refund.rs b/crates/router/src/db/refund.rs
index cb7a46dfb4..67980730f8 100644
--- a/crates/router/src/db/refund.rs
+++ b/crates/router/src/db/refund.rs
@@ -629,13 +629,9 @@ mod storage {
}
enums::MerchantStorageScheme::RedisKv => {
let key = format!("{merchant_id}_{payment_id}");
- let lookup = self.get_lookup_by_lookup_id(&key).await?;
-
- let pattern = db_utils::generate_hscan_pattern_for_refund(&lookup.sk_id);
-
self.get_redis_conn()
.map_err(Into::<errors::StorageError>::into)?
- .hscan_and_deserialize(&key, &pattern, None)
+ .hscan_and_deserialize(&key, "pa_*_ref_*", None)
.await
.change_context(errors::StorageError::KVError)
}
diff --git a/crates/storage_impl/src/payments/payment_attempt.rs b/crates/storage_impl/src/payments/payment_attempt.rs
index 84e119fd7c..f99a23ba53 100644
--- a/crates/storage_impl/src/payments/payment_attempt.rs
+++ b/crates/storage_impl/src/payments/payment_attempt.rs
@@ -29,10 +29,7 @@ use crate::{
diesel_error_to_data_error,
lookup::ReverseLookupInterface,
redis::kv_store::{PartitionKey, RedisConnInterface},
- utils::{
- generate_hscan_pattern_for_attempt, pg_connection_read, pg_connection_write,
- try_redis_get_else_try_database_get,
- },
+ utils::{pg_connection_read, pg_connection_write, try_redis_get_else_try_database_get},
DataModelExt, DatabaseStore, KVRouterStore, RouterStore,
};
@@ -800,16 +797,13 @@ impl<T: DatabaseStore> PaymentAttemptInterface for KVRouterStore<T> {
}
MerchantStorageScheme::RedisKv => {
let key = format!("{merchant_id}_{payment_id}");
- let lookup = self.get_lookup_by_lookup_id(&key).await?;
-
- let pattern = generate_hscan_pattern_for_attempt(&lookup.sk_id);
self.get_redis_conn()
.map_err(|er| {
let error = format!("{}", er);
er.change_context(errors::StorageError::RedisError(error))
})?
- .hscan_and_deserialize(&key, &pattern, None)
+ .hscan_and_deserialize(&key, "pa_*", None)
.await
.change_context(errors::StorageError::KVError)
}
diff --git a/crates/storage_impl/src/utils.rs b/crates/storage_impl/src/utils.rs
index 92fd11debe..6d6e1cd540 100644
--- a/crates/storage_impl/src/utils.rs
+++ b/crates/storage_impl/src/utils.rs
@@ -68,13 +68,3 @@ where
},
}
}
-
-/// Generates hscan field pattern. Suppose the field is pa_1234 it will generate
-/// pa_*
-pub fn generate_hscan_pattern_for_attempt(sk: &str) -> String {
- sk.split('_')
- .take(1)
- .chain(["*"])
- .collect::<Vec<&str>>()
- .join("_")
-}