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

This commit is contained in:
Sai Harsha Vardhan
2023-09-27 13:24:29 +05:30
committed by GitHub
parent 934542e926
commit ee9155208d

View File

@ -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