Skip to content

Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation

fix(router): desc payment list for pagination (#1556)

P K Navin Shrinivasf77fdb7a6ed3
diff --git a/.github/workflows/validate-openapi-spec.yml b/.github/workflows/validate-openapi-spec.yml
index 75ebe228c8..72b76157f1 100644
--- a/.github/workflows/validate-openapi-spec.yml
+++ b/.github/workflows/validate-openapi-spec.yml
@@ -22,6 +22,7 @@ jobs:
with:
# Checkout pull request branch instead of merge commit
ref: ${{ github.event.pull_request.head.ref }}
+ repository: ${{ github.event.pull_request.head.repo.full_name }}
- name: Checkout merge group HEAD commit
if: ${{ github.event_name == 'merge_group' }}
diff --git a/crates/router/src/core/payments.rs b/crates/router/src/core/payments.rs
index 384a223038..c9bc3d0a64 100644
--- a/crates/router/src/core/payments.rs
+++ b/crates/router/src/core/payments.rs
@@ -1204,8 +1204,6 @@ pub async fn list_payments(
merchant: domain::MerchantAccount,
constraints: api::PaymentListConstraints,
) -> RouterResponse<api::PaymentListResponse> {
- use futures::stream::StreamExt;
-
use crate::types::transformers::ForeignFrom;
helpers::validate_payment_list_request(&constraints)?;
@@ -1215,9 +1213,9 @@ pub async fn list_payments(
.await
.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?;
- let pi = futures::stream::iter(payment_intents)
- .filter_map(|pi| async {
- let pa = db
+ let collected_futures = payment_intents.into_iter().map(|pi| {
+ async {
+ match db
.find_payment_attempt_by_payment_id_merchant_id_attempt_id(
&pi.payment_id,
merchant_id,
@@ -1226,13 +1224,38 @@ pub async fn list_payments(
storage_enums::MerchantStorageScheme::PostgresOnly,
)
.await
- .ok()?;
- Some((pi, pa))
- })
- .collect::<Vec<(storage::PaymentIntent, storage::PaymentAttempt)>>()
- .await;
+ {
+ Ok(pa) => Some(Ok((pi, pa))),
+ Err(e) => {
+ if e.current_context().is_db_not_found() {
+ logger::warn!(
+ "payment_attempts missing for payment_id : {} | error : {}",
+ pi.payment_id,
+ e
+ );
+ return None;
+ }
+ Some(Err(e))
+ }
+ }
+ }
+ });
- let data: Vec<api::PaymentsResponse> = pi.into_iter().map(ForeignFrom::foreign_from).collect();
+ //If any of the response are Err, we will get Result<Err(_)>
+ let pi_pa_tuple_vec: Result<Vec<(storage::PaymentIntent, storage::PaymentAttempt)>, _> =
+ join_all(collected_futures)
+ .await
+ .into_iter()
+ .flatten() //Will ignore `None`, will only flatten 1 level
+ .collect::<Result<Vec<(storage::PaymentIntent, storage::PaymentAttempt)>, _>>();
+ //Will collect responses in same order async, leading to sorted responses
+
+ //Converting Intent-Attempt array to Response if no error
+ let data: Vec<api::PaymentsResponse> = pi_pa_tuple_vec
+ .change_context(errors::ApiErrorResponse::InternalServerError)?
+ .into_iter()
+ .map(ForeignFrom::foreign_from)
+ .collect();
Ok(services::ApplicationResponse::Json(
api::PaymentListResponse {
diff --git a/crates/router/src/types/storage/payment_intent.rs b/crates/router/src/types/storage/payment_intent.rs
index 89bcafa08e..b4ec4fe2b5 100644
--- a/crates/router/src/types/storage/payment_intent.rs
+++ b/crates/router/src/types/storage/payment_intent.rs
@@ -40,7 +40,7 @@ impl PaymentIntentDbExt for PaymentIntent {
// when https://github.com/rust-lang/rust/issues/52662 becomes stable
let mut filter = <Self as HasTable>::table()
.filter(dsl::merchant_id.eq(merchant_id.to_owned()))
- .order(dsl::modified_at.desc())
+ .order(dsl::created_at.desc())
.into_boxed();
if let Some(customer_id) = customer_id {