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
Rust adyenbeginner-friendlyfeaturedfinancefintechhacktoberfesthigh-performanceopen-sourceorchestrationpaymentpayment-gatewaypayment-integrationpayment-processingpaymentspayments-platformrestful-apirustsdkstripeworks-with-react
feat(payments): support sort criteria in payments list (#5389)
Apoorv Dixit043ea6d8dc9f
diff --git a/crates/api_models/src/payments.rs b/crates/api_models/src/payments.rsindex 8433ac43d0..eb04fe8300 100644--- a/crates/api_models/src/payments.rs+++ b/crates/api_models/src/payments.rs@@ -4063,6 +4063,9 @@ pub struct PaymentListFilterConstraints {pub authentication_type: Option<Vec<enums::AuthenticationType>>,/// The list of merchant connector ids to filter payments list for selected labelpub merchant_connector_id: Option<Vec<String>>,+ /// The order in which payments list should be sorted+ #[serde(default)]+ pub order: Order,}#[derive(Clone, Debug, serde::Serialize)]pub struct PaymentListFilters {@@ -4102,6 +4105,34 @@ pub struct AmountFilter {pub end_amount: Option<i64>,}+#[derive(Clone, Debug, Default, Eq, PartialEq, serde::Deserialize, serde::Serialize, ToSchema)]+pub struct Order {+ /// The field to sort, such as Amount or Created etc.+ pub on: SortOn,+ /// The order in which to sort the items, either Ascending or Descending+ pub by: SortBy,+}++#[derive(Clone, Debug, Default, Eq, PartialEq, serde::Deserialize, serde::Serialize, ToSchema)]+#[serde(rename_all = "snake_case")]+pub enum SortOn {+ /// Sort by the amount field+ Amount,+ /// Sort by the created_at field+ #[default]+ Created,+}++#[derive(Clone, Debug, Default, Eq, PartialEq, serde::Deserialize, serde::Serialize, ToSchema)]+#[serde(rename_all = "snake_case")]+pub enum SortBy {+ /// Sort in ascending order+ Asc,+ /// Sort in descending order+ #[default]+ Desc,+}+#[derive(Debug, Clone, Copy, serde::Serialize, serde::Deserialize, PartialEq, Eq, Hash, ToSchema,)]diff --git a/crates/hyperswitch_domain_models/src/payments/payment_intent.rs b/crates/hyperswitch_domain_models/src/payments/payment_intent.rsindex 3d30565679..8033ec7706 100644--- a/crates/hyperswitch_domain_models/src/payments/payment_intent.rs+++ b/crates/hyperswitch_domain_models/src/payments/payment_intent.rs@@ -737,6 +737,7 @@ pub struct PaymentIntentListParams {pub starting_after_id: Option<String>,pub ending_before_id: Option<String>,pub limit: Option<u32>,+ pub order: api_models::payments::Order,}impl From<api_models::payments::PaymentListConstraints> for PaymentIntentFetchConstraints {@@ -758,6 +759,7 @@ impl From<api_models::payments::PaymentListConstraints> for PaymentIntentFetchCostarting_after_id: value.starting_after,ending_before_id: value.ending_before,limit: Some(std::cmp::min(value.limit, PAYMENTS_LIST_MAX_LIMIT_V1)),+ order: Default::default(),}))}}@@ -781,6 +783,7 @@ impl From<api_models::payments::TimeRange> for PaymentIntentFetchConstraints {starting_after_id: None,ending_before_id: None,limit: None,+ order: Default::default(),}))}}@@ -807,6 +810,7 @@ impl From<api_models::payments::PaymentListFilterConstraints> for PaymentIntentFstarting_after_id: None,ending_before_id: None,limit: Some(std::cmp::min(value.limit, PAYMENTS_LIST_MAX_LIMIT_V2)),+ order: value.order,}))}}diff --git a/crates/storage_impl/src/payments/payment_intent.rs b/crates/storage_impl/src/payments/payment_intent.rsindex ea91732631..c8dc011b81 100644--- a/crates/storage_impl/src/payments/payment_intent.rs+++ b/crates/storage_impl/src/payments/payment_intent.rs@@ -1,5 +1,5 @@#[cfg(feature = "olap")]-use api_models::payments::AmountFilter;+use api_models::payments::{AmountFilter, Order, SortBy, SortOn};#[cfg(feature = "olap")]use async_bb8_diesel::{AsyncConnection, AsyncRunQueryDsl};#[cfg(feature = "olap")]@@ -674,7 +674,6 @@ impl<T: DatabaseStore> PaymentIntentInterface for crate::RouterStore<T> {payment_attempt_schema::table.on(pa_dsl::attempt_id.eq(pi_dsl::active_attempt_id)),).filter(pi_dsl::merchant_id.eq(merchant_id.to_owned()))- .order(pi_dsl::created_at.desc()).into_boxed();query = match constraints {@@ -682,6 +681,25 @@ impl<T: DatabaseStore> PaymentIntentInterface for crate::RouterStore<T> {query.filter(pi_dsl::payment_id.eq(payment_intent_id.to_owned()))}PaymentIntentFetchConstraints::List(params) => {+ query = match params.order {+ Order {+ on: SortOn::Amount,+ by: SortBy::Asc,+ } => query.order(pi_dsl::amount.asc()),+ Order {+ on: SortOn::Amount,+ by: SortBy::Desc,+ } => query.order(pi_dsl::amount.desc()),+ Order {+ on: SortOn::Created,+ by: SortBy::Asc,+ } => query.order(pi_dsl::created_at.asc()),+ Order {+ on: SortOn::Created,+ by: SortBy::Desc,+ } => query.order(pi_dsl::created_at.desc()),+ };+if let Some(limit) = params.limit {query = query.limit(limit.into());}