mirror of
				https://github.com/juspay/hyperswitch.git
				synced 2025-10-31 01:57:45 +08:00 
			
		
		
		
	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:
		| @ -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( | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user
	 Sanchith Hegde
					Sanchith Hegde