Skip to content

Commit 35173a1

Browse files
akshay-97akshay.sgithub-actions[bot]
authored
refactor: #3059 group db update calls (#2788)
Co-authored-by: akshay.s <[email protected]> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent 8af150e commit 35173a1

File tree

1 file changed

+27
-9
lines changed

1 file changed

+27
-9
lines changed

crates/router/src/core/payments/operations/payment_response.rs

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
use std::collections::HashMap;
22

33
use async_trait::async_trait;
4+
use data_models::payments::payment_attempt::PaymentAttempt;
45
use error_stack::ResultExt;
56
use futures::FutureExt;
67
use router_derive;
78
use router_env::{instrument, tracing};
9+
use storage_impl::DataModelExt;
810
use tracing_futures::Instrument;
911

1012
use super::{Operation, PostUpdateTracker};
@@ -589,6 +591,17 @@ async fn payment_response_update_tracker<F: Clone, T: types::Capturable>(
589591
let m_db = state.clone().store;
590592
let m_payment_attempt_update = payment_attempt_update.clone();
591593
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+
592605
let payment_attempt_fut = tokio::spawn(
593606
async move {
594607
Box::pin(async move {
@@ -602,7 +615,7 @@ async fn payment_response_update_tracker<F: Clone, T: types::Capturable>(
602615
)
603616
.await
604617
.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?,
605-
None => payment_attempt,
618+
None => m_payment_attempt,
606619
},
607620
)
608621
})
@@ -614,6 +627,13 @@ async fn payment_response_update_tracker<F: Clone, T: types::Capturable>(
614627
let m_db = state.clone().store;
615628
let m_connector_response_update = connector_response_update.clone();
616629
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+
617637
let connector_response_fut = tokio::spawn(
618638
async move {
619639
Box::pin(async move {
@@ -627,7 +647,7 @@ async fn payment_response_update_tracker<F: Clone, T: types::Capturable>(
627647
)
628648
.await
629649
.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?,
630-
None => connector_response,
650+
None => m_connector_response,
631651
},
632652
)
633653
})
@@ -636,10 +656,6 @@ async fn payment_response_update_tracker<F: Clone, T: types::Capturable>(
636656
.in_current_span(),
637657
);
638658

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-
)?;
643659
payment_data.payment_attempt = payment_attempt;
644660
payment_data.connector_response = connector_response;
645661

@@ -701,12 +717,14 @@ async fn payment_response_update_tracker<F: Clone, T: types::Capturable>(
701717
.in_current_span(),
702718
);
703719

704-
let (payment_intent, _) = futures::try_join!(
720+
let (payment_intent, _, _, _) = futures::try_join!(
705721
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)
707725
)?;
708-
payment_data.payment_intent = payment_intent;
709726

727+
payment_data.payment_intent = payment_intent;
710728
Ok(payment_data)
711729
}
712730

0 commit comments

Comments
 (0)