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

feat(router): append payment_id to secondary key for payment_intent in kv flow (#2378)

Sai Harsha Vardhanee9155208d6c
diff --git a/crates/storage_impl/src/payments/payment_intent.rs b/crates/storage_impl/src/payments/payment_intent.rs
index 27d2a3a3de..b365c6a378 100644
--- a/crates/storage_impl/src/payments/payment_intent.rs
+++ b/crates/storage_impl/src/payments/payment_intent.rs
@@ -56,6 +56,7 @@ impl<T: DatabaseStore> PaymentIntentInterface for KVRouterStore<T> {
MerchantStorageScheme::RedisKv => {
let key = format!("{}_{}", new.merchant_id, new.payment_id);
+ let field = format!("pi_{}", new.payment_id);
let created_intent = PaymentIntent {
id: 0i32,
payment_id: new.payment_id.clone(),
@@ -95,7 +96,7 @@ impl<T: DatabaseStore> PaymentIntentInterface for KVRouterStore<T> {
match self
.get_redis_conn()
.change_context(StorageError::DatabaseConnectionError)?
- .serialize_and_set_hash_field_if_not_exist(&key, "pi", &created_intent)
+ .serialize_and_set_hash_field_if_not_exist(&key, &field, &created_intent)
.await
{
Ok(HsetnxReply::KeyNotSet) => Err(StorageError::DuplicateValue {
@@ -141,6 +142,7 @@ impl<T: DatabaseStore> PaymentIntentInterface for KVRouterStore<T> {
}
MerchantStorageScheme::RedisKv => {
let key = format!("{}_{}", this.merchant_id, this.payment_id);
+ let field = format!("pi_{}", this.payment_id);
let updated_intent = payment_intent.clone().apply_changeset(this.clone());
// Check for database presence as well Maybe use a read replica here ?
@@ -152,7 +154,7 @@ impl<T: DatabaseStore> PaymentIntentInterface for KVRouterStore<T> {
let updated_intent = self
.get_redis_conn()
.change_context(StorageError::DatabaseConnectionError)?
- .set_hash_fields(&key, ("pi", &redis_value))
+ .set_hash_fields(&key, (&field, &redis_value))
.await
.map(|_| updated_intent)
.change_context(StorageError::KVError)?;
@@ -203,10 +205,11 @@ impl<T: DatabaseStore> PaymentIntentInterface for KVRouterStore<T> {
MerchantStorageScheme::RedisKv => {
let key = format!("{merchant_id}_{payment_id}");
+ let field = format!("pi_{payment_id}");
crate::utils::try_redis_get_else_try_database_get(
self.get_redis_conn()
.change_context(StorageError::DatabaseConnectionError)?
- .get_hash_field_and_deserialize(&key, "pi", "PaymentIntent"),
+ .get_hash_field_and_deserialize(&key, &field, "PaymentIntent"),
database_call,
)
.await