fix(payment_attempt): consider merchant storage scheme when finding payment attempt by connector txn ID, payment ID, merchant ID (#291)

This commit is contained in:
Sanchith Hegde
2023-01-05 17:31:08 +05:30
committed by GitHub
parent 3c1406787e
commit 3174c43b24

View File

@ -564,26 +564,42 @@ mod storage {
async fn find_payment_attempt_by_connector_transaction_id_payment_id_merchant_id( async fn find_payment_attempt_by_connector_transaction_id_payment_id_merchant_id(
&self, &self,
connector_transaction_id: &str, connector_transaction_id: &str,
_payment_id: &str, payment_id: &str,
merchant_id: &str, merchant_id: &str,
_storage_scheme: enums::MerchantStorageScheme, storage_scheme: enums::MerchantStorageScheme,
) -> CustomResult<PaymentAttempt, errors::StorageError> { ) -> CustomResult<PaymentAttempt, errors::StorageError> {
// We assume that PaymentAttempt <=> PaymentIntent is a one-to-one relation for now match storage_scheme {
let lookup_id = format!("{merchant_id}_{connector_transaction_id}"); enums::MerchantStorageScheme::PostgresOnly => {
let lookup = self let conn = pg_connection(&self.master_pool).await;
.get_lookup_by_lookup_id(&lookup_id) PaymentAttempt::find_by_connector_transaction_id_payment_id_merchant_id(
.await &conn,
.map_err(Into::<errors::StorageError>::into) connector_transaction_id,
.into_report()?; payment_id,
let key = &lookup.pk_id; merchant_id,
self.redis_conn )
.get_hash_field_and_deserialize::<PaymentAttempt>( .await
key, .map_err(Into::into)
&lookup.sk_id, .into_report()
"PaymentAttempt", }
) enums::MerchantStorageScheme::RedisKv => {
.await // We assume that PaymentAttempt <=> PaymentIntent is a one-to-one relation for now
.map_err(|error| error.to_redis_failed_response(key)) let lookup_id = format!("{merchant_id}_{connector_transaction_id}");
let lookup = self
.get_lookup_by_lookup_id(&lookup_id)
.await
.map_err(Into::<errors::StorageError>::into)
.into_report()?;
let key = &lookup.pk_id;
self.redis_conn
.get_hash_field_and_deserialize::<PaymentAttempt>(
key,
&lookup.sk_id,
"PaymentAttempt",
)
.await
.map_err(|error| error.to_redis_failed_response(key))
}
}
} }
async fn find_payment_attempt_last_successful_attempt_by_payment_id_merchant_id( async fn find_payment_attempt_last_successful_attempt_by_payment_id_merchant_id(