mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-29 17:19:15 +08:00
fix(payment): fix max limit on payment intents list (#2014)
Co-authored-by: Apoorv Dixit <apoorv.dixit@juspay.in>
This commit is contained in:
@ -1923,9 +1923,9 @@ pub struct PaymentListConstraints {
|
|||||||
pub ending_before: Option<String>,
|
pub ending_before: Option<String>,
|
||||||
|
|
||||||
/// limit on the number of objects to return
|
/// limit on the number of objects to return
|
||||||
#[schema(default = 10)]
|
#[schema(default = 10, maximum = 100)]
|
||||||
#[serde(default = "default_limit")]
|
#[serde(default = "default_limit")]
|
||||||
pub limit: i64,
|
pub limit: u32,
|
||||||
|
|
||||||
/// The time at which payment is created
|
/// The time at which payment is created
|
||||||
#[schema(example = "2022-09-10T10:11:12Z")]
|
#[schema(example = "2022-09-10T10:11:12Z")]
|
||||||
@ -2037,7 +2037,7 @@ pub struct VerifyResponse {
|
|||||||
pub error_message: Option<String>,
|
pub error_message: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn default_limit() -> i64 {
|
fn default_limit() -> u32 {
|
||||||
10
|
10
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -4,7 +4,8 @@ use serde::{Deserialize, Serialize};
|
|||||||
use time::PrimitiveDateTime;
|
use time::PrimitiveDateTime;
|
||||||
|
|
||||||
use crate::{errors, MerchantStorageScheme};
|
use crate::{errors, MerchantStorageScheme};
|
||||||
|
const QUERY_LIMIT: u32 = 20;
|
||||||
|
const MAX_LIMIT: u32 = 100;
|
||||||
#[async_trait::async_trait]
|
#[async_trait::async_trait]
|
||||||
pub trait PaymentIntentInterface {
|
pub trait PaymentIntentInterface {
|
||||||
async fn update_payment_intent(
|
async fn update_payment_intent(
|
||||||
@ -353,7 +354,7 @@ pub enum PaymentIntentFetchConstraints {
|
|||||||
payment_intent_id: String,
|
payment_intent_id: String,
|
||||||
},
|
},
|
||||||
List {
|
List {
|
||||||
offset: Option<u32>,
|
offset: u32,
|
||||||
starting_at: Option<PrimitiveDateTime>,
|
starting_at: Option<PrimitiveDateTime>,
|
||||||
ending_at: Option<PrimitiveDateTime>,
|
ending_at: Option<PrimitiveDateTime>,
|
||||||
connector: Option<Vec<api_models::enums::Connector>>,
|
connector: Option<Vec<api_models::enums::Connector>>,
|
||||||
@ -370,7 +371,7 @@ pub enum PaymentIntentFetchConstraints {
|
|||||||
impl From<api_models::payments::PaymentListConstraints> for PaymentIntentFetchConstraints {
|
impl From<api_models::payments::PaymentListConstraints> for PaymentIntentFetchConstraints {
|
||||||
fn from(value: api_models::payments::PaymentListConstraints) -> Self {
|
fn from(value: api_models::payments::PaymentListConstraints) -> Self {
|
||||||
Self::List {
|
Self::List {
|
||||||
offset: None,
|
offset: 0,
|
||||||
starting_at: value.created_gte.or(value.created_gt).or(value.created),
|
starting_at: value.created_gte.or(value.created_gt).or(value.created),
|
||||||
ending_at: value.created_lte.or(value.created_lt).or(value.created),
|
ending_at: value.created_lte.or(value.created_lt).or(value.created),
|
||||||
connector: None,
|
connector: None,
|
||||||
@ -380,7 +381,7 @@ impl From<api_models::payments::PaymentListConstraints> for PaymentIntentFetchCo
|
|||||||
customer_id: value.customer_id,
|
customer_id: value.customer_id,
|
||||||
starting_after_id: value.starting_after,
|
starting_after_id: value.starting_after,
|
||||||
ending_before_id: value.ending_before,
|
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 {
|
impl From<api_models::payments::TimeRange> for PaymentIntentFetchConstraints {
|
||||||
fn from(value: api_models::payments::TimeRange) -> Self {
|
fn from(value: api_models::payments::TimeRange) -> Self {
|
||||||
Self::List {
|
Self::List {
|
||||||
offset: None,
|
offset: 0,
|
||||||
starting_at: Some(value.start_time),
|
starting_at: Some(value.start_time),
|
||||||
ending_at: value.end_time,
|
ending_at: value.end_time,
|
||||||
connector: None,
|
connector: None,
|
||||||
@ -409,7 +410,7 @@ impl From<api_models::payments::PaymentListFilterConstraints> for PaymentIntentF
|
|||||||
Self::Single { payment_intent_id }
|
Self::Single { payment_intent_id }
|
||||||
} else {
|
} else {
|
||||||
Self::List {
|
Self::List {
|
||||||
offset: value.offset,
|
offset: value.offset.unwrap_or_default(),
|
||||||
starting_at: value.time_range.map(|t| t.start_time),
|
starting_at: value.time_range.map(|t| t.start_time),
|
||||||
ending_at: value.time_range.and_then(|t| t.end_time),
|
ending_at: value.time_range.and_then(|t| t.end_time),
|
||||||
connector: value.connector,
|
connector: value.connector,
|
||||||
@ -419,7 +420,7 @@ impl From<api_models::payments::PaymentListFilterConstraints> for PaymentIntentF
|
|||||||
customer_id: None,
|
customer_id: None,
|
||||||
starting_after_id: None,
|
starting_after_id: None,
|
||||||
ending_before_id: None,
|
ending_before_id: None,
|
||||||
limit: None,
|
limit: Some(QUERY_LIMIT),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -586,7 +586,7 @@ pub struct StripePaymentListConstraints {
|
|||||||
pub starting_after: Option<String>,
|
pub starting_after: Option<String>,
|
||||||
pub ending_before: Option<String>,
|
pub ending_before: Option<String>,
|
||||||
#[serde(default = "default_limit")]
|
#[serde(default = "default_limit")]
|
||||||
pub limit: i64,
|
pub limit: u32,
|
||||||
pub created: Option<i64>,
|
pub created: Option<i64>,
|
||||||
#[serde(rename = "created[lt]")]
|
#[serde(rename = "created[lt]")]
|
||||||
pub created_lt: Option<i64>,
|
pub created_lt: Option<i64>,
|
||||||
@ -598,7 +598,7 @@ pub struct StripePaymentListConstraints {
|
|||||||
pub created_gte: Option<i64>,
|
pub created_gte: Option<i64>,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn default_limit() -> i64 {
|
fn default_limit() -> u32 {
|
||||||
10
|
10
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -511,7 +511,7 @@ pub struct StripePaymentListConstraints {
|
|||||||
pub starting_after: Option<String>,
|
pub starting_after: Option<String>,
|
||||||
pub ending_before: Option<String>,
|
pub ending_before: Option<String>,
|
||||||
#[serde(default = "default_limit")]
|
#[serde(default = "default_limit")]
|
||||||
pub limit: i64,
|
pub limit: u32,
|
||||||
pub created: Option<i64>,
|
pub created: Option<i64>,
|
||||||
#[serde(rename = "created[lt]")]
|
#[serde(rename = "created[lt]")]
|
||||||
pub created_lt: Option<i64>,
|
pub created_lt: Option<i64>,
|
||||||
@ -523,7 +523,7 @@ pub struct StripePaymentListConstraints {
|
|||||||
pub created_gte: Option<i64>,
|
pub created_gte: Option<i64>,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn default_limit() -> i64 {
|
fn default_limit() -> u32 {
|
||||||
10
|
10
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -39,9 +39,6 @@ use crate::{
|
|||||||
DataModelExt, DatabaseStore, KVRouterStore,
|
DataModelExt, DatabaseStore, KVRouterStore,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[cfg(feature = "olap")]
|
|
||||||
const QUERY_LIMIT: u32 = 20;
|
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
#[async_trait::async_trait]
|
||||||
impl<T: DatabaseStore> PaymentIntentInterface for KVRouterStore<T> {
|
impl<T: DatabaseStore> PaymentIntentInterface for KVRouterStore<T> {
|
||||||
async fn insert_payment_intent(
|
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()));
|
query = query.filter(pi_dsl::payment_id.eq(payment_intent_id.to_owned()));
|
||||||
}
|
}
|
||||||
PaymentIntentFetchConstraints::List {
|
PaymentIntentFetchConstraints::List {
|
||||||
offset: _,
|
offset,
|
||||||
starting_at,
|
starting_at,
|
||||||
ending_at,
|
ending_at,
|
||||||
connector: _,
|
connector: _,
|
||||||
@ -351,7 +348,9 @@ impl<T: DatabaseStore> PaymentIntentInterface for crate::RouterStore<T> {
|
|||||||
ending_before_id,
|
ending_before_id,
|
||||||
limit,
|
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 {
|
if let Some(customer_id) = customer_id {
|
||||||
query = query.filter(pi_dsl::customer_id.eq(customer_id.clone()));
|
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,
|
(None, None) => query,
|
||||||
};
|
};
|
||||||
|
query = query.offset((*offset).into());
|
||||||
|
|
||||||
query = match currency {
|
query = match currency {
|
||||||
Some(currency) => query.filter(pi_dsl::currency.eq_any(currency.clone())),
|
Some(currency) => query.filter(pi_dsl::currency.eq_any(currency.clone())),
|
||||||
None => query,
|
None => query,
|
||||||
@ -470,7 +471,9 @@ impl<T: DatabaseStore> PaymentIntentInterface for crate::RouterStore<T> {
|
|||||||
ending_before_id,
|
ending_before_id,
|
||||||
limit,
|
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 {
|
if let Some(customer_id) = customer_id {
|
||||||
query = query.filter(pi_dsl::customer_id.eq(customer_id.clone()));
|
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,
|
(None, None) => query,
|
||||||
};
|
};
|
||||||
|
|
||||||
query = match offset {
|
query = query.offset((*offset).into());
|
||||||
Some(offset) => query.offset((*offset).into()),
|
|
||||||
None => query,
|
|
||||||
};
|
|
||||||
|
|
||||||
query = match currency {
|
query = match currency {
|
||||||
Some(currency) => query.filter(pi_dsl::currency.eq_any(currency.clone())),
|
Some(currency) => query.filter(pi_dsl::currency.eq_any(currency.clone())),
|
||||||
|
|||||||
@ -7661,9 +7661,11 @@
|
|||||||
},
|
},
|
||||||
"limit": {
|
"limit": {
|
||||||
"type": "integer",
|
"type": "integer",
|
||||||
"format": "int64",
|
"format": "int32",
|
||||||
"description": "limit on the number of objects to return",
|
"description": "limit on the number of objects to return",
|
||||||
"default": 10
|
"default": 10,
|
||||||
|
"maximum": 100.0,
|
||||||
|
"minimum": 0.0
|
||||||
},
|
},
|
||||||
"created": {
|
"created": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
|
|||||||
Reference in New Issue
Block a user