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: empty payment attempts on payment retrieve (#3447)

Kartikeya Hegdebec4f2a24e22
diff --git a/crates/storage_impl/src/payments/payment_attempt.rs b/crates/storage_impl/src/payments/payment_attempt.rs
index b8d71cb32b..ad52a8aaea 100644
--- a/crates/storage_impl/src/payments/payment_attempt.rs
+++ b/crates/storage_impl/src/payments/payment_attempt.rs
@@ -932,12 +932,23 @@ impl<T: DatabaseStore> PaymentAttemptInterface for KVRouterStore<T> {
}
MerchantStorageScheme::RedisKv => {
let key = format!("mid_{merchant_id}_pid_{payment_id}");
-
- kv_wrapper(self, KvOperation::<DieselPaymentAttempt>::Scan("pa_*"), key)
- .await
- .change_context(errors::StorageError::KVError)?
- .try_into_scan()
- .change_context(errors::StorageError::KVError)
+ Box::pin(try_redis_get_else_try_database_get(
+ async {
+ kv_wrapper(self, KvOperation::<DieselPaymentAttempt>::Scan("pa_*"), key)
+ .await?
+ .try_into_scan()
+ },
+ || async {
+ self.router_store
+ .find_attempts_by_merchant_id_payment_id(
+ merchant_id,
+ payment_id,
+ storage_scheme,
+ )
+ .await
+ },
+ ))
+ .await
}
}
}
diff --git a/crates/storage_impl/src/redis/kv_store.rs b/crates/storage_impl/src/redis/kv_store.rs
index 9339b11a9b..ad57ad403d 100644
--- a/crates/storage_impl/src/redis/kv_store.rs
+++ b/crates/storage_impl/src/redis/kv_store.rs
@@ -131,7 +131,16 @@ where
}
KvOperation::Scan(pattern) => {
- let result: Vec<T> = redis_conn.hscan_and_deserialize(key, pattern, None).await?;
+ let result: Vec<T> = redis_conn
+ .hscan_and_deserialize(key, pattern, None)
+ .await
+ .and_then(|result| {
+ if result.is_empty() {
+ Err(RedisError::NotFound).into_report()
+ } else {
+ Ok(result)
+ }
+ })?;
Ok(KvResult::Scan(result))
}