1
1
use std:: collections:: HashMap ;
2
2
3
3
use async_trait:: async_trait;
4
+ use data_models:: payments:: payment_attempt:: PaymentAttempt ;
4
5
use error_stack:: ResultExt ;
5
6
use futures:: FutureExt ;
6
7
use router_derive;
7
8
use router_env:: { instrument, tracing} ;
9
+ use storage_impl:: DataModelExt ;
8
10
use tracing_futures:: Instrument ;
9
11
10
12
use super :: { Operation , PostUpdateTracker } ;
@@ -589,6 +591,17 @@ async fn payment_response_update_tracker<F: Clone, T: types::Capturable>(
589
591
let m_db = state. clone ( ) . store ;
590
592
let m_payment_attempt_update = payment_attempt_update. clone ( ) ;
591
593
let m_payment_attempt = payment_attempt. clone ( ) ;
594
+
595
+ let payment_attempt = payment_attempt_update
596
+ . map ( |payment_attempt_update| {
597
+ PaymentAttempt :: from_storage_model (
598
+ payment_attempt_update
599
+ . to_storage_model ( )
600
+ . apply_changeset ( payment_attempt. clone ( ) . to_storage_model ( ) ) ,
601
+ )
602
+ } )
603
+ . unwrap_or_else ( || payment_attempt) ;
604
+
592
605
let payment_attempt_fut = tokio:: spawn (
593
606
async move {
594
607
Box :: pin ( async move {
@@ -602,7 +615,7 @@ async fn payment_response_update_tracker<F: Clone, T: types::Capturable>(
602
615
)
603
616
. await
604
617
. to_not_found_response ( errors:: ApiErrorResponse :: PaymentNotFound ) ?,
605
- None => payment_attempt ,
618
+ None => m_payment_attempt ,
606
619
} ,
607
620
)
608
621
} )
@@ -614,6 +627,13 @@ async fn payment_response_update_tracker<F: Clone, T: types::Capturable>(
614
627
let m_db = state. clone ( ) . store ;
615
628
let m_connector_response_update = connector_response_update. clone ( ) ;
616
629
let m_connector_response = connector_response. clone ( ) ;
630
+
631
+ let connector_response = connector_response_update
632
+ . map ( |connector_response_update| {
633
+ connector_response_update. apply_changeset ( connector_response. clone ( ) )
634
+ } )
635
+ . unwrap_or_else ( || connector_response) ;
636
+
617
637
let connector_response_fut = tokio:: spawn (
618
638
async move {
619
639
Box :: pin ( async move {
@@ -627,7 +647,7 @@ async fn payment_response_update_tracker<F: Clone, T: types::Capturable>(
627
647
)
628
648
. await
629
649
. to_not_found_response ( errors:: ApiErrorResponse :: PaymentNotFound ) ?,
630
- None => connector_response ,
650
+ None => m_connector_response ,
631
651
} ,
632
652
)
633
653
} )
@@ -636,10 +656,6 @@ async fn payment_response_update_tracker<F: Clone, T: types::Capturable>(
636
656
. in_current_span ( ) ,
637
657
) ;
638
658
639
- let ( payment_attempt, connector_response) = futures:: try_join!(
640
- utils:: flatten_join_error( payment_attempt_fut) ,
641
- utils:: flatten_join_error( connector_response_fut)
642
- ) ?;
643
659
payment_data. payment_attempt = payment_attempt;
644
660
payment_data. connector_response = connector_response;
645
661
@@ -701,12 +717,14 @@ async fn payment_response_update_tracker<F: Clone, T: types::Capturable>(
701
717
. in_current_span ( ) ,
702
718
) ;
703
719
704
- let ( payment_intent, _) = futures:: try_join!(
720
+ let ( payment_intent, _, _ , _ ) = futures:: try_join!(
705
721
utils:: flatten_join_error( payment_intent_fut) ,
706
- utils:: flatten_join_error( mandate_update_fut)
722
+ utils:: flatten_join_error( mandate_update_fut) ,
723
+ utils:: flatten_join_error( payment_attempt_fut) ,
724
+ utils:: flatten_join_error( connector_response_fut)
707
725
) ?;
708
- payment_data. payment_intent = payment_intent;
709
726
727
+ payment_data. payment_intent = payment_intent;
710
728
Ok ( payment_data)
711
729
}
712
730
0 commit comments