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(payment): fix max limit on payment intents list (#2014)
Sampras Lopesa8889530043e
diff --git a/crates/api_models/src/payments.rs b/crates/api_models/src/payments.rsindex bcc274c156..c65f30150a 100644--- a/crates/api_models/src/payments.rs+++ b/crates/api_models/src/payments.rs@@ -1923,9 +1923,9 @@ pub struct PaymentListConstraints {pub ending_before: Option<String>,/// limit on the number of objects to return- #[schema(default = 10)]+ #[schema(default = 10, maximum = 100)]#[serde(default = "default_limit")]- pub limit: i64,+ pub limit: u32,/// The time at which payment is created#[schema(example = "2022-09-10T10:11:12Z")]@@ -2037,7 +2037,7 @@ pub struct VerifyResponse {pub error_message: Option<String>,}-fn default_limit() -> i64 {+fn default_limit() -> u32 {10}diff --git a/crates/data_models/src/payments/payment_intent.rs b/crates/data_models/src/payments/payment_intent.rsindex 824049837e..a2110900ef 100644--- a/crates/data_models/src/payments/payment_intent.rs+++ b/crates/data_models/src/payments/payment_intent.rs@@ -4,7 +4,8 @@ use serde::{Deserialize, Serialize};use time::PrimitiveDateTime;use crate::{errors, MerchantStorageScheme};-+const QUERY_LIMIT: u32 = 20;+const MAX_LIMIT: u32 = 100;#[async_trait::async_trait]pub trait PaymentIntentInterface {async fn update_payment_intent(@@ -353,7 +354,7 @@ pub enum PaymentIntentFetchConstraints {payment_intent_id: String,},List {- offset: Option<u32>,+ offset: u32,starting_at: Option<PrimitiveDateTime>,ending_at: Option<PrimitiveDateTime>,connector: Option<Vec<api_models::enums::Connector>>,@@ -370,7 +371,7 @@ pub enum PaymentIntentFetchConstraints {impl From<api_models::payments::PaymentListConstraints> for PaymentIntentFetchConstraints {fn from(value: api_models::payments::PaymentListConstraints) -> Self {Self::List {- offset: None,+ offset: 0,starting_at: value.created_gte.or(value.created_gt).or(value.created),ending_at: value.created_lte.or(value.created_lt).or(value.created),connector: None,@@ -380,7 +381,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: None,+ limit: Some(std::cmp::min(value.limit, MAX_LIMIT)),}}}@@ -388,7 +389,7 @@ impl From<api_models::payments::PaymentListConstraints> for PaymentIntentFetchCoimpl From<api_models::payments::TimeRange> for PaymentIntentFetchConstraints {fn from(value: api_models::payments::TimeRange) -> Self {Self::List {- offset: None,+ offset: 0,starting_at: Some(value.start_time),ending_at: value.end_time,connector: None,@@ -409,7 +410,7 @@ impl From<api_models::payments::PaymentListFilterConstraints> for PaymentIntentFSelf::Single { payment_intent_id }} else {Self::List {- offset: value.offset,+ offset: value.offset.unwrap_or_default(),starting_at: value.time_range.map(|t| t.start_time),ending_at: value.time_range.and_then(|t| t.end_time),connector: value.connector,@@ -419,7 +420,7 @@ impl From<api_models::payments::PaymentListFilterConstraints> for PaymentIntentFcustomer_id: None,starting_after_id: None,ending_before_id: None,- limit: None,+ limit: Some(QUERY_LIMIT),}}}diff --git a/crates/router/src/compatibility/stripe/payment_intents/types.rs b/crates/router/src/compatibility/stripe/payment_intents/types.rsindex 8bc6632833..51ccf61377 100644--- a/crates/router/src/compatibility/stripe/payment_intents/types.rs+++ b/crates/router/src/compatibility/stripe/payment_intents/types.rs@@ -586,7 +586,7 @@ pub struct StripePaymentListConstraints {pub starting_after: Option<String>,pub ending_before: Option<String>,#[serde(default = "default_limit")]- pub limit: i64,+ pub limit: u32,pub created: Option<i64>,#[serde(rename = "created[lt]")]pub created_lt: Option<i64>,@@ -598,7 +598,7 @@ pub struct StripePaymentListConstraints {pub created_gte: Option<i64>,}-fn default_limit() -> i64 {+fn default_limit() -> u32 {10}diff --git a/crates/router/src/compatibility/stripe/setup_intents/types.rs b/crates/router/src/compatibility/stripe/setup_intents/types.rsindex 896183da0d..32caf4308c 100644--- a/crates/router/src/compatibility/stripe/setup_intents/types.rs+++ b/crates/router/src/compatibility/stripe/setup_intents/types.rs@@ -511,7 +511,7 @@ pub struct StripePaymentListConstraints {pub starting_after: Option<String>,pub ending_before: Option<String>,#[serde(default = "default_limit")]- pub limit: i64,+ pub limit: u32,pub created: Option<i64>,#[serde(rename = "created[lt]")]pub created_lt: Option<i64>,@@ -523,7 +523,7 @@ pub struct StripePaymentListConstraints {pub created_gte: Option<i64>,}-fn default_limit() -> i64 {+fn default_limit() -> u32 {10}diff --git a/crates/storage_impl/src/payments/payment_intent.rs b/crates/storage_impl/src/payments/payment_intent.rsindex 72437afd29..9b5ce8ee58 100644--- a/crates/storage_impl/src/payments/payment_intent.rs+++ b/crates/storage_impl/src/payments/payment_intent.rs@@ -39,9 +39,6 @@ use crate::{DataModelExt, DatabaseStore, KVRouterStore,};-#[cfg(feature = "olap")]-const QUERY_LIMIT: u32 = 20;-#[async_trait::async_trait]impl<T: DatabaseStore> PaymentIntentInterface for KVRouterStore<T> {async fn insert_payment_intent(@@ -339,7 +336,7 @@ impl<T: DatabaseStore> PaymentIntentInterface for crate::RouterStore<T> {query = query.filter(pi_dsl::payment_id.eq(payment_intent_id.to_owned()));}PaymentIntentFetchConstraints::List {- offset: _,+ offset,starting_at,ending_at,connector: _,@@ -351,7 +348,9 @@ impl<T: DatabaseStore> PaymentIntentInterface for crate::RouterStore<T> {ending_before_id,limit,} => {- query = query.limit(limit.unwrap_or(QUERY_LIMIT).into());+ if let Some(limit) = limit {+ query = query.limit((*limit).into());+ };if let Some(customer_id) = customer_id {query = query.filter(pi_dsl::customer_id.eq(customer_id.clone()));@@ -390,6 +389,8 @@ impl<T: DatabaseStore> PaymentIntentInterface for crate::RouterStore<T> {}(None, None) => query,};+ query = query.offset((*offset).into());+query = match currency {Some(currency) => query.filter(pi_dsl::currency.eq_any(currency.clone())),None => query,@@ -470,7 +471,9 @@ impl<T: DatabaseStore> PaymentIntentInterface for crate::RouterStore<T> {ending_before_id,limit,} => {- query = query.limit(limit.unwrap_or(QUERY_LIMIT).into());+ if let Some(limit) = limit {+ query = query.limit((*limit).into());+ }if let Some(customer_id) = customer_id {query = query.filter(pi_dsl::customer_id.eq(customer_id.clone()));@@ -510,10 +513,7 @@ impl<T: DatabaseStore> PaymentIntentInterface for crate::RouterStore<T> {(None, None) => query,};- query = match offset {- Some(offset) => query.offset((*offset).into()),- None => query,- };+ query = query.offset((*offset).into());query = match currency {Some(currency) => query.filter(pi_dsl::currency.eq_any(currency.clone())),diff --git a/openapi/openapi_spec.json b/openapi/openapi_spec.jsonindex 7a7bc9d891..f9618b98b8 100644--- a/openapi/openapi_spec.json+++ b/openapi/openapi_spec.json@@ -7661,9 +7661,11 @@},"limit": {"type": "integer",- "format": "int64",+ "format": "int32","description": "limit on the number of objects to return",- "default": 10+ "default": 10,+ "maximum": 100.0,+ "minimum": 0.0},"created": {"type": "string",