mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-27 11:24:45 +08:00
feat(payments): add amount and connector id filter in list (#4354)
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
This commit is contained in:
@ -42,6 +42,7 @@ impl PaymentAttemptInterface for MockDb {
|
||||
_payment_method: Option<Vec<PaymentMethod>>,
|
||||
_payment_method_type: Option<Vec<PaymentMethodType>>,
|
||||
_authentication_type: Option<Vec<AuthenticationType>>,
|
||||
_merchanat_connector_id: Option<Vec<String>>,
|
||||
_storage_scheme: storage_enums::MerchantStorageScheme,
|
||||
) -> CustomResult<i64, StorageError> {
|
||||
Err(StorageError::MockDbError)?
|
||||
|
||||
@ -292,6 +292,7 @@ impl<T: DatabaseStore> PaymentAttemptInterface for RouterStore<T> {
|
||||
payment_method: Option<Vec<PaymentMethod>>,
|
||||
payment_method_type: Option<Vec<PaymentMethodType>>,
|
||||
authentication_type: Option<Vec<AuthenticationType>>,
|
||||
merchant_connector_id: Option<Vec<String>>,
|
||||
_storage_scheme: MerchantStorageScheme,
|
||||
) -> CustomResult<i64, errors::StorageError> {
|
||||
let conn = self
|
||||
@ -314,6 +315,7 @@ impl<T: DatabaseStore> PaymentAttemptInterface for RouterStore<T> {
|
||||
payment_method,
|
||||
payment_method_type,
|
||||
authentication_type,
|
||||
merchant_connector_id,
|
||||
)
|
||||
.await
|
||||
.map_err(|er| {
|
||||
@ -1021,6 +1023,7 @@ impl<T: DatabaseStore> PaymentAttemptInterface for KVRouterStore<T> {
|
||||
payment_method: Option<Vec<PaymentMethod>>,
|
||||
payment_method_type: Option<Vec<PaymentMethodType>>,
|
||||
authentication_type: Option<Vec<AuthenticationType>>,
|
||||
merchant_connector_id: Option<Vec<String>>,
|
||||
storage_scheme: MerchantStorageScheme,
|
||||
) -> CustomResult<i64, errors::StorageError> {
|
||||
self.router_store
|
||||
@ -1031,6 +1034,7 @@ impl<T: DatabaseStore> PaymentAttemptInterface for KVRouterStore<T> {
|
||||
payment_method,
|
||||
payment_method_type,
|
||||
authentication_type,
|
||||
merchant_connector_id,
|
||||
storage_scheme,
|
||||
)
|
||||
.await
|
||||
|
||||
@ -1,5 +1,9 @@
|
||||
#[cfg(feature = "olap")]
|
||||
use api_models::payments::AmountFilter;
|
||||
#[cfg(feature = "olap")]
|
||||
use async_bb8_diesel::{AsyncConnection, AsyncRunQueryDsl};
|
||||
#[cfg(feature = "olap")]
|
||||
use common_utils::errors::ReportSwitchExt;
|
||||
use common_utils::{date_time, ext_traits::Encode};
|
||||
#[cfg(feature = "olap")]
|
||||
use data_models::payments::payment_intent::PaymentIntentFetchConstraints;
|
||||
@ -549,8 +553,6 @@ impl<T: DatabaseStore> PaymentIntentInterface for crate::RouterStore<T> {
|
||||
constraints: &PaymentIntentFetchConstraints,
|
||||
storage_scheme: MerchantStorageScheme,
|
||||
) -> error_stack::Result<Vec<(PaymentIntent, PaymentAttempt)>, StorageError> {
|
||||
use common_utils::errors::ReportSwitchExt;
|
||||
|
||||
let conn = connection::pg_connection_read(self).await.switch()?;
|
||||
let conn = async_bb8_diesel::Connection::as_async_conn(&conn);
|
||||
let mut query = DieselPaymentIntent::table()
|
||||
@ -615,9 +617,26 @@ impl<T: DatabaseStore> PaymentIntentInterface for crate::RouterStore<T> {
|
||||
|
||||
query = query.offset(params.offset.into());
|
||||
|
||||
if let Some(currency) = ¶ms.currency {
|
||||
query = query.filter(pi_dsl::currency.eq_any(currency.clone()));
|
||||
}
|
||||
query = match params.amount_filter {
|
||||
Some(AmountFilter {
|
||||
start_amount: Some(start),
|
||||
end_amount: Some(end),
|
||||
}) => query.filter(pi_dsl::amount.between(start, end)),
|
||||
Some(AmountFilter {
|
||||
start_amount: Some(start),
|
||||
end_amount: None,
|
||||
}) => query.filter(pi_dsl::amount.ge(start)),
|
||||
Some(AmountFilter {
|
||||
start_amount: None,
|
||||
end_amount: Some(end),
|
||||
}) => query.filter(pi_dsl::amount.le(end)),
|
||||
_ => query,
|
||||
};
|
||||
|
||||
query = match ¶ms.currency {
|
||||
Some(currency) => query.filter(pi_dsl::currency.eq_any(currency.clone())),
|
||||
None => query,
|
||||
};
|
||||
|
||||
let connectors = params
|
||||
.connector
|
||||
@ -653,6 +672,13 @@ impl<T: DatabaseStore> PaymentIntentInterface for crate::RouterStore<T> {
|
||||
None => query,
|
||||
};
|
||||
|
||||
query = match ¶ms.merchant_connector_id {
|
||||
Some(merchant_connector_id) => query.filter(
|
||||
pa_dsl::merchant_connector_id.eq_any(merchant_connector_id.clone()),
|
||||
),
|
||||
None => query,
|
||||
};
|
||||
|
||||
query
|
||||
}
|
||||
};
|
||||
@ -690,8 +716,6 @@ impl<T: DatabaseStore> PaymentIntentInterface for crate::RouterStore<T> {
|
||||
constraints: &PaymentIntentFetchConstraints,
|
||||
_storage_scheme: MerchantStorageScheme,
|
||||
) -> error_stack::Result<Vec<String>, StorageError> {
|
||||
use common_utils::errors::ReportSwitchExt;
|
||||
|
||||
let conn = connection::pg_connection_read(self).await.switch()?;
|
||||
let conn = async_bb8_diesel::Connection::as_async_conn(&conn);
|
||||
let mut query = DieselPaymentIntent::table()
|
||||
@ -722,6 +746,22 @@ impl<T: DatabaseStore> PaymentIntentInterface for crate::RouterStore<T> {
|
||||
None => query,
|
||||
};
|
||||
|
||||
query = match params.amount_filter {
|
||||
Some(AmountFilter {
|
||||
start_amount: Some(start),
|
||||
end_amount: Some(end),
|
||||
}) => query.filter(pi_dsl::amount.between(start, end)),
|
||||
Some(AmountFilter {
|
||||
start_amount: Some(start),
|
||||
end_amount: None,
|
||||
}) => query.filter(pi_dsl::amount.ge(start)),
|
||||
Some(AmountFilter {
|
||||
start_amount: None,
|
||||
end_amount: Some(end),
|
||||
}) => query.filter(pi_dsl::amount.le(end)),
|
||||
_ => query,
|
||||
};
|
||||
|
||||
query = match ¶ms.currency {
|
||||
Some(currency) => query.filter(pi_dsl::currency.eq_any(currency.clone())),
|
||||
None => query,
|
||||
|
||||
Reference in New Issue
Block a user