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
fix(router): correct limit for payments list by filters (#2060)
Apoorv Dixitb7d6d31504c1
diff --git a/crates/api_models/src/payments.rs b/crates/api_models/src/payments.rsindex 062d06c177..7d0f24ebbb 100644--- a/crates/api_models/src/payments.rs+++ b/crates/api_models/src/payments.rs@@ -1991,8 +1991,9 @@ pub struct PaymentListResponseV2 {pub struct PaymentListFilterConstraints {/// The identifier for paymentpub payment_id: Option<String>,- /// The limit on the number of objects. The max limit is 20- pub limit: Option<u32>,+ /// The limit on the number of objects. The default limit is 10 and max limit is 20+ #[serde(default = "default_limit")]+ pub limit: u32,/// The starting point within a list of objectspub offset: Option<u32>,/// The time range for which objects are needed. TimeRange has two fields start_time and end_time from which objects can be filtered as per required scenarios (created_at, time less than, greater than etc).diff --git a/crates/common_utils/src/consts.rs b/crates/common_utils/src/consts.rsindex 947b880e11..5797e7b487 100644--- a/crates/common_utils/src/consts.rs+++ b/crates/common_utils/src/consts.rs@@ -18,3 +18,8 @@ pub const TOKEN_TTL: i64 = 900;pub static FRM_CONFIGS_EG: &str = r#"[{"gateway":"stripe","payment_methods":[{"payment_method":"card","payment_method_types":[{"payment_method_type":"credit","card_networks":["Visa"],"flow":"pre","action":"cancel_txn"},{"payment_method_type":"debit","card_networks":["Visa"],"flow":"pre"}]}]}]"#;++/// Maximum limit for payments list get api+pub const PAYMENTS_LIST_MAX_LIMIT_V1: u32 = 100;+/// Maximum limit for payments list post api with filters+pub const PAYMENTS_LIST_MAX_LIMIT_V2: u32 = 20;diff --git a/crates/data_models/src/payments/payment_intent.rs b/crates/data_models/src/payments/payment_intent.rsindex c5e6ed9b0b..74d23695ed 100644--- a/crates/data_models/src/payments/payment_intent.rs+++ b/crates/data_models/src/payments/payment_intent.rs@@ -1,10 +1,12 @@use common_enums as storage_enums;-use common_utils::pii;+use common_utils::{+ consts::{PAYMENTS_LIST_MAX_LIMIT_V1, PAYMENTS_LIST_MAX_LIMIT_V2},+ pii,+};use serde::{Deserialize, Serialize};use time::PrimitiveDateTime;use crate::{errors, MerchantStorageScheme};-const MAX_LIMIT: u32 = 100;#[async_trait::async_trait]pub trait PaymentIntentInterface {async fn update_payment_intent(@@ -388,7 +390,7 @@ impl From<api_models::payments::PaymentListConstraints> for PaymentIntentFetchCocustomer_id: value.customer_id,starting_after_id: value.starting_after,ending_before_id: value.ending_before,- limit: Some(std::cmp::min(value.limit, MAX_LIMIT)),+ limit: Some(std::cmp::min(value.limit, PAYMENTS_LIST_MAX_LIMIT_V1)),}}}@@ -427,7 +429,7 @@ impl From<api_models::payments::PaymentListFilterConstraints> for PaymentIntentFcustomer_id: None,starting_after_id: None,ending_before_id: None,- limit: value.limit,+ limit: Some(std::cmp::min(value.limit, PAYMENTS_LIST_MAX_LIMIT_V2)),}}}diff --git a/crates/router/src/core/payments.rs b/crates/router/src/core/payments.rsindex e7784661d6..8783f1f9d3 100644--- a/crates/router/src/core/payments.rs+++ b/crates/router/src/core/payments.rs@@ -42,8 +42,6 @@ use crate::{utils::{add_connector_http_status_code_metrics, Encode, OptionExt, ValueExt},};-#[cfg(feature = "olap")]-const PAYMENTS_LIST_MAX_LIMIT: u32 = 20;#[instrument(skip_all, fields(payment_id, merchant_id))]pub async fn payments_operation_core<F, Req, Op, FData>(state: &AppState,@@ -1326,9 +1324,9 @@ pub async fn apply_filters_on_payments(use crate::types::transformers::ForeignFrom;- let limit = &constraints.limit.unwrap_or(PAYMENTS_LIST_MAX_LIMIT);+ let limit = &constraints.limit;- helpers::validate_payment_list_request_for_joins(*limit, PAYMENTS_LIST_MAX_LIMIT)?;+ helpers::validate_payment_list_request_for_joins(*limit)?;let list: Vec<(storage::PaymentIntent, storage::PaymentAttempt)> = db.get_filtered_payment_intents_attempt(&merchant.merchant_id,diff --git a/crates/router/src/core/payments/helpers.rs b/crates/router/src/core/payments/helpers.rsindex 99a04b80b8..dda14c12ee 100644--- a/crates/router/src/core/payments/helpers.rs+++ b/crates/router/src/core/payments/helpers.rs@@ -1683,21 +1683,33 @@ pub(super) async fn filter_by_constraints(pub(super) fn validate_payment_list_request(req: &api::PaymentListConstraints,) -> CustomResult<(), errors::ApiErrorResponse> {- utils::when(req.limit > 100 || req.limit < 1, || {- Err(errors::ApiErrorResponse::InvalidRequestData {- message: "limit should be in between 1 and 100".to_string(),- })- })?;+ use common_utils::consts::PAYMENTS_LIST_MAX_LIMIT_V1;++ utils::when(+ req.limit > PAYMENTS_LIST_MAX_LIMIT_V1 || req.limit < 1,+ || {+ Err(errors::ApiErrorResponse::InvalidRequestData {+ message: format!(+ "limit should be in between 1 and {}",+ PAYMENTS_LIST_MAX_LIMIT_V1+ ),+ })+ },+ )?;Ok(())}#[cfg(feature = "olap")]pub(super) fn validate_payment_list_request_for_joins(limit: u32,- max_limit: u32,) -> CustomResult<(), errors::ApiErrorResponse> {- utils::when(limit > max_limit || limit < 1, || {+ use common_utils::consts::PAYMENTS_LIST_MAX_LIMIT_V2;++ utils::when(!(1..=PAYMENTS_LIST_MAX_LIMIT_V2).contains(&limit), || {Err(errors::ApiErrorResponse::InvalidRequestData {- message: format!("limit should be in between 1 and {}", max_limit),+ message: format!(+ "limit should be in between 1 and {}",+ PAYMENTS_LIST_MAX_LIMIT_V2+ ),})})?;Ok(())