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

feat(payments): add attempt_count sorting support (#11644)

Susritha296313835813
diff --git a/api-reference/v2/openapi_spec_v2.json b/api-reference/v2/openapi_spec_v2.json
index 24426572fe..ebd1d8a455 100644
--- a/api-reference/v2/openapi_spec_v2.json
+++ b/api-reference/v2/openapi_spec_v2.json
@@ -29570,6 +29570,7 @@
"type": "string",
"enum": [
"amount",
+ "attempt_count",
"created",
"modified"
]
diff --git a/crates/analytics/src/opensearch.rs b/crates/analytics/src/opensearch.rs
index a499bd5df0..c00ebfc04e 100644
--- a/crates/analytics/src/opensearch.rs
+++ b/crates/analytics/src/opensearch.rs
@@ -882,6 +882,7 @@ impl OpenSearchQueryBuilder {
Some(order) => {
let sort_on = match order.on {
SortOn::Amount => self.get_amount_field(*index).to_string(),
+ SortOn::AttemptCount => "attempt_count".to_string(),
SortOn::Created => "@timestamp".to_string(),
SortOn::Modified => "modified_at".to_string(),
};
diff --git a/crates/api_models/src/payments.rs b/crates/api_models/src/payments.rs
index cf73daf56b..f1383ae11e 100644
--- a/crates/api_models/src/payments.rs
+++ b/crates/api_models/src/payments.rs
@@ -9120,6 +9120,8 @@ pub struct Order {
pub enum SortOn {
/// Sort by the amount field
Amount,
+ /// Sort by the attempt_count field
+ AttemptCount,
/// Sort by the created_at field
#[default]
Created,
diff --git a/crates/storage_impl/src/payments/payment_intent.rs b/crates/storage_impl/src/payments/payment_intent.rs
index 6e628be0b1..5e219d5771 100644
--- a/crates/storage_impl/src/payments/payment_intent.rs
+++ b/crates/storage_impl/src/payments/payment_intent.rs
@@ -1151,6 +1151,14 @@ impl<T: DatabaseStore> PaymentIntentInterface for crate::RouterStore<T> {
on: SortOn::Modified,
by: SortBy::Desc,
} => query.order(pi_dsl::modified_at.desc()),
+ Order {
+ on: SortOn::AttemptCount,
+ by: SortBy::Asc,
+ } => query.order(pi_dsl::attempt_count.asc()),
+ Order {
+ on: SortOn::AttemptCount,
+ by: SortBy::Desc,
+ } => query.order(pi_dsl::attempt_count.desc()),
};
if let Some(limit) = params.limit {
@@ -1376,6 +1384,14 @@ impl<T: DatabaseStore> PaymentIntentInterface for crate::RouterStore<T> {
on: SortOn::Modified,
by: SortBy::Desc,
} => query.order(pi_dsl::modified_at.desc()),
+ Order {
+ on: SortOn::AttemptCount,
+ by: SortBy::Asc,
+ } => query.order(pi_dsl::attempt_count.asc()),
+ Order {
+ on: SortOn::AttemptCount,
+ by: SortBy::Desc,
+ } => query.order(pi_dsl::attempt_count.desc()),
};
if let Some(limit) = params.limit {