fix(payment): fix max limit on payment intents list (#2014)

Co-authored-by: Apoorv Dixit <apoorv.dixit@juspay.in>
This commit is contained in:
Sampras Lopes
2023-08-25 14:44:17 +05:30
committed by GitHub
parent ac63794162
commit a888953004
6 changed files with 29 additions and 26 deletions

View File

@ -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
}

View File

@ -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 PaymentIntentFetchCo
customer_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 PaymentIntentFetchCo
impl 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 PaymentIntentF
Self::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 PaymentIntentF
customer_id: None,
starting_after_id: None,
ending_before_id: None,
limit: None,
limit: Some(QUERY_LIMIT),
}
}
}

View File

@ -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
}

View File

@ -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
}

View File

@ -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())),

View File

@ -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",