@@ -46,11 +46,12 @@ where
4646 merchant_key_store : & domain:: MerchantKeyStore ,
4747 ) -> CustomResult < domain:: Event , errors:: StorageError > ;
4848
49- async fn list_initial_events_by_merchant_id_primary_object_id (
49+ async fn list_initial_events_by_merchant_id_primary_object_or_initial_attempt_id (
5050 & self ,
5151 state : & KeyManagerState ,
5252 merchant_id : & common_utils:: id_type:: MerchantId ,
5353 primary_object_id : & str ,
54+ initial_attempt_id : & str ,
5455 merchant_key_store : & domain:: MerchantKeyStore ,
5556 ) -> CustomResult < Vec < domain:: Event > , errors:: StorageError > ;
5657
@@ -76,11 +77,12 @@ where
7677 merchant_key_store : & domain:: MerchantKeyStore ,
7778 ) -> CustomResult < Vec < domain:: Event > , errors:: StorageError > ;
7879
79- async fn list_initial_events_by_profile_id_primary_object_id (
80+ async fn list_initial_events_by_profile_id_primary_object_or_initial_attempt_id (
8081 & self ,
8182 state : & KeyManagerState ,
8283 profile_id : & common_utils:: id_type:: ProfileId ,
8384 primary_object_id : & str ,
85+ initial_attempt_id : & str ,
8486 merchant_key_store : & domain:: MerchantKeyStore ,
8587 ) -> CustomResult < Vec < domain:: Event > , errors:: StorageError > ;
8688
@@ -191,18 +193,20 @@ impl EventInterface for Store {
191193 }
192194
193195 #[ instrument( skip_all) ]
194- async fn list_initial_events_by_merchant_id_primary_object_id (
196+ async fn list_initial_events_by_merchant_id_primary_object_or_initial_attempt_id (
195197 & self ,
196198 state : & KeyManagerState ,
197199 merchant_id : & common_utils:: id_type:: MerchantId ,
198200 primary_object_id : & str ,
201+ initial_attempt_id : & str ,
199202 merchant_key_store : & domain:: MerchantKeyStore ,
200203 ) -> CustomResult < Vec < domain:: Event > , errors:: StorageError > {
201204 let conn = connection:: pg_connection_read ( self ) . await ?;
202- storage:: Event :: list_initial_attempts_by_merchant_id_primary_object_id (
205+ storage:: Event :: list_initial_attempts_by_merchant_id_primary_object_id_or_initial_attempt_id (
203206 & conn,
204207 merchant_id,
205208 primary_object_id,
209+ initial_attempt_id,
206210 )
207211 . await
208212 . map_err ( |error| report ! ( errors:: StorageError :: from( error) ) )
@@ -306,18 +310,20 @@ impl EventInterface for Store {
306310 }
307311
308312 #[ instrument( skip_all) ]
309- async fn list_initial_events_by_profile_id_primary_object_id (
313+ async fn list_initial_events_by_profile_id_primary_object_or_initial_attempt_id (
310314 & self ,
311315 state : & KeyManagerState ,
312316 profile_id : & common_utils:: id_type:: ProfileId ,
313317 primary_object_id : & str ,
318+ initial_attempt_id : & str ,
314319 merchant_key_store : & domain:: MerchantKeyStore ,
315320 ) -> CustomResult < Vec < domain:: Event > , errors:: StorageError > {
316321 let conn = connection:: pg_connection_read ( self ) . await ?;
317- storage:: Event :: list_initial_attempts_by_profile_id_primary_object_id (
322+ storage:: Event :: list_initial_attempts_by_profile_id_primary_object_id_or_initial_attempt_id (
318323 & conn,
319324 profile_id,
320325 primary_object_id,
326+ initial_attempt_id,
321327 )
322328 . await
323329 . map_err ( |error| report ! ( errors:: StorageError :: from( error) ) )
@@ -527,20 +533,22 @@ impl EventInterface for MockDb {
527533 )
528534 }
529535
530- async fn list_initial_events_by_merchant_id_primary_object_id (
536+ async fn list_initial_events_by_merchant_id_primary_object_or_initial_attempt_id (
531537 & self ,
532538 state : & KeyManagerState ,
533539 merchant_id : & common_utils:: id_type:: MerchantId ,
534540 primary_object_id : & str ,
541+ initial_attempt_id : & str ,
535542 merchant_key_store : & domain:: MerchantKeyStore ,
536543 ) -> CustomResult < Vec < domain:: Event > , errors:: StorageError > {
537544 let locked_events = self . events . lock ( ) . await ;
538545 let events = locked_events
539546 . iter ( )
540547 . filter ( |event| {
541548 event. merchant_id == Some ( merchant_id. to_owned ( ) )
542- && event. initial_attempt_id . as_ref ( ) == Some ( & event. event_id )
543- && event. primary_object_id == primary_object_id
549+ && event. initial_attempt_id . as_deref ( ) == Some ( & event. event_id )
550+ && ( event. primary_object_id == primary_object_id
551+ || event. initial_attempt_id . as_deref ( ) == Some ( initial_attempt_id) )
544552 } )
545553 . cloned ( )
546554 . collect :: < Vec < _ > > ( ) ;
@@ -663,11 +671,12 @@ impl EventInterface for MockDb {
663671 Ok ( domain_events)
664672 }
665673
666- async fn list_initial_events_by_profile_id_primary_object_id (
674+ async fn list_initial_events_by_profile_id_primary_object_or_initial_attempt_id (
667675 & self ,
668676 state : & KeyManagerState ,
669677 profile_id : & common_utils:: id_type:: ProfileId ,
670678 primary_object_id : & str ,
679+ initial_attempt_id : & str ,
671680 merchant_key_store : & domain:: MerchantKeyStore ,
672681 ) -> CustomResult < Vec < domain:: Event > , errors:: StorageError > {
673682 let locked_events = self . events . lock ( ) . await ;
@@ -676,7 +685,8 @@ impl EventInterface for MockDb {
676685 . filter ( |event| {
677686 event. business_profile_id == Some ( profile_id. to_owned ( ) )
678687 && event. initial_attempt_id . as_ref ( ) == Some ( & event. event_id )
679- && event. primary_object_id == primary_object_id
688+ && ( event. primary_object_id == primary_object_id
689+ || event. initial_attempt_id . as_deref ( ) == Some ( initial_attempt_id) )
680690 } )
681691 . cloned ( )
682692 . collect :: < Vec < _ > > ( ) ;
@@ -1310,6 +1320,7 @@ mod tests {
13101320 let event_type = enums:: EventType :: PaymentSucceeded ;
13111321 let event_class = enums:: EventClass :: Payments ;
13121322 let primary_object_id = Arc :: new ( "concurrent_payment_id" . to_string ( ) ) ;
1323+ let initial_attempt_id = Arc :: new ( "initial_attempt_id" . to_string ( ) ) ;
13131324 let primary_object_type = enums:: EventObjectType :: PaymentDetails ;
13141325 let payment_id = common_utils:: id_type:: PaymentId :: try_from ( std:: borrow:: Cow :: Borrowed (
13151326 "pay_mbabizu24mvu3mela5njyhpit10" ,
@@ -1462,10 +1473,11 @@ mod tests {
14621473 // Collect all initial-attempt events for this payment
14631474 let events = state
14641475 . store
1465- . list_initial_events_by_merchant_id_primary_object_id (
1476+ . list_initial_events_by_merchant_id_primary_object_or_initial_attempt_id (
14661477 key_manager_state,
14671478 & business_profile. merchant_id ,
14681479 & primary_object_id. clone ( ) ,
1480+ & initial_attempt_id. clone ( ) ,
14691481 merchant_context. get_merchant_key_store ( ) ,
14701482 )
14711483 . await ?;
0 commit comments